Пример #1
0
 def process_step(self, form):
     if form.prefix == constants.USER_ACCOUNT:
         response = sso_api_client.user.create_user(
             email=form.cleaned_data['email'],
             password=form.cleaned_data['password'],
         )
         if response.status_code == 400:
             errors = response.json()
             if 'password' in errors:
                 self.storage.set_step_data(
                     constants.USER_ACCOUNT, {
                         form.add_prefix('remote_password_error'):
                         errors['password']
                     })
                 raise RemotePasswordValidationError(form)
             elif 'email' in errors:
                 helpers.notify_already_registered(
                     email=form.cleaned_data['email'],
                     form_url=self.request.path)
         else:
             response.raise_for_status()
             user_details = response.json()
             helpers.send_verification_code_email(
                 email=user_details['email'],
                 verification_code=user_details['verification_code'],
                 form_url=self.request.path,
                 verification_link=self.verification_link_url)
     return super().process_step(form)
def test_notify_already_registered(mock_submit):
    email = '*****@*****.**'
    form_url = 'test'

    mock_submit.return_value = create_response(status_code=201)
    helpers.notify_already_registered(
        email=email,
        form_url=form_url,
    )

    expected = {
        'data': {
            'login_url': settings.SSO_PROXY_LOGIN_URL,
            'password_reset_url': settings.SSO_PROXY_PASSWORD_RESET_URL,
            'contact_us_url': urls.domestic.FEEDBACK,
        },
        'meta': {
            'action_name': 'gov-notify-email',
            'form_url': form_url,
            'sender': {},
            'spam_control': {},
            'template_id': settings.GOV_NOTIFY_ALREADY_REGISTERED_TEMPLATE_ID,
            'email_address': email
        }
    }
    assert mock_submit.call_count == 1
    assert mock_submit.call_args == mock.call(expected)
Пример #3
0
 def render_next_step(self, form, **kwargs):
     response = super().render_next_step(form, **kwargs)
     if form.prefix == USER_ACCOUNT:
         # Check if we have a user, else the user is already registered
         if form.cleaned_data['user_details']:
             user_details = form.cleaned_data['user_details']
             helpers.send_verification_code_email(
                 email=user_details['email'],
                 verification_code=user_details['verification_code'],
                 form_url=self.request.path,
             )
         else:
             helpers.notify_already_registered(
                 email=form.cleaned_data['email'],
                 form_url=self.request.path)
     elif form.prefix == VERIFICATION:
         response.cookies.update(form.cleaned_data['cookies'])
     return response