Django

Code

Changeset 2888

Show
Ignore:
Timestamp:
05/09/06 23:30:38 (2 years ago)
Author:
jkocherhans
Message:

multi-auth: Updated admin system to use new auth api.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/multi-auth/django/contrib/admin/views/decorators.py

    r2809 r2888  
    11from django import http, template 
    22from django.conf import settings 
    3 from django.contrib.auth.models import User, SESSION_KEY 
     3from django.contrib.auth.models import User 
     4from django.contrib.auth import authenticate, login 
    45from django.shortcuts import render_to_response 
    56from django.utils.translation import gettext_lazy 
     
    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: 
     
    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()