<s> from datetime import datetime , timedelta <EOL> from app import db , bcrypt <EOL> from app . utils . misc import make_code <EOL> def expiration_date ( ) : <EOL> return datetime . now ( ) + timedelta ( days = <NUM_LIT:1> ) <EOL> class AppUser ( db . Model ) : <EOL> id = db . Column ( db . Integer ( ) , primary_key = True ) <EOL> email = db . Column ( db . String ( <NUM_LIT:255> ) , unique = True ) <EOL> password = db . Column ( db . String ( <NUM_LIT:255> ) ) <EOL> active = db . Column ( db . Boolean ( ) ) <EOL> is_admin = db . Column ( db . Boolean ( ) ) <EOL> def __init__ ( self , email , password , is_admin = False ) : <EOL> self . email = email <EOL> self . active = True <EOL> self . is_admin = is_admin <EOL> self . set_password ( password ) <EOL> def set_password ( self , password ) : <EOL> self . password = bcrypt . generate_password_hash ( password ) <EOL> def deactivate ( self ) : <EOL> self . active = False <EOL> class PasswordReset ( db . Model ) : <EOL> id = db . Column ( db . Integer ( ) , primary_key = True ) <EOL> user_id = db . Column ( db . Integer ( ) , db . ForeignKey ( '<STR_LIT>' ) ) <EOL> code = db . Column ( db . String ( <NUM_LIT:255> ) , unique = True , default = make_code ) <EOL> date = db . Column ( db . DateTime ( ) , default = expiration_date ) <EOL> user = db . relationship ( AppUser ) <EOL> db . UniqueConstraint ( '<STR_LIT>' , '<STR_LIT:code>' , name = '<STR_LIT>' ) <EOL> def __init__ ( self , user ) : <EOL> self . user = user </s>
