Ticket #3166: change_password.patch
File change_password.patch, 8.0 KB (added by , 18 years ago) |
---|
-
django/contrib/admin/templates/admin/auth/user/change_password.html
1 {% extends "admin/base_site.html" %} 2 {% load i18n admin_modify adminmedia %} 3 {% block extrahead %}{{ block.super }} 4 <script type="text/javascript" src="../../../../jsi18n/"></script> 5 {% for js in javascript_imports %}{% include_admin_script js %}{% endfor %} 6 {% endblock %} 7 {% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock %} 8 {% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %} 9 {% block userlinks %}<a href="../../../../doc/">{% trans 'Documentation' %}</a> / <a href="../../../password_change/">{% trans 'Change password' %}</a> / <a href="../../../logout/">{% trans 'Log out' %}</a>{% endblock %} 10 {% block breadcrumbs %}{% if not is_popup %} 11 <div class="breadcrumbs"> 12 <a href="../../../../">{% trans "Home" %}</a> › 13 <a href="../../">{{ opts.verbose_name_plural|capfirst|escape }}</a> › 14 <a href="../">{{ original|truncatewords:"18"|escape }}</a> › 15 {% trans 'change password' %} 16 </div> 17 {% endif %}{% endblock %} 18 {% block content %}<div id="content-main"> 19 <form action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% block form_top %}{% endblock %} 20 <div> 21 {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %} 22 {% if form.error_dict %} 23 <p class="errornote"> 24 {% blocktrans count form.error_dict.items|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} 25 </p> 26 {% endif %} 27 28 <p>{% trans "Enter a new username and password." %}</p> 29 30 <fieldset class="module aligned"> 31 32 <div class="form-row"> 33 {{ form.password1.html_error_list }} 34 <label for="id_password1" class="required">{% trans 'Password' %}:</label> {{ form.password1 }} 35 </div> 36 37 <div class="form-row"> 38 {{ form.password2.html_error_list }} 39 <label for="id_password2" class="required">{% trans 'Password (again)' %}:</label> {{ form.password2 }} 40 <p class="help">{% trans 'Enter the same password as above, for verification.' %}</p> 41 </div> 42 43 </fieldset> 44 45 <div class="submit-row"> 46 <input type="submit" value="{% trans 'Change password' %}" class="default" /> 47 </div> 48 49 <script type="text/javascript">document.getElementById("{{ first_form_field_id }}").focus();</script> 50 </div> 51 </form></div> 52 {% endblock %} -
django/contrib/admin/urls.py
29 29 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 34 36 ('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list'), -
django/contrib/admin/views/auth.py
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 8 9 9 def user_add_stage(request): … … 42 42 'username_help_text': User._meta.get_field('username').help_text, 43 43 }, context_instance=template.RequestContext(request)) 44 44 user_add_stage = staff_member_required(user_add_stage) 45 46 def user_change_password(request, id): 47 if not request.user.has_perm('auth.change_user'): 48 raise PermissionDenied 49 user = get_object_or_404(User, pk=id) 50 manipulator = AdminPasswordChangeForm(user) 51 if request.method == 'POST': 52 new_data = request.POST.copy() 53 errors = manipulator.get_validation_errors(new_data) 54 if not errors: 55 new_user = manipulator.save(new_data) 56 msg = _('Password changed successfully.') % user 57 request.user.message_set.create(message=msg) 58 return HttpResponseRedirect('..') 59 else: 60 errors = new_data = {} 61 form = oldforms.FormWrapper(manipulator, new_data, errors) 62 return render_to_response('admin/auth/user/change_password.html', { 63 'title': _("Change password"), 64 'form': form, 65 'is_popup': request.REQUEST.has_key('_popup'), 66 'add': True, 67 'change': False, 68 'has_delete_permission': False, 69 'has_change_permission': True, 70 'has_absolute_url': False, 71 'first_form_field_id': 'id_password1', 72 'opts': User._meta, 73 'original': user, 74 'show_save': True, 75 }, context_instance=template.RequestContext(request)) 76 user_change_password = staff_member_required(user_change_password) -
django/contrib/auth/forms.py
126 126 "Saves the new password." 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 isValidUsername(self, field_data, all_data): 141 try: 142 User.objects.get(username=field_data) 143 except User.DoesNotExist: 144 return 145 raise validators.ValidationError, _('A user with that username already exists.') 146 147 def save(self, new_data): 148 "Saves the new password." 149 self.user.set_password(new_data['password1']) 150 self.user.save() -
django/contrib/auth/models.py
91 91 first_name = models.CharField(_('first name'), maxlength=30, blank=True) 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.")) 97 97 is_superuser = models.BooleanField(_('superuser status'), default=False, help_text=_("Designates that this user has all permissions without explicitly assigning them."))