Exemplo n.º 1
0
def test_activate_user_redirects_to_service_dashboard_if_user_already_belongs_to_service(
    mocker,
    client,
    service_one,
    sample_invite,
    api_user_active,
    mock_login,
):
    mocker.patch(
        'app.user_api_client.add_user_to_service',
        side_effect=HTTPError(
            response=Mock(
                status_code=400,
                json={
                    "result": "error",
                    "message": {
                        f"User id: {api_user_active['id']} already part of service id: {service_one['id']}"
                    }
                },
            ),
            message=
            f"User id: {api_user_active['id']} already part of service id: {service_one['id']}"
        ))

    # Can't use `with client.session_transaction()...` here since activate_session is not a view function
    flask_session['invited_user'] = sample_invite

    response = activate_user(api_user_active['id'])

    assert response.location == url_for('main.service_dashboard',
                                        service_id=service_one['id'])

    flask_session.pop('invited_user')
Exemplo n.º 2
0
def register_from_invite():
    invited_user = session.get('invited_user')
    if not invited_user:
        abort(404)

    is_sms_auth = invited_user['auth_type'] == 'sms_auth'

    form = RegisterUserFromInviteForm(invited_user)

    if form.validate_on_submit():
        if form.service.data != invited_user[
                'service'] or form.email_address.data != invited_user[
                    'email_address']:
            abort(400)
        _do_registration(form, send_email=False, send_sms=is_sms_auth)
        invite_api_client.accept_invite(invited_user['service'],
                                        invited_user['id'])
        if is_sms_auth:
            return redirect(url_for('main.verify'))
        else:
            # we've already proven this user has email because they clicked the invite link,
            # so just activate them straight away
            return activate_user(session['user_details']['id'])

    return render_template('views/register-from-invite.html',
                           invited_user=invited_user,
                           form=form)
Exemplo n.º 3
0
def register_from_invite():
    invited_user = InvitedUser.from_session()
    if not invited_user:
        abort(404)

    form = RegisterUserFromInviteForm(invited_user)

    if form.validate_on_submit():
        if form.service.data != invited_user.service or form.email_address.data != invited_user.email_address:
            abort(400)
        _do_registration(form,
                         send_email=False,
                         send_sms=invited_user.sms_auth)
        invited_user.accept_invite()
        if invited_user.sms_auth:
            return redirect(url_for("main.verify"))
        else:
            # we've already proven this user has email because they clicked the invite link,
            # so just activate them straight away
            return activate_user(session["user_details"]["id"])

    return render_template("views/register-from-invite.html",
                           invited_user=invited_user,
                           form=form)