| Home | Trees | Indices | Help |
|---|
|
|
1 from django.contrib.auth.models import User 2 from django.contrib.auth import authenticate 3 from django.contrib.sites.models import Site 4 from django.template import Context, loader 5 from django.core import validators 6 from django import oldforms 7 from django.utils.translation import ugettext as _ 810 "A form that creates a user, with no privileges, from the given username and password."3012 self.fields = ( 13 oldforms.TextField(field_name='username', length=30, max_length=30, is_required=True, 14 validator_list=[validators.isAlphaNumeric, self.isValidUsername]), 15 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 16 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 17 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 18 )1921 try: 22 User.objects.get(username=field_data) 23 except User.DoesNotExist: 24 return 25 raise validators.ValidationError, _('A user with that username already exists.')2628 "Creates the user." 29 return User.objects.create_user(new_data['username'], '', new_data['password1'])32 """ 33 Base class for authenticating users. Extend this to get a form that accepts 34 username/password logins. 35 """7137 """ 38 If request is passed in, the manipulator will validate that cookies are 39 enabled. Note that the request (a HttpRequest object) must have set a 40 cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before 41 running this validator. 42 """ 43 self.request = request 44 self.fields = [ 45 oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 46 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 47 oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 48 ] 49 self.user_cache = None5052 if self.request and not self.request.session.test_cookie_worked(): 53 raise validators.ValidationError, _("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.")5456 username = field_data 57 password = all_data.get('password', None) 58 self.user_cache = authenticate(username=username, password=password) 59 if self.user_cache is None: 60 raise validators.ValidationError, _("Please enter a correct username and password. Note that both fields are case-sensitive.") 61 elif not self.user_cache.is_active: 62 raise validators.ValidationError, _("This account is inactive.")63 6873 "A form that lets a user request a password reset"10875 self.fields = ( 76 oldforms.EmailField(field_name="email", length=40, is_required=True, 77 validator_list=[self.isValidUserEmail]), 78 )7981 "Validates that a user exists with the given e-mail address" 82 self.users_cache = list(User.objects.filter(email__iexact=new_data)) 83 if len(self.users_cache) == 0: 84 raise validators.ValidationError, _("That e-mail address doesn't have an associated user account. Are you sure you've registered?")8586 - def save(self, domain_override=None, email_template_name='registration/password_reset_email.html'):87 "Calculates a new password randomly and sends it to the user" 88 from django.core.mail import send_mail 89 for user in self.users_cache: 90 new_pass = User.objects.make_random_password() 91 user.set_password(new_pass) 92 user.save() 93 if not domain_override: 94 current_site = Site.objects.get_current() 95 site_name = current_site.name 96 domain = current_site.domain 97 else: 98 site_name = domain = domain_override 99 t = loader.get_template(email_template_name) 100 c = { 101 'new_password': new_pass, 102 'email': user.email, 103 'domain': domain, 104 'site_name': site_name, 105 'user': user, 106 } 107 send_mail(_('Password reset on %s') % site_name, t.render(Context(c)), None, [user.email])110 "A form that lets a user change his password."130112 self.user = user 113 self.fields = ( 114 oldforms.PasswordField(field_name="old_password", length=30, max_length=30, is_required=True, 115 validator_list=[self.isValidOldPassword]), 116 oldforms.PasswordField(field_name="new_password1", length=30, max_length=30, is_required=True, 117 validator_list=[validators.AlwaysMatchesOtherField('new_password2', _("The two 'new password' fields didn't match."))]), 118 oldforms.PasswordField(field_name="new_password2", length=30, max_length=30, is_required=True), 119 )120122 "Validates that the old_password field is correct." 123 if not self.user.check_password(new_data): 124 raise validators.ValidationError, _("Your old password was entered incorrectly. Please enter it again.")125127 "Saves the new password." 128 self.user.set_password(new_data['new_password1']) 129 self.user.save()132 "A form used to change the password of a user in the admin interface."145134 self.user = user 135 self.fields = ( 136 oldforms.PasswordField(field_name='password1', length=30, max_length=60, is_required=True), 137 oldforms.PasswordField(field_name='password2', length=30, max_length=60, is_required=True, 138 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 139 )140142 "Saves the new password." 143 self.user.set_password(new_data['password1']) 144 self.user.save()
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Apr 17 18:52:46 2008 | http://epydoc.sourceforge.net |