Changeset 2887
- Timestamp:
- 05/09/06 23:30:25 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/multi-auth/django/contrib/auth/forms.py
r2809 r2887 1 1 from django.contrib.auth.models import User 2 from django.contrib.auth import authenticate 2 3 from django.contrib.sites.models import Site 3 4 from django.template import Context, loader … … 21 22 forms.TextField(field_name="username", length=15, maxlength=30, is_required=True, 22 23 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 23 forms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True, 24 validator_list=[self.isValidPasswordForUser]), 24 forms.PasswordField(field_name="password", length=15, maxlength=30, is_required=True), 25 25 ] 26 26 self.user_cache = None … … 31 31 32 32 def isValidUser(self, field_data, all_data): 33 try: 34 self.user_cache = User.objects.get(username=field_data) 35 except User.DoesNotExist: 36 raise validators.ValidationError, _("Please enter a correct username and password. Note that both fields are case-sensitive.") 37 38 def isValidPasswordForUser(self, field_data, all_data): 39 if self.user_cache is not None and not self.user_cache.check_password(field_data): 40 self.user_cache = None 33 username = field_data 34 password = all_data.get('password', None) 35 self.user_cache = authenticate(username=username, password=password) 36 if self.user_cache is None: 41 37 raise validators.ValidationError, _("Please enter a correct username and password. Note that both fields are case-sensitive.") 42 38 django/branches/multi-auth/django/contrib/auth/views.py
r2809 r2887 4 4 from django.shortcuts import render_to_response 5 5 from django.template import RequestContext 6 from django.contrib.auth.models import SESSION_KEY7 6 from django.contrib.sites.models import Site 8 7 from django.http import HttpResponse, HttpResponseRedirect … … 20 19 if not redirect_to or '://' in redirect_to or ' ' in redirect_to: 21 20 redirect_to = '/accounts/profile/' 22 request.session[SESSION_KEY] = manipulator.get_user_id() 21 from django.contrib.auth import login 22 login(request, manipulator.get_user()) 23 23 request.session.delete_test_cookie() 24 24 return HttpResponseRedirect(redirect_to) … … 34 34 def logout(request, next_page=None): 35 35 "Logs out the user and displays 'You are logged out' message." 36 from django.contrib.auth import logout 36 37 try: 37 del request.session[SESSION_KEY]38 logout(request) 38 39 except KeyError: 39 40 return render_to_response('registration/logged_out.html', {'title': 'Logged out'}, context_instance=RequestContext(request))
