mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
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
This commit is contained in:
parent
c9136c0bff
commit
89c6a07a5f
@ -1,6 +1,7 @@
|
|||||||
from django import http, template
|
from django import http, template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User, SESSION_KEY
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.auth import authenticate, login
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
import base64, datetime, md5
|
import base64, datetime, md5
|
||||||
@ -69,10 +70,10 @@ def staff_member_required(view_func):
|
|||||||
return _display_login_form(request, message)
|
return _display_login_form(request, message)
|
||||||
|
|
||||||
# Check the password.
|
# Check the password.
|
||||||
username = request.POST.get('username', '')
|
username = request.POST.get('username', None)
|
||||||
try:
|
password = request.POST.get('password', None)
|
||||||
user = User.objects.get(username=username, is_staff=True)
|
user = authenticate(username=username, password=password)
|
||||||
except User.DoesNotExist:
|
if user is None:
|
||||||
message = ERROR_MESSAGE
|
message = ERROR_MESSAGE
|
||||||
if '@' in username:
|
if '@' in username:
|
||||||
# Mistakenly entered e-mail address instead of username? Look it up.
|
# Mistakenly entered e-mail address instead of username? Look it up.
|
||||||
@ -86,8 +87,9 @@ def staff_member_required(view_func):
|
|||||||
|
|
||||||
# The user data is correct; log in the user in and continue.
|
# The user data is correct; log in the user in and continue.
|
||||||
else:
|
else:
|
||||||
if user.check_password(request.POST.get('password', '')):
|
if user.is_staff:
|
||||||
request.session[SESSION_KEY] = user.id
|
login(request, user)
|
||||||
|
# TODO: set last_login with an event.
|
||||||
user.last_login = datetime.datetime.now()
|
user.last_login = datetime.datetime.now()
|
||||||
user.save()
|
user.save()
|
||||||
if request.POST.has_key('post_data'):
|
if request.POST.has_key('post_data'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user