I see django-allauth supports forcing users to login using their email address, and doesn't ask them for a username when signing up (instead generating one automatically from the email address) - https://stackoverflow.com/a/19683532/221001
Is it possible to have a user sign up, entering an email address and username manually, and then allow them to sign in using either? (e.g. there are two fields on the Login page: "username or email" and "password")
As Yogesh posted above, the username_email value for ACCOUNT_AUTHENTICATION_METHOD does the job.
http://django-allauth.readthedocs.org/en/latest/configuration.html
Related
I'm trying to configure Django app with a user authentication model(django-allauth).
It almost works well but when a user tries to change his password, a problem occurs.
Let's say when a user want to change his password, he goes to Password reset page
Example
http://3.129.xx.xxx/accounts/password/reset/
He put his Email address on the form and submit, then he recieve a "Password Reset E-mail" with a link to reset the password.
Example
https://u22207100.ct.sendgrid.net/ls/click?upn=EGpFlOkd4a3JZnFjHjqKqsCiiinSf51vqFvV.....
Cliking above link, the user redirected to
http://3.129.xx.xxx/accounts/password/reset/key/1-set-password/
But that page has only links "Sign In" and "Sign Up".
It does not have any form to put new password the user want to set.
Change password page's image
In this situation, the user can not change password.
should I set something to allauth system??
I just mentioned the above settings in this question but still if more code is required then tell me I'll update my question with that information. Thank you
How we can know user email address is valid or not without sending a link is there any method to do this in django , i just try to check the user their email address is valid or not .
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.
e.g,
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.
I have started django building my first app tutorials, i have to send email to all my users store in the database table on some special Ocations. i have searched on google and found many apis but found it very hard to configure with my app.
here is my model.py
class Users(models.Model):
UserID = models.IntegerField(verbose_name='User ID',max_length=255,primary_key=True)
UserName = models.CharField(verbose_name='User Name',max_length=254,null=True,blank=True)
Email = models.EmailField(verbose_name='Email',max_length=254,null=True,blank=True)
Phone = models.CharField(verbose_name='Phone Number',max_length=254,null=True,blank=True)
i want to have a function here which should get all users one-by-one and send email also tells the status weather the email has been sent or not.
battery's answer is ok, but i would do this way:
recievers = []
for user in Users.objects.all():
recievers.append(user.email)
send_mail(subject, message, from_email, recievers)
this way, you will open only once connection to mail server rather than opening for each email.
Sending email is very simple.
For your Users model this would be:
for user in Users.objects.all():
send_mail(subject, message, from_email,
user.Email)
Checkout Django's Documentation on send emails for more details.
Would be useful if you mention what problem you are facing if you've tried this.
Also note, IntegerField does not have a max_length argument.
for user in Users.objects.all():
send_mail(subject, message, from_email,
user.Email)
This is the best solutions and it works well
I'm building a Python web application using Flask along with Flask-User. I want to be able to restrict user registration to users that have an email on a specific domain (i.e. whoever#example.com)
Is this possible?
You could do it validate it before sending the form, like this:
DOMAINS_NOT_ALLOWED = ['yahoo.com', 'baidu.ch', 'example.com']
email_domain = request.form['email'].split('#')[-1]
if email_domain in DOMAINS_NOT_ALLOWED:
return "You're not allowed to register from this email provider."
You could validate the E-Mail in the RegisterForm, so only users with E-Mail ending on example.com will be allowed to register. If you are using Flask-WTF you can check the documentation of WTForms for custom validators.