33
44from random import choice
55
6- from passlib .hash import pbkdf2_sha256 as sha256
76from sqlalchemy import Boolean , Column , ForeignKey , Index , Integer , JSON , DATE , String , DateTime , TIMESTAMP , func , \
87 Numeric , UniqueConstraint , UUID
98from sqlalchemy .ext .declarative import declarative_base , declared_attr
@@ -64,7 +63,6 @@ class User(Base):
6463 updated_at = Column (TIMESTAMP , server_default = func .now ())
6564
6665 # Relationships
67- password_resets = relationship ("PasswordReset" , backref = "user" )
6866 email_verifications = relationship ("EmailVerification" , backref = "user" )
6967
7068 avatar = relationship ("Image" ,
@@ -118,13 +116,6 @@ def to_dict(self):
118116 "trips" : active_trips ,
119117 }
120118
121- @staticmethod
122- def generate_hash (password ):
123- return sha256 .hash (password )
124-
125- @staticmethod
126- def verify_hash (password , hash ):
127- return sha256 .verify (password , hash )
128119
129120
130121class Item (Base ):
@@ -465,10 +456,11 @@ class Reported(Base):
465456 DateTime , default = datetime .datetime .utcnow , nullable = False )
466457
467458
468- class PasswordReset (Base ):
459+ class EmailVerification (Base ):
469460 id = Column (Integer , primary_key = True , index = True , autoincrement = True )
470461 user_id = Column (Integer , ForeignKey ("user.id" ))
471462 callback_id = Column (String )
463+ created_at = Column (DateTime , default = datetime .datetime .utcnow , nullable = False )
472464
473465 def __init__ (self , user_id ):
474466 self .callback_id = self .generate_callback_id ()
@@ -479,16 +471,11 @@ def generate_callback_id():
479471 return '' .join (choice ('0123456789ABCDEF' ) for i in range (16 ))
480472
481473
482- class EmailVerification (Base ):
474+ class AuthOtp (Base ):
483475 id = Column (Integer , primary_key = True , index = True , autoincrement = True )
484- user_id = Column (Integer , ForeignKey ("user.id" ))
485- callback_id = Column (String )
476+ email = Column (String , nullable = False , index = True )
477+ otp_code = Column (String (6 ), nullable = False )
478+ username = Column (String (15 ), nullable = True )
479+ is_registration = Column (Boolean , default = False , nullable = False )
480+ expires_at = Column (DateTime , nullable = False )
486481 created_at = Column (DateTime , default = datetime .datetime .utcnow , nullable = False )
487-
488- def __init__ (self , user_id ):
489- self .callback_id = self .generate_callback_id ()
490- self .user_id = user_id
491-
492- @staticmethod
493- def generate_callback_id ():
494- return '' .join (choice ('0123456789ABCDEF' ) for i in range (16 ))
0 commit comments