2

I am using username for primary identification. However, users also have email addresses. I would like to know how can I set up "email address reset" so that users can change their email addresses. This functionality seems obvious to me but I did not find anything - am I missing something or maybe my approach is not correct?

Oh, and I would like to keep the username as is, I just want to make it possible to change the email with confirmations etc. I think it is important to have an email sent to the new address first and only then change it.

Any help will be much appreciated. Thank you in advance.

Teddy Markov
  • 266
  • 3
  • 15
  • Do you have smtp server configured already? – Al Amin Oct 06 '19 at 10:36
  • Hey Al Amin. I have successfully configured password reset and account activation. The problem is I am not aware if this email reset thing is even supported by Djoser. Of course I could reverse engineer it but from what I see it is not. And logic tells me that if it really is nothing you can do to reset your email, then this is a huge flaw. This is why I think there should be something. If there is not, I guess I will have to implement it by myself. Which I also consider (and maybe create a pull request, IDK) – Teddy Markov Oct 07 '19 at 18:00

1 Answers1

0

First I suggest you watch this awesome Djoser tutorial Django Rest Framework Authentication Crash Course then you need to set up your email configuration with your gmail API or sendgrid API. Here is a sample code you need to put in your settings

For gmail

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_PORT = 587
EMAIL_HOST_USER = 'your email address@gmail.com'
EMAIL_HOST_PASSWORD = 'gmail API Key (password)'

copy templates from REST implementation of Django authentication system then in the settings add your html like below

'PASSWORD_RESET_CONFIRM_URL': 'password_changed_confirmation/password/reset/confirm/{uid}/{token}',
    'USERNAME_RESET_CONFIRM_URL': 'username_changed_confirmation/username/reset/confirm/{uid}/{token}',
    'ACTIVATION_URL': 'activation/activate/{uid}/{token}',
    'SEND_ACTIVATION_EMAIL': True,
    'SERIALIZERS': {},

Hope this will help

Jayesh Babu
  • 1,389
  • 2
  • 20
  • 34