mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-31 11:49:58 -04:00
Working tests, hopefully all code changes done.
This commit is contained in:
@@ -14,32 +14,6 @@ class Blacklist(object):
|
||||
raise ValidationError(self.message)
|
||||
|
||||
|
||||
class ValidateUserCodes(object):
|
||||
def __init__(self,
|
||||
expiry_msg='Code has expired',
|
||||
invalid_msg='Code does not match',
|
||||
code_type=None):
|
||||
self.expiry_msg = expiry_msg
|
||||
self.invalid_msg = invalid_msg
|
||||
self.code_type = code_type
|
||||
|
||||
def __call__(self, form, field):
|
||||
# TODO would be great to do this sql query but
|
||||
# not couple those parts of the code.
|
||||
user_codes = getattr(form, 'user_codes', [])
|
||||
valid_code = False
|
||||
for code in user_codes:
|
||||
if check_hash(field.data, code.code) and self.code_type == code.code_type:
|
||||
if code.expiry_datetime <= datetime.now():
|
||||
raise ValidationError(self.expiry_msg)
|
||||
else:
|
||||
# Valid code
|
||||
valid_code = True
|
||||
break
|
||||
if not valid_code:
|
||||
raise ValidationError(self.invalid_msg)
|
||||
|
||||
|
||||
class CsvFileValidator(object):
|
||||
|
||||
def __init__(self, message='Not a csv file'):
|
||||
|
||||
Reference in New Issue
Block a user