diff --git a/ckan/controllers/user.py b/ckan/controllers/user.py index 301ef856fb6..61ccec97feb 100644 --- a/ckan/controllers/user.py +++ b/ckan/controllers/user.py @@ -512,8 +512,11 @@ def perform_reset(self, id): if request.method == 'POST': try: context['reset_password'] = True + user_state = user_dict['state'] new_password = self._get_form_password() - user_dict['password'] = new_password + username = request.params.get('name') + if (username is not None and username != ''): + user_dict['name'] = username user_dict['reset_key'] = c.reset_key user_dict['state'] = model.State.ACTIVE user = get_action('user_update')(context, user_dict) @@ -531,6 +534,7 @@ def perform_reset(self, id): h.flash_error(u'%r' % e.error_dict) except ValueError, ve: h.flash_error(unicode(ve)) + user_dict['state'] = user_state c.user_dict = user_dict return render('user/perform_reset.html') diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index 0d1b249288c..3f82629ba1c 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -668,7 +668,7 @@ def user_update(context, data_dict): '''Update a user account. Normal users can only update their own user accounts. Sysadmins can update - any user account. + any user account. Can not modify exisiting user's name. For further parameters see :py:func:`~ckan.logic.action.create.user_create`. diff --git a/ckan/logic/validators.py b/ckan/logic/validators.py index 41e08e48d2f..e87a1ba6202 100644 --- a/ckan/logic/validators.py +++ b/ckan/logic/validators.py @@ -568,10 +568,9 @@ def user_name_validator(key, data, errors, context): raise Invalid(_('User names must be strings')) user = model.User.get(new_user_name) + user_obj_from_context = context.get('user_obj') if user is not None: # A user with new_user_name already exists in the database. - - user_obj_from_context = context.get('user_obj') if user_obj_from_context and user_obj_from_context.id == user.id: # If there's a user_obj in context with the same id as the user # found in the db, then we must be doing a user_update and not @@ -582,6 +581,12 @@ def user_name_validator(key, data, errors, context): # name, so you can create a new user with that name or update an # existing user's name to that name. errors[key].append(_('That login name is not available.')) + elif user_obj_from_context: + old_user = model.User.get(user_obj_from_context.id) + if old_user is not None and old_user.state != model.State.PENDING: + errors[key].append(_('That login name can not be modified.')) + else: + return def user_both_passwords_entered(key, data, errors, context): diff --git a/ckan/templates/user/edit_user_form.html b/ckan/templates/user/edit_user_form.html index 9643b35b0ea..dfdf4e8c51e 100644 --- a/ckan/templates/user/edit_user_form.html +++ b/ckan/templates/user/edit_user_form.html @@ -5,7 +5,7 @@