Changeset 4266
- Timestamp:
- 12/30/06 01:16:25 (2 years ago)
- Files:
-
- django/trunk/django/contrib/admin/templates/admin/auth/user/change_password.html (added)
- django/trunk/django/contrib/admin/urls.py (modified) (1 diff)
- django/trunk/django/contrib/admin/views/auth.py (modified) (2 diffs)
- django/trunk/django/contrib/auth/forms.py (modified) (1 diff)
- django/trunk/django/contrib/auth/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/admin/urls.py
r3564 r4266 30 30 # "Add user" -- a special-case view 31 31 ('^auth/user/add/$', 'django.contrib.admin.views.auth.user_add_stage'), 32 # "Change user password" -- another special-case view 33 ('^auth/user/(\d+)/password/$', 'django.contrib.admin.views.auth.user_change_password'), 32 34 33 35 # Add/change/delete/history django/trunk/django/contrib/admin/views/auth.py
r4265 r4266 1 1 from django.contrib.admin.views.decorators import staff_member_required 2 from django.contrib.auth.forms import UserCreationForm 2 from django.contrib.auth.forms import UserCreationForm, AdminPasswordChangeForm 3 3 from django.contrib.auth.models import User 4 4 from django.core.exceptions import PermissionDenied 5 5 from django import oldforms, template 6 from django.shortcuts import render_to_response 6 from django.shortcuts import render_to_response, get_object_or_404 7 7 from django.http import HttpResponseRedirect 8 from django.utils.html import escape 8 9 9 10 def user_add_stage(request): … … 43 44 }, context_instance=template.RequestContext(request)) 44 45 user_add_stage = staff_member_required(user_add_stage) 46 47 def user_change_password(request, id): 48 if not request.user.has_perm('auth.change_user'): 49 raise PermissionDenied 50 user = get_object_or_404(User, pk=id) 51 manipulator = AdminPasswordChangeForm(user) 52 if request.method == 'POST': 53 new_data = request.POST.copy() 54 errors = manipulator.get_validation_errors(new_data) 55 if not errors: 56 new_user = manipulator.save(new_data) 57 msg = _('Password changed successfully.') 58 request.user.message_set.create(message=msg) 59 return HttpResponseRedirect('..') 60 else: 61 errors = new_data = {} 62 form = oldforms.FormWrapper(manipulator, new_data, errors) 63 return render_to_response('admin/auth/user/change_password.html', { 64 'title': _('Change password: %s') % escape(user.username), 65 'form': form, 66 'is_popup': request.REQUEST.has_key('_popup'), 67 'add': True, 68 'change': False, 69 'has_delete_permission': False, 70 'has_change_permission': True, 71 'has_absolute_url': False, 72 'first_form_field_id': 'id_password1', 73 'opts': User._meta, 74 'original': user, 75 'show_save': True, 76 }, context_instance=template.RequestContext(request)) 77 user_change_password = staff_member_required(user_change_password) django/trunk/django/contrib/auth/forms.py
r4208 r4266 127 127 self.user.set_password(new_data['new_password1']) 128 128 self.user.save() 129 130 class AdminPasswordChangeForm(oldforms.Manipulator): 131 "A form used to change the password of a user in the admin interface." 132 def __init__(self, user): 133 self.user = user 134 self.fields = ( 135 oldforms.PasswordField(field_name='password1', length=30, maxlength=60, is_required=True), 136 oldforms.PasswordField(field_name='password2', length=30, maxlength=60, is_required=True, 137 validator_list=[validators.AlwaysMatchesOtherField('password1', _("The two password fields didn't match."))]), 138 ) 139 140 def save(self, new_data): 141 "Saves the new password." 142 self.user.set_password(new_data['password1']) 143 self.user.save() django/trunk/django/contrib/auth/models.py
r4265 r4266 92 92 last_name = models.CharField(_('last name'), maxlength=30, blank=True) 93 93 email = models.EmailField(_('e-mail address'), blank=True) 94 password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' "))94 password = models.CharField(_('password'), maxlength=128, help_text=_("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.")) 95 95 is_staff = models.BooleanField(_('staff status'), default=False, help_text=_("Designates whether the user can log into this admin site.")) 96 96 is_active = models.BooleanField(_('active'), default=True, help_text=_("Designates whether this user can log into the Django admin. Unselect this instead of deleting accounts."))
