Search code examples
djangodjango-rest-frameworkemail-verification

How to create django registration with email conformation code


Someone has a guide mb or tutorial about how can i make instant email verification by code like i want to register user and after he typed his email username and password in registerForm send him code on email NOT link and check that code and create user if everything is good with code

And i also searching for way to do the same with drf


Solution

  • A minimal specification to add user signup with email code verification in Django can be:

    • On the User model, add two fields:

      • For the verification code (e.g. email_code: str)
      • For the user's first log-in (with default value as true) (e.g is_first_login: str = True)
    • On the user signup form/view

      • generate a random verification code (by your flavor)
      • save the signed user and its verification code in the email_code field
      • pass the random code to the email template as a variable
      • fire the email
    • On the user login form/view

      • (Django version)
        • Read the user email and password on the login page
        • Verify if the user's email exists in the database and if is_first_login==True.
          • If True :
            • Redirects the user to the email verification code page
            • Read the code from the template form
            • Verify the code with the user email against the database
              • If True:
                • Update user model field is_first_loginto False
                • Let the user get logged in.
          • Else False:
            • Return a warning or an error message about the wrong code.