Skip to content

Commit 89c6a07

Browse files
committed
multi-auth: Updated admin system to use new auth api.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@2888 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent c9136c0 commit 89c6a07

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

django/contrib/admin/views/decorators.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django import http, template
22
from django.conf import settings
3-
from django.contrib.auth.models import User, SESSION_KEY
3+
from django.contrib.auth.models import User
4+
from django.contrib.auth import authenticate, login
45
from django.shortcuts import render_to_response
56
from django.utils.translation import gettext_lazy
67
import base64, datetime, md5
@@ -69,10 +70,10 @@ def _checklogin(request, *args, **kwargs):
6970
return _display_login_form(request, message)
7071

7172
# Check the password.
72-
username = request.POST.get('username', '')
73-
try:
74-
user = User.objects.get(username=username, is_staff=True)
75-
except User.DoesNotExist:
73+
username = request.POST.get('username', None)
74+
password = request.POST.get('password', None)
75+
user = authenticate(username=username, password=password)
76+
if user is None:
7677
message = ERROR_MESSAGE
7778
if '@' in username:
7879
# Mistakenly entered e-mail address instead of username? Look it up.
@@ -86,8 +87,9 @@ def _checklogin(request, *args, **kwargs):
8687

8788
# The user data is correct; log in the user in and continue.
8889
else:
89-
if user.check_password(request.POST.get('password', '')):
90-
request.session[SESSION_KEY] = user.id
90+
if user.is_staff:
91+
login(request, user)
92+
# TODO: set last_login with an event.
9193
user.last_login = datetime.datetime.now()
9294
user.save()
9395
if request.POST.has_key('post_data'):

0 commit comments

Comments
 (0)