mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-17 21:20:32 -04:00
Merge pull request #953 from alphagov/fix-change-email-bug
Fixed bug where there was an error when try and change email.
This commit is contained in:
@@ -82,9 +82,10 @@ def user_profile_email_authenticate():
|
||||
return redirect('main.user_profile_email')
|
||||
|
||||
if form.validate_on_submit():
|
||||
session[NEW_EMAIL_PASSWORD_CONFIRMED] = True
|
||||
user_api_client.send_verify_code(current_user.id, 'email', session[NEW_EMAIL])
|
||||
return redirect(url_for('.user_profile_email_confirm'))
|
||||
current_user.email_address = session[NEW_EMAIL]
|
||||
del session[NEW_EMAIL]
|
||||
user_api_client.update_user(current_user)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
'views/user-profile/authenticate.html',
|
||||
@@ -94,32 +95,6 @@ def user_profile_email_authenticate():
|
||||
)
|
||||
|
||||
|
||||
@main.route("/user-profile/email/confirm", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def user_profile_email_confirm():
|
||||
|
||||
# Validate verify code for form
|
||||
def _check_code(cde):
|
||||
return user_api_client.check_verify_code(current_user.id, cde, 'email')
|
||||
form = ConfirmEmailForm(_check_code)
|
||||
|
||||
if NEW_EMAIL_PASSWORD_CONFIRMED not in session:
|
||||
return redirect('main.user_profile_email_authenticate')
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_user.email_address = session[NEW_EMAIL]
|
||||
del session[NEW_EMAIL]
|
||||
del session[NEW_EMAIL_PASSWORD_CONFIRMED]
|
||||
user_api_client.update_user(current_user)
|
||||
return redirect(url_for('.user_profile'))
|
||||
|
||||
return render_template(
|
||||
'views/user-profile/confirm.html',
|
||||
form_field=form.email_code,
|
||||
thing='email address'
|
||||
)
|
||||
|
||||
|
||||
@main.route("/user-profile/mobile-number", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def user_profile_mobile_number():
|
||||
|
||||
@@ -98,13 +98,13 @@ def test_should_show_authenticate_after_email_change(app_,
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_redirect_after_email_change_confirm(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_user,
|
||||
mock_verify_password,
|
||||
mock_send_verify_code,
|
||||
mock_is_email_unique):
|
||||
def test_should_redirect_to_profile_after_email_change_confirm(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_user,
|
||||
mock_verify_password,
|
||||
mock_send_verify_code,
|
||||
mock_is_email_unique):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
@@ -115,43 +115,6 @@ def test_should_redirect_after_email_change_confirm(app_,
|
||||
url_for('main.user_profile_email_authenticate'),
|
||||
data=data)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.user_profile_email_confirm', _external=True)
|
||||
|
||||
|
||||
def test_should_show_confirm_after_email_change(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_user):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
with client.session_transaction() as session:
|
||||
session['new-email-password-confirmed'] = True
|
||||
response = client.get(url_for('main.user_profile_email_confirm'))
|
||||
|
||||
assert 'Change your email address' in response.get_data(as_text=True)
|
||||
assert 'Confirm' in response.get_data(as_text=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_should_redirect_after_email_change_confirm(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_user,
|
||||
mock_check_verify_code):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
with client.session_transaction() as session:
|
||||
session['new-email-password-confirmed'] = True
|
||||
session['new-email'] = 'new_notify@notify.gov.uk'
|
||||
data = {'email_code': '12345'}
|
||||
response = client.post(
|
||||
url_for('main.user_profile_email_confirm'),
|
||||
data=data)
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.user_profile', _external=True)
|
||||
|
||||
Reference in New Issue
Block a user