Refactor for code_not_received, sign_in, two_factor and verify.

This commit is contained in:
Nicholas Staples
2016-01-05 17:08:50 +00:00
parent 1f520116f0
commit 0ebacd6929
16 changed files with 336 additions and 321 deletions

View File

@@ -1,4 +1,5 @@
from flask import render_template, redirect, jsonify, session
from flask import (
render_template, redirect, jsonify, session, url_for)
from flask_login import login_user
from app.main import main
@@ -6,19 +7,14 @@ from app.main.dao import users_dao, verify_codes_dao
from app.main.forms import TwoFactorForm
@main.route("/two-factor", methods=['GET'])
def render_two_factor():
return render_template('views/two-factor.html', form=TwoFactorForm())
@main.route('/two-factor', methods=['POST'])
def process_two_factor():
@main.route('/two-factor', methods=['GET', 'POST'])
def two_factor():
form = TwoFactorForm()
if form.validate_on_submit():
user = users_dao.get_user_by_id(session['user_id'])
verify_codes_dao.use_code_for_user_and_type(user_id=user.id, code_type='sms')
login_user(user)
return redirect('/dashboard')
else:
return jsonify(form.errors), 400
return redirect(url_for('.dashboard'))
return render_template('views/two-factor.html', form=form)