mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
109526520: Add custom validators for the VerifyForm
If the email_code or sms_code entered does not pass check password, then add errors to the form.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from flask import session
|
||||
from flask_wtf import Form
|
||||
from wtforms import StringField, PasswordField, IntegerField
|
||||
from wtforms.validators import DataRequired, Email, Length, Regexp
|
||||
|
||||
from app.main.encryption import checkpw
|
||||
from app.main.validators import Blacklist
|
||||
|
||||
|
||||
@@ -43,3 +45,19 @@ class VerifyForm(Form):
|
||||
validators=[DataRequired(message='SMS code can not be empty')])
|
||||
email_code = IntegerField("Email confirmation code",
|
||||
validators=[DataRequired(message='Email code can not be empty')])
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user