Skip to content

Commit

Permalink
Merge pull request #2872 from Zharktas/2870-require-password-when-cha…
Browse files Browse the repository at this point in the history
…nging-email

#2870: require password when changing email
  • Loading branch information
rossjones committed Mar 10, 2016
2 parents ca8b046 + f4c31b2 commit 6674419
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ckan/controllers/user.py
Expand Up @@ -323,7 +323,10 @@ def _save_edit(self, id, context):
context['message'] = data_dict.get('log_message', '')
data_dict['id'] = id

if data_dict['password1'] and data_dict['password2']:
email_changed = data_dict['email'] != c.userobj.email

if (data_dict['password1'] and data_dict['password2']) \
or email_changed:
identity = {'login': c.user,
'password': data_dict['old_password']}
auth = authenticator.UsernamePasswordAuthenticator()
Expand Down
31 changes: 31 additions & 0 deletions ckan/tests/controllers/test_user.py
Expand Up @@ -246,6 +246,37 @@ def test_edit_user(self):
assert_equal(user.about, 'new about')
assert_equal(user.activity_streams_email_notifications, True)

def test_email_change_without_password(self):

app = self._get_test_app()
env, response, user = _get_user_edit_page(app)

form = response.forms['user-edit-form']

# new values
form['email'] = 'new@example.com'

# factory returns user with password 'pass'
form.fields['old_password'][0].value = 'wrong-pass'

response = webtest_submit(form, 'save', status=200, extra_environ=env)
assert_true('Old Password: incorrect password' in response)

def test_email_change_with_password(self):
app = self._get_test_app()
env, response, user = _get_user_edit_page(app)

form = response.forms['user-edit-form']

# new values
form['email'] = 'new@example.com'

# factory returns user with password 'pass'
form.fields['old_password'][0].value = 'pass'

response = submit_and_follow(app, form, env, 'save')
assert_true('Profile updated' in response)

def test_perform_reset_for_key_change(self):
password = 'password'
params = {'password1': password, 'password2': password}
Expand Down

0 comments on commit 6674419

Please sign in to comment.