Re: Using email instead of username for registration and login
I opted to customize a little. First the backend: from django.contrib.auth.backends import ModelBackend from django.contrib.auth.models import User class EmailBackend(ModelBackend): """A django.contrib.auth backend that authenticates the user based on its email address instead of the username. """ def authenticate(self, email=None, password=None): """Authenticate user using its email address instead of username.""" try: user = User.objects.get(email=email) if user.check_password(password): return user except User.DoesNotExist: return None Then setup settings accordingly (notice that I wrote the backend inside an app called 'accounts'): AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', # necessary for django.auth 'accounts.backends.EmailBackend' # custom backend to authenticate using the email field ) And then modify your login view: if request.method == 'POST' and username and password: user = auth.authenticate(username=username, password=password) if user is None: user = auth.authenticate(email=email, password=password) What do you think? I know it is not that simple but I couldn't figure out an easier/cleaner way to do it. On Monday, September 24, 2012 10:57:20 PM UTC-3, Bill Beal wrote: > > Hi all, > > I want to use the email address as the username for registration and > login. I'm using django-registration for 2-stage registration. I'm > looking for an easier way than what I've come up with so far. I can modify > registration and activation, but then django.contrib.auth.views.login has a > 30-character limit on the username. I'm not looking forward to making > username act like an email address. Any quick fixes? > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/S6IA5wIf6FQJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using email instead of username for registration and login
This should cover it: https://github.com/dabapps/django-email-as-username For compatibility with django-registration you'll also want to take a look at the thread on this ticket: https://github.com/dabapps/django-email-as-username/issues/17 Cheers, Tom On Tuesday, 25 September 2012 02:57:20 UTC+1, Bill Beal wrote: > > Hi all, > > I want to use the email address as the username for registration and > login. I'm using django-registration for 2-stage registration. I'm > looking for an easier way than what I've come up with so far. I can modify > registration and activation, but then django.contrib.auth.views.login has a > 30-character limit on the username. I'm not looking forward to making > username act like an email address. Any quick fixes? > -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/pm-WyxpvirMJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using email instead of username for registration and login
Hi, For login with email or username in Django visit http://www.f2finterview.com/web/Django/18/ it will give you direction On Tue, Sep 25, 2012 at 7:27 AM, Bill Bealwrote: > Hi all, > > I want to use the email address as the username for registration and > login. I'm using django-registration for 2-stage registration. I'm > looking for an easier way than what I've come up with so far. I can modify > registration and activation, but then django.contrib.auth.views.login has a > 30-character limit on the username. I'm not looking forward to making > username act like an email address. Any quick fixes? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/E4GTF1wAPZ8J. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- Thanks & Regards Stephen S Website: www.f2finterview.com Blog: blog.f2finterview.com Tutorial: tutorial.f2finterview.com Group:www.charvigroups.com -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using email instead of username for registration and login
On Tue, Sep 25, 2012 at 9:57 AM, Bill Bealwrote: > Hi all, > > I want to use the email address as the username for registration and login. > I'm using django-registration for 2-stage registration. I'm looking for an > easier way than what I've come up with so far. I can modify registration > and activation, but then django.contrib.auth.views.login has a 30-character > limit on the username. I'm not looking forward to making username act like > an email address. Any quick fixes? The quick and nasty fix -- issue the ALTER statement on your database to make the field longer, and define custom forms that enforce the new field length. Provide those custom forms to the auth login views, etc. The slightly better fix -- fork Django (or, at least, django.contrib.auth) for the purposes of your local deployment, and modify the 30 character constraint wherever it occurs. The real fix: I'm about to land a new feature for Django 1.5 that will allow you to install a custom your User model that has whatever properties you want (e.g., a longer username field, only an email field, twitter handle instead of username, etc). If you want to test this branch, you can check out my Github repo [1], or wait a day or two and try it out on the Django development branch (that will eventually become 1.5). [1] https://github.com/freakboy3742/django/tree/t3011 Yours, Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Using email instead of username for registration and login
You could check out django-userena On Mon, Sep 24, 2012 at 9:57 PM, Bill Bealwrote: > Hi all, > > I want to use the email address as the username for registration and > login. I'm using django-registration for 2-stage registration. I'm > looking for an easier way than what I've come up with so far. I can modify > registration and activation, but then django.contrib.auth.views.login has a > 30-character limit on the username. I'm not looking forward to making > username act like an email address. Any quick fixes? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/E4GTF1wAPZ8J. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Using email instead of username for registration and login
Hi all, I want to use the email address as the username for registration and login. I'm using django-registration for 2-stage registration. I'm looking for an easier way than what I've come up with so far. I can modify registration and activation, but then django.contrib.auth.views.login has a 30-character limit on the username. I'm not looking forward to making username act like an email address. Any quick fixes? -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/E4GTF1wAPZ8J. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.