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',)


 
views.py:

def auth_view(request):
>     username = request.POST.get('username','')
>     password = request.POST.get('password','')
>     user = auth.authenticate(username=username, password=password)
>     if user is not None:
>         auth.login(request, user)
>         return HttpResponseRedirect('/')
>     elif:
>         user = auth.authenticate(email=username, password=password)
>         if user is not None:
>             auth.login(request, user)
>             return HttpResponseRedirect('/')
>     else:
>         return HttpResponseRedirect('/accounts/invalid_login')


html:

<form action="/accounts/auth/" method="post">
>     {%csrf_token%}
>     <label for="name">Email or Username:</label>
>     <input type="text" name="name" id="name" value="">
>     <label for="password">Password:</label>
>     <input type="password" name="password" id="password" value="">
>     <input type="submit" value="LOGIN">
> </form>



In the views I tried giving both the *username* and *email *as input from 
the form as *name*, and check to see if username and password authenticate. 
If not then check whether email and password authenticate. But its not 
working. How do I solve this problem? Please kindly help me. Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0cb8e818-3145-4e91-a374-7b018092f4fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to