diff --git a/app/main/views/invites.py b/app/main/views/invites.py index 662d66cec..44d00296c 100644 --- a/app/main/views/invites.py +++ b/app/main/views/invites.py @@ -33,6 +33,7 @@ def accept_invite(token): session['invited_user'] = invited_user.serialize() if existing_user: + user_api_client.add_user_to_service(invited_user.service, existing_user.id, invited_user.permissions) diff --git a/app/main/views/register.py b/app/main/views/register.py index 7400f113d..eaeeaf150 100644 --- a/app/main/views/register.py +++ b/app/main/views/register.py @@ -51,7 +51,7 @@ def register_from_invite(): form.service.data = invited_user['service'] form.email_address.data = invited_user['email_address'] - return render_template('views/register-from-invite.html', form=form) + return render_template('views/register-from-invite.html', email_address=invited_user['email_address'], form=form) def _do_registration(form, service=None): diff --git a/app/main/views/sign_in.py b/app/main/views/sign_in.py index c2931b1cd..5b598e4ae 100644 --- a/app/main/views/sign_in.py +++ b/app/main/views/sign_in.py @@ -45,6 +45,11 @@ def sign_in(): # Vague error message for login in case of user not known, locked, inactive or password not verified flash('Username or password is incorrect') + invited_user = session.get('invited_user') + if invited_user: + message = 'You already have an account with GOV.UK Notify. Sign in to your account to accept this invitation.' + flash(message, 'default') + return render_template('views/signin.html', form=form) diff --git a/app/templates/views/register-from-invite.html b/app/templates/views/register-from-invite.html index 7e7e81aaa..df9cf8221 100644 --- a/app/templates/views/register-from-invite.html +++ b/app/templates/views/register-from-invite.html @@ -11,6 +11,7 @@ Create an account – GOV.UK Notify

Create an account

+

Your account will be created with this email: {{email_address}}

{{ textbox(form.name, width='3-4') }} {{ textbox(form.mobile_number, width='3-4') }} diff --git a/tests/app/main/views/test_accept_invite.py b/tests/app/main/views/test_accept_invite.py index a302def3f..3e48e1f73 100644 --- a/tests/app/main/views/test_accept_invite.py +++ b/tests/app/main/views/test_accept_invite.py @@ -58,6 +58,10 @@ def test_existing_signed_out_user_accept_invite_redirects_to_sign_in(app_, assert response.status_code == 200 page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Sign in' + flash_banners = page.find_all('div', class_='banner-default') + assert len(flash_banners) == 2 + assert flash_banners[0].text.strip() == 'Please log in to access this page.' + assert flash_banners[1].text.strip() == 'You already have an account with GOV.UK Notify. Sign in to your account to accept this invitation.' # noqa def test_new_user_accept_invite_calls_api_and_redirects_to_registration(app_, @@ -100,6 +104,9 @@ def test_new_user_accept_invite_calls_api_and_views_registration_page(app_, page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser') assert page.h1.string.strip() == 'Create an account' + email_in_page = page.find('p') + assert email_in_page.text.strip() == 'Your account will be created with this email: invited_user@test.gov.uk' # noqa + form = page.find('form') name = form.find('input', id='name') password = form.find('input', id='password')