Yes, there *is* a very simple way to implement “Email address as username”
- you use a custom user model that implements that approach.
https://docs.djangoproject.com/en/1.8/topics/auth/customizing/#substituting-a-custom-user-model
Django’s docs contain details of how to do this, and there are
Are you suggesting that there's a relatively easy way to implement "email
address as username"? Is it as easy as just putting an email address into
the username field? And making sure to update it when someone updates their
email address?
On Monday, January 19, 2015 at 2:33:35 AM UTC-8, James
Damn. That's one heck of an explanation James! And very detailed to boot!
As a programmer, the OP's approach to login a user with either
username/email with ONLY the default auth system seemed flawed (or
incomplete, at best) to me. You've not just validated my opinion, but given
me a wonder
I guess I'm not clear on what you are trying to achieve. There are a couple
of scenarios to consider.
As it stands with the default contrib.auth authentication backend, sending
both the username and email address entered by the user will only work IF
the user registered/was created using their
Ignoring the malformed code, will the call to authenticate() even work
without username? According to the docs,
https://docs.djangoproject.com/en/1.7/topics/auth/default/#django.contrib.auth.authenticate
It takes credentials in the form of keyword arguments, for the default
> configuration this
Your if block in views.py is not well-formed. I haven't tested this but I'd
write it more like this:
# try username
user = auth.authenticate(username=username, password=password)
if user is not None:
auth.login(request, user)
return HttpResponseRedirect('/')
#
I have extendted the *UserCreationForm* with email and other fields, so
that I could authenticate a user with both its username and email.
forms.py:
> class UserCreationForm(UserCreationForm):
> class Meta:
> model = User
> fields = ('first_name', 'last_name', 'username', 'email',)
7 matches
Mail list logo