Hi, you see the full example in docs
https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#a-full-example

Cheers

On Wed, Oct 15, 2014 at 2:52 AM, monoBOT <[email protected]> wrote:

> You can implement an alternative authentication backend like so:
>
> *on your settings:*
>
> AUTHENTICATION_BACKENDS = (
>     'your_app.backend.EmailBackend',
>     'django.contrib.auth.backends.ModelBackend'
>     )
>
> *and on "your_app.backends":*
>
> #!/usr/bin/env python
> # -*- coding: utf-8 -*-
>
> from django.contrib.auth import get_user_model
>
>
> class EmailBackend(object):
>     def authenticate(self, username=None, password=None):
>         user_cls = get_user_model()
>         try:
>             user = user_cls.objects.get(email=username)
>             if user.check_password(password):
>                 return user
>         except user_cls.DoesNotExist:
>             return None
>         except:
>             return None
>
>     def get_user(self, user_id):
>         user_cls = get_user_model()
>         try:
>             return user_cls.objects.get(pk=user_id)
>         except user_cls.DoesNotExist:
>             return None
>
>
> So the app checks if the user can be authenticated via your backend and if
> fails goes to the normal authentication backend.
>
>
> 2014-10-15 9:35 GMT+01:00 Frankline <[email protected]>:
>
>> Hi all,
>>
>> Just started looking at Django 1.7. I've followed the tutorials on
>> https://docs.djangoproject.com/en/1.7/.
>>
>> However, I find myself in a position where I need to login users based on
>> either email or username, AND NOT just the username. I want my users to
>> register using email addresses. This presents some issues with the standard
>> Django user implementation since the authentication backend is still going
>> to look for the username when logging in.
>>
>> I am keen to know how developers here implement this in their own Django
>> 1.7 projects. And also what user models are preferable: AbstractUser or
>> AbstractBaseUser.
>>
>> Any links to example tutorials will also be greatly appreciated.
>>
>> Regards,
>> Frankline
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> 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/CAEAUGdUzZ3ytWQPpBihXOJm2vE7ZxBRhXYQ3mMwgjr2xJR4bpw%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAEAUGdUzZ3ytWQPpBihXOJm2vE7ZxBRhXYQ3mMwgjr2xJR4bpw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *monoBOT*
> Visite mi sitio(Visit my site): monobotsoft.es/blog/
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CA%2BxOsGA5WvSmkEKM1cPy5HhhUMQpHb4wu5rbtQxuoxBjJznjdw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BxOsGA5WvSmkEKM1cPy5HhhUMQpHb4wu5rbtQxuoxBjJznjdw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAM-7rO3MOwvqgp5HVELyObtF999teobFoUv8YZPbsKSRKoQ1-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to