mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 23:26:23 -05:00
Move VERIFY_CODE_TYPES outside the class and use it in the schema
This commit is contained in:
@@ -155,16 +155,18 @@ class Job(db.Model):
|
||||
onupdate=datetime.datetime.now)
|
||||
|
||||
|
||||
VERIFY_CODE_TYPES = ['email', 'sms']
|
||||
|
||||
|
||||
class VerifyCode(db.Model):
|
||||
__tablename__ = 'verify_codes'
|
||||
|
||||
code_types = ['email', 'sms']
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), index=True, nullable=False)
|
||||
user = db.relationship('User', backref=db.backref('verify_codes', lazy='dynamic'))
|
||||
_code = db.Column(db.String, nullable=False)
|
||||
code_type = db.Column(db.Enum(*code_types, name='verify_code_types'), index=False, unique=False, nullable=False)
|
||||
code_type = db.Column(db.Enum(*VERIFY_CODE_TYPES, name='verify_code_types'),
|
||||
index=False, unique=False, nullable=False)
|
||||
expiry_datetime = db.Column(db.DateTime, nullable=False)
|
||||
code_used = db.Column(db.Boolean, default=False)
|
||||
created_at = db.Column(
|
||||
|
||||
@@ -60,7 +60,7 @@ class JobSchema(BaseSchema):
|
||||
|
||||
class RequestVerifyCodeSchema(ma.Schema):
|
||||
def verify_code_type(self):
|
||||
if self not in ['sms', 'email']:
|
||||
if self not in models.VERIFY_CODE_TYPES:
|
||||
raise ValidationError('Invalid code type')
|
||||
|
||||
code_type = fields.Str(required=True, validate=verify_code_type)
|
||||
|
||||
Reference in New Issue
Block a user