简体   繁体   中英

How can I update the email address using the confirmation code in Django?

I use all the functionalities of dj-rest-auth to register, log in, confirm the email address, change the password, reset the password and many more. Unfortunately, the library does not support changing the email address. I would like the authenticated user to first enter the account password and the new email address. After the successful process of authentication, I would like to send the user a specially generated confirmation code. Only when he enters it, the old email address will be changed to the new one. As far as I know, there is no such functionality in dj-rest-auth . Unfortunately, I also have not found any current solutions or libraries for this purpose anywhere. Did anyone have such a problem and could share his solution here? Thank you in advance.

Though i don't have any solution for what you want accurately but here is a replace. You can use django all-auth and some email backend to send an email to the new added email to confirm the new email. In the sent email, there will be a confirmation link and the user has to click that to confirm the new email. After using django all-auth you only have to add an email backend which will help in sending email. Rest will be maintained by all-auth. eg, In your settings.py you can add an SMTP email backend to send email from your selected gmail account. Add these lines of code to your settings.py;

EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = 'HOST_EMAIL' #HOST_EMAIL is your email from which you want to send email to the user.
EMAIL_HOST_PASSWORD = 'HOST_PASSWORD' #HOST_PASSWORD is the password of the email you are using as HOST_EMAIL

But after doing all these things, to make it work locally, you need to go to your google account which you are using as HOST_EMAIL. Go to manage google account >> security >> Turn on less secure apps . Then you will be able to send email to the user. NOTE : If you have 2-factor authentication turned on for your google account, then these steps will not work. That type of account has some different setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM