Merge pull request #926 from alphagov/add-redirect-for-email-verification

Redirect and resend verification email when pending user attempts to login
This commit is contained in:
imdadahad
2016-09-07 14:23:56 +01:00
committed by GitHub
2 changed files with 17 additions and 5 deletions
+1 -2
View File
@@ -38,8 +38,7 @@ def sign_in():
user = user_api_client.get_user_by_email_or_none(form.email_address.data) user = user_api_client.get_user_by_email_or_none(form.email_address.data)
user = _get_and_verify_user(user, form.password.data) user = _get_and_verify_user(user, form.password.data)
if user and user.state == 'pending': if user and user.state == 'pending':
flash("You haven't verified your email or mobile number yet.") return redirect(url_for('main.resend_email_verification'))
return redirect(url_for('main.sign_in'))
if user and session.get('invited_user'): if user and session.get('invited_user'):
invited_user = session.get('invited_user') invited_user = session.get('invited_user')
+16 -3
View File
@@ -51,7 +51,8 @@ def test_should_return_locked_out_true_when_user_is_locked(app_,
assert 'The email address or password you entered is incorrect' in resp.get_data(as_text=True) assert 'The email address or password you entered is incorrect' in resp.get_data(as_text=True)
def test_should_return_200_when_user_does_not_exist(app_, mock_get_user_by_email_not_found): def test_should_return_200_when_user_does_not_exist(app_,
mock_get_user_by_email_not_found):
with app_.test_request_context(): with app_.test_request_context():
response = app_.test_client().post( response = app_.test_client().post(
url_for('main.sign_in'), data={ url_for('main.sign_in'), data={
@@ -69,10 +70,22 @@ def test_should_return_redirect_when_user_is_pending(app_,
url_for('main.sign_in'), data={ url_for('main.sign_in'), data={
'email_address': 'pending_user@example.gov.uk', 'email_address': 'pending_user@example.gov.uk',
'password': 'val1dPassw0rd!'}, follow_redirects=True) 'password': 'val1dPassw0rd!'}, follow_redirects=True)
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.h1.string == 'Sign in' assert page.h1.string == 'Sign in'
flash_banner = page.find('div', class_='banner-dangerous').string.strip() assert response.status_code == 200
assert flash_banner == "You haven't verified your email or mobile number yet."
def test_should_attempt_redirect_when_user_is_pending(app_,
mock_get_user_by_email_pending,
mock_verify_password):
with app_.test_request_context():
response = app_.test_client().post(
url_for('main.sign_in'), data={
'email_address': 'pending_user@example.gov.uk',
'password': 'val1dPassw0rd!'})
assert response.location == url_for('main.resend_email_verification', _external=True)
assert response.status_code == 302
def test_not_fresh_session_login(app_, def test_not_fresh_session_login(app_,