Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend - Email Verification #473

Closed
rburaksaritas opened this issue Nov 7, 2023 · 1 comment · Fixed by #712
Closed

Backend - Email Verification #473

rburaksaritas opened this issue Nov 7, 2023 · 1 comment · Fixed by #712
Assignees
Labels
effort: level 5 How much effort is needed for this task priority: high Issue is important, must be resolved in a reasonable time state: assigned This task is currently assigned to a contributor team: back-end Issue is part of back-end development

Comments

@rburaksaritas
Copy link
Contributor

rburaksaritas commented Nov 7, 2023

Description

Backend Email verification endpoints must be implemented.

Ensure endpoints have validation and return appropriate status codes as stated in the API convention document.

Deadline

12.12.2023

@azizamankenova azizamankenova added state: assigned This task is currently assigned to a contributor priority: high Issue is important, must be resolved in a reasonable time effort: level 5 How much effort is needed for this task team: back-end Issue is part of back-end development labels Nov 7, 2023
@rburaksaritas rburaksaritas changed the title Backend - Email verify endpoint implementation Backend - Email Verification Dec 5, 2023
@rburaksaritas rburaksaritas reopened this Dec 5, 2023
@rburaksaritas rburaksaritas linked a pull request Dec 12, 2023 that will close this issue
@rburaksaritas
Copy link
Contributor Author

The email verification feature is implemented as follows:

Endpoints

The following endpoints have been added:

  1. Send Verification Email (/api/email_verification/send)

    • Method: POST
    • Description: Triggers the sending of a verification email with a unique code to the current user's email address.
    • Dependencies: Automatically retrieves the current user's username and email through authentication token.
    • Success Response: A message indicating the verification email was sent successfully.
    • Usage: /api/email_verification/send (user info will be obtained from authentication header token.)
  2. Verify Email (/api/email_verification/verify)

    • Method: POST
    • Description: Verifies the user's email by checking the provided token against the one stored in the database.
    • Parameters:
      • token (Query Parameter): The verification token received in the user's email.
      • username (Dependency): Automatically retrieved username of the current user through authentication token.
    • Success Response: A message indicating successful email verification.
    • Error Response: An error message if the token is invalid or expired.
    • Usage: /api/email_verification/verify?token=572492

Implementation Details

  • Token Generation: A 6-digit numerical token is generated.
  • Token Entry to Database: Token is saved to the new collection email_verification in the database along with the username, email and expiration date.
  • Token Expiration: Tokens are set to expire in 10 minutes.
  • Email Sending: Utilizes SMTP protocol to send emails. Requires email and password configuration in config.py.

Added Files

  • Models/email_verification_model.py: Defines the Pydantic model for email verification data.
  • Services/email_verification_service.py: Contains all the business logic for the email verification process.
  • Controllers/email_verification_controller.py: Contains the mentioned endpoints for the email verification process.

Modified Files

  • Services/authentication_service.py: Updated to include a function to retrieve the email of the current user.

Configuration

  • Update Required: The config.py file in the deployment environment needs to be updated to include the mail server credentials (DAPP_EMAIL and DAPP_EMAIL_PASSWORD) for the verification email sender.

Notes

  • This implementation assumes the server's timezone is set to GMT+3 for expiration calculation. Adjustments may be required for servers in different time zones.
  • Please update configuration for email & password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: level 5 How much effort is needed for this task priority: high Issue is important, must be resolved in a reasonable time state: assigned This task is currently assigned to a contributor team: back-end Issue is part of back-end development
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants