mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-26 02:49:16 -04:00
109638656: Implement two factor verify flow
When user enters valid sms code they are redirected to the dashboard. Otherwise, form errors are present.
This commit is contained in:
@@ -44,6 +44,14 @@ class RegisterUserForm(Form):
|
||||
class TwoFactorForm(Form):
|
||||
sms_code = IntegerField('sms code', validators=[DataRequired(message='Please enter your code')])
|
||||
|
||||
def validate_sms_code(self, a):
|
||||
if self.sms_code.data is not None:
|
||||
if checkpw(str(self.sms_code.data), session['sms_code']) is False:
|
||||
self.sms_code.errors.append('Code does not match')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class VerifyForm(Form):
|
||||
sms_code = StringField("Text message confirmation code",
|
||||
|
||||
@@ -27,4 +27,4 @@ def send_email_code(email):
|
||||
except:
|
||||
raise AdminApiClientException('Exception when sending email.')
|
||||
|
||||
return email_code
|
||||
return email_code
|
||||
|
||||
@@ -43,6 +43,3 @@ def process_register():
|
||||
else:
|
||||
return jsonify(form.errors), 400
|
||||
return redirect('/verify')
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from flask import render_template, redirect, jsonify
|
||||
from flask import render_template, redirect, jsonify, session
|
||||
from flask_login import login_user
|
||||
|
||||
from app.main import main
|
||||
from app.main.dao import users_dao
|
||||
from app.main.forms import TwoFactorForm
|
||||
|
||||
|
||||
@@ -15,6 +16,8 @@ def process_two_factor():
|
||||
form = TwoFactorForm()
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
user = users_dao.get_user_by_id(session['user_id'])
|
||||
login_user(user)
|
||||
return redirect('/dashboard')
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user