Changed registration flow to first send email verification link that

when visited sends sms code for second step of account verification.

At that second step user enters just sms code sent to users mobile
number.

Also moved dao calls that simply proxied calls to client to calling
client directly.

There is still a place where a user will be a sent a code for
verification to their email namely if they update email address.
This commit is contained in:
Adam Shimali
2016-03-17 13:07:52 +00:00
parent dcc253bf61
commit 2792bece54
23 changed files with 363 additions and 481 deletions

View File

@@ -1,35 +1,32 @@
from flask import (
render_template, redirect, session, url_for)
from flask_login import current_user
render_template,
redirect,
session,
url_for
)
from app import user_api_client
from app.main import main
from app.main.dao import users_dao
from app.main.forms import EmailNotReceivedForm, TextNotReceivedForm
from app.main.forms import TextNotReceivedForm
@main.route('/email-not-received', methods=['GET', 'POST'])
def check_and_resend_email_code():
@main.route('/resend-email-verification')
def resend_email_verification():
# TODO there needs to be a way to regenerate a session id
user = users_dao.get_user_by_email(session['user_details']['email'])
form = EmailNotReceivedForm(email_address=user.email_address)
if form.validate_on_submit():
users_dao.send_verify_code(user.id, 'email', to=form.email_address.data)
user.email_address = form.email_address.data
users_dao.update_user(user)
return redirect(url_for('.verify'))
return render_template('views/email-not-received.html', form=form)
user = user_api_client.get_user_by_email(session['user_details']['email'])
user_api_client.send_verify_email(user.id, user.email_address)
return render_template('views/resend-email-verification.html', email=user.email_address)
@main.route('/text-not-received', methods=['GET', 'POST'])
def check_and_resend_text_code():
# TODO there needs to be a way to regenerate a session id
user = users_dao.get_user_by_email(session['user_details']['email'])
user = user_api_client.get_user_by_email(session['user_details']['email'])
form = TextNotReceivedForm(mobile_number=user.mobile_number)
if form.validate_on_submit():
users_dao.send_verify_code(user.id, 'sms', to=form.mobile_number.data)
user_api_client.send_verify_code(user.id, 'sms', to=form.mobile_number.data)
user.mobile_number = form.mobile_number.data
users_dao.update_user(user)
user_api_client.update_user(user)
return redirect(url_for('.verify'))
return render_template('views/text-not-received.html', form=form)
@@ -42,6 +39,6 @@ def verification_code_not_received():
@main.route('/send-new-code', methods=['GET'])
def check_and_resend_verification_code():
# TODO there needs to be a way to generate a new session id
user = users_dao.get_user_by_email(session['user_details']['email'])
users_dao.send_verify_code(user.id, 'sms', user.mobile_number)
user = user_api_client.get_user_by_email(session['user_details']['email'])
user_api_client.send_verify_code(user.id, 'sms', user.mobile_number)
return redirect(url_for('main.two_factor'))