コード例 #1
0
def two_factor():
    user_id = session['user_details']['id']

    def _check_code(code):
        return user_api_client.check_verify_code(user_id, code, "sms")

    form = TwoFactorForm(_check_code)

    if form.validate_on_submit():
        try:
            user = user_api_client.get_user(user_id)
            services = service_api_client.get_services({'user_id': str(user_id)}).get('data', [])
            # Check if coming from new password page
            if 'password' in session['user_details']:
                user.set_password(session['user_details']['password'])
                user.reset_failed_login_count()
                user_api_client.update_user(user)
            login_user(user, remember=True)
        finally:
            del session['user_details']

        next_url = request.args.get('next')
        if next_url and _is_safe_redirect_url(next_url):
            return redirect(next_url)

        if current_user.platform_admin:
            return redirect(url_for('main.show_all_services'))
        if len(services) == 1:
            return redirect(url_for('main.service_dashboard', service_id=services[0]['id']))
        else:
            return redirect(url_for('main.choose_service'))

    return render_template('views/two-factor.html', form=form)
コード例 #2
0
def user_profile_name():

    form = ChangeNameForm(new_name=current_user.name)

    if form.validate_on_submit():
        current_user.name = form.new_name.data
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template('views/user-profile/change.html',
                           thing='name',
                           form_field=form.new_name)
コード例 #3
0
def user_profile_email_confirm(token):

    token_data = check_token(token, current_app.config['SECRET_KEY'],
                             current_app.config['DANGEROUS_SALT'],
                             current_app.config['EMAIL_EXPIRY_SECONDS'])
    token_data = json.loads(token_data)
    user_id = token_data['user_id']
    new_email = token_data['email']
    user = user_api_client.get_user(user_id)
    user.email_address = new_email
    user_api_client.update_user(user)
    session.pop(NEW_EMAIL, None)

    return redirect(url_for('.user_profile'))
コード例 #4
0
def check_and_resend_text_code():
    user = user_api_client.get_user_by_email(session['user_details']['email'])

    if user.state == 'active':
        # this is a verified user and therefore redirect to page to request resend without edit mobile
        return render_template('views/verification-not-received.html')

    form = TextNotReceivedForm(mobile_number=user.mobile_number)
    if form.validate_on_submit():
        user_api_client.send_verify_code(user.id, 'sms', to=form.mobile_number.data)
        user.mobile_number = form.mobile_number.data
        user_api_client.update_user(user)
        return redirect(url_for('.verify'))

    return render_template('views/text-not-received.html', form=form)
コード例 #5
0
def user_profile_password():

    # Validate password for form
    def _check_password(pwd):
        return user_api_client.verify_password(current_user.id, pwd)

    form = ChangePasswordForm(_check_password)

    if form.validate_on_submit():
        current_user.set_password(form.new_password.data)
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template('views/user-profile/change-password.html',
                           form=form)
コード例 #6
0
def user_profile_password():

    # Validate password for form
    def _check_password(pwd):
        return user_api_client.verify_password(current_user.id, pwd)
    form = ChangePasswordForm(_check_password)

    if form.validate_on_submit():
        current_user.set_password(form.new_password.data)
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template(
        'views/user-profile/change-password.html',
        form=form
    )
コード例 #7
0
def check_and_resend_text_code():
    user = user_api_client.get_user_by_email(session['user_details']['email'])

    if user.state == 'active':
        # this is a verified user and therefore redirect to page to request resend without edit mobile
        return render_template('views/verification-not-received.html')

    form = TextNotReceivedForm(mobile_number=user.mobile_number)
    if form.validate_on_submit():
        user_api_client.send_verify_code(user.id,
                                         'sms',
                                         to=form.mobile_number.data)
        user.mobile_number = form.mobile_number.data
        user_api_client.update_user(user)
        return redirect(url_for('.verify'))

    return render_template('views/text-not-received.html', form=form)
コード例 #8
0
def user_profile_mobile_number_confirm():

    # Validate verify code for form
    def _check_code(cde):
        return user_api_client.check_verify_code(current_user.id, cde, 'sms')

    if NEW_MOBILE_PASSWORD_CONFIRMED not in session:
        return redirect(url_for('.user_profile_mobile_number'))

    form = ConfirmMobileNumberForm(_check_code)

    if form.validate_on_submit():
        current_user.mobile_number = session[NEW_MOBILE]
        del session[NEW_MOBILE]
        del session[NEW_MOBILE_PASSWORD_CONFIRMED]
        user_api_client.update_user(current_user)
        return redirect(url_for('.user_profile'))

    return render_template('views/user-profile/confirm.html',
                           form_field=form.sms_code,
                           thing='mobile number')
コード例 #9
0
def two_factor():
    user_id = session['user_details']['id']

    def _check_code(code):
        return user_api_client.check_verify_code(user_id, code, "sms")

    form = TwoFactorForm(_check_code)

    if form.validate_on_submit():
        try:
            user = user_api_client.get_user(user_id)
            services = service_api_client.get_services({
                'user_id': str(user_id)
            }).get('data', [])
            # Check if coming from new password page
            if 'password' in session['user_details']:
                user.set_password(session['user_details']['password'])
                user.reset_failed_login_count()
                user_api_client.update_user(user)
            activated_user = user_api_client.activate_user(user)
            login_user(activated_user, remember=True)
        finally:
            del session['user_details']

        next_url = request.args.get('next')
        if next_url and _is_safe_redirect_url(next_url):
            return redirect(next_url)

        if current_user.platform_admin:
            return redirect(url_for('main.show_all_services'))
        if len(services) == 1:
            return redirect(
                url_for('main.service_dashboard',
                        service_id=services[0]['id']))
        else:
            return redirect(url_for('main.choose_service'))

    return render_template('views/two-factor.html', form=form)