Beispiel #1
0
def register_from_org_invite():
    invited_org_user = InvitedOrgUser.from_session()
    if not invited_org_user:
        abort(404)

    form = RegisterUserFromOrgInviteForm(invited_org_user, )
    form.auth_type.data = "sms_auth"

    if form.validate_on_submit():
        if form.organisation.data != invited_org_user.organisation or form.email_address.data != invited_org_user.email_address:
            abort(400)
        _do_registration(
            form,
            send_email=False,
            send_sms=True,
            organisation_id=invited_org_user.organisation,
        )
        invited_org_user.accept_invite()

        return redirect(url_for("main.verify"))
    return render_template(
        "views/register-from-org-invite.html",
        invited_org_user=invited_org_user,
        form=form,
    )
def activate_user(user_id):
    user = User.from_id(user_id)
    # the user will have a new current_session_id set by the API - store it in the cookie for future requests
    session['current_session_id'] = user.current_session_id
    organisation_id = session.get('organisation_id')
    activated_user = user.activate()
    activated_user.login()

    invited_user = InvitedUser.from_session()
    if invited_user:
        service_id = _add_invited_user_to_service(invited_user)
        service = Service.from_id(service_id)
        if service.has_permission('broadcast'):
            return redirect(
                url_for('main.broadcast_tour',
                        service_id=service.id,
                        step_index=1))
        return redirect(
            url_for('main.service_dashboard', service_id=service_id))

    invited_org_user = InvitedOrgUser.from_session()
    if invited_org_user:
        user_api_client.add_user_to_organisation(invited_org_user.organisation,
                                                 session['user_details']['id'])

    if organisation_id:
        return redirect(
            url_for('main.organisation_dashboard', org_id=organisation_id))
    else:
        return redirect(url_for('main.add_service', first='first'))
Beispiel #3
0
def test_invited_org_user_from_session_uses_id(client, mocker,
                                               mock_get_invited_org_user_by_id,
                                               sample_org_invite):
    session_dict = {'invited_org_user_id': sample_org_invite['id']}
    mocker.patch.dict('app.models.user.session',
                      values=session_dict,
                      clear=True)

    assert InvitedOrgUser.from_session().id == sample_org_invite['id']

    mock_get_invited_org_user_by_id.assert_called_once_with(
        sample_org_invite['id'])
Beispiel #4
0
def test_invited_org_user_from_session_returns_none_if_nothing_present(
        client, mocker):
    mocker.patch.dict('app.models.user.session', values={}, clear=True)
    assert InvitedOrgUser.from_session() is None