For user could login with email or username,
I did as what this page
http://www.djangosnippets.org/snippets/74/
said

# in settings.py
# ...
AUTHENTICATION_BACKENDS = (
    'online.accounts.backends.EmailOrUsernameModelBackend',
    'django.contrib.auth.backends.ModelBackend'
)
# ...

l...@lab ~/online $ tree accounts/
accounts/
├── __init__.py
├── __init__.pyc
├── backends.py
└── backends.pyc

l...@lab ~/online $ cat accounts/backends.py
from django.conf import settings
from django.contrib.auth.models import User

class EmailOrUsernameModelBackend(object):
    def authenticate(self, username=None, password=None):
        if '@' in username:
            kwargs = {'email': username}
        else:
            kwargs = {'username': username}
        try:
            user = User.objects.get(**kwargs)
            if user.check_password(password):
                return user
        except User.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return User.objects.get(pk=user_id)
        except User.DoesNotExist:
            return None


Then I found somthing wrong,

first, admin view doesn't work well,
http://127.0.0.1:8000/admin/logout/
become
http://127.0.0.1:8000/admin/admin/logout/
user couldnt't logout as usual

second, many url rules which in myproject.urls doesn't work

^admin/doc/
^admin/ ^$
^admin/ ^logout/$
^admin/ ^password_change/$
^admin/ ^password_change/done/$
^admin/ ^jsi18n/$
^admin/ ^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$
^admin/ ^(?P<app_label>\w+)/$
^admin/ ^auth/user/
^admin/ ^auth/group/
^admin/ ^seed/seed/
^admin/ ^seed/format/
^admin/ ^seed/language/
^admin/ ^comments/comment/
^admin/ ^seed/right/
^admin/ ^sites/site/
^admin/ ^seed/category/

Why prefix '^admin'/ will be added in the front of those url rules
automatically after I
add `login with email custom backend` ?

How to fix it /

l...@lab ~/online $ django-admin.py --version
1.1 beta 1

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to