mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
109638656: Implementation of two factor verification
Validation of the code is done in the form, when the form.validate_on_submit is called the validate code methods are called as well.
This commit is contained in:
@@ -46,12 +46,7 @@ class TwoFactorForm(Form):
|
||||
Regexp(regex=verify_code, message='Code must be 5 digits')])
|
||||
|
||||
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
|
||||
validate_code(self.sms_code, session['sms_code'])
|
||||
|
||||
|
||||
class VerifyForm(Form):
|
||||
@@ -63,17 +58,18 @@ class VerifyForm(Form):
|
||||
Regexp(regex=verify_code, message='Code must be 5 digits')])
|
||||
|
||||
def validate_email_code(self, a):
|
||||
if self.email_code.data is not None:
|
||||
if checkpw(str(self.email_code.data), session['email_code']) is False:
|
||||
self.email_code.errors.append('Code does not match')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
validate_code(self.email_code, session['email_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
|
||||
validate_code(self.sms_code, session['sms_code'])
|
||||
|
||||
|
||||
def validate_code(field, code):
|
||||
if field.data is not None:
|
||||
if checkpw(str(field.data), code) is False:
|
||||
field.errors.append('Code does not match')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
return True
|
||||
|
||||
@@ -16,7 +16,6 @@ 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')
|
||||
|
||||
Reference in New Issue
Block a user