old_contents: from main import db, app
  from passlib.apps import custom_app_context as pwd_context
  from itsdangerous import (TimedJSONWebSignatureSerializer
                            as Serializer, BadSignature, SignatureExpired)
  
  
  class User(db.Model):
      __tablename__ = 'users'
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(80), unique=True)
      password_hash = db.Column(db.String(128))
      email = db.Column(db.String(120), unique=True)
      admin = db.Column(db.Boolean)
      active = db.Column(db.Boolean)
  
      def __init__(self, username, password, email, admin=False, active=False):
          self.username = username
          self.email = email
          self.admin = admin
          self.hash_password(password)
          self.active = active
  
      def to_dict(self):
          dict = self.__dict__
          del dict['_sa_instance_state']
          del dict['password_hash']
          return dict
  
      def hash_password(self, password):
          self.password_hash = pwd_context.encrypt(password)
  
      def verify_password(self, password):
          return pwd_context.verify(password, self.password_hash)
  
      def generate_auth_token(self, expiration=600):
          s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
          return s.dumps({'id': self.id, "admin": self.admin, "username": self.username})
  
      @staticmethod
      def verify_auth_token(token):
          s = Serializer(app.config['SECRET_KEY'])
          try:
              data = s.loads(token)
          except SignatureExpired:
              return None  # valid token, but expired
          except BadSignature:
              return None  # invalid token
          user = User.query.get(data['id'])
          return user
  
      @staticmethod
      def get_required_attributes():
          return ['username', 'password', 'email']
  
      @staticmethod
      def get_admin_accounts():
          return User.query.filter_by(admin=True).all()
  
new_contents: from main import db, app
  from passlib.apps import custom_app_context as pwd_context
  from itsdangerous import (TimedJSONWebSignatureSerializer
                            as Serializer, BadSignature, SignatureExpired)
  
  
  class User(db.Model):
      __tablename__ = 'users'
      id = db.Column(db.Integer, primary_key=True)
      username = db.Column(db.String(80), unique=True)
      password_hash = db.Column(db.String(128))
      email = db.Column(db.String(120), unique=True)
      admin = db.Column(db.Boolean)
      active = db.Column(db.Boolean)
  
      def __init__(self, username, password, email, admin=False, active=False):
          self.username = username
          self.email = email
          self.admin = admin
          self.hash_password(password)
          self.active = active
  
      def to_dict(self):
          dict = self.__dict__
          del dict['_sa_instance_state']
          del dict['password_hash']
          return dict
  
      def hash_password(self, password):
          self.password_hash = pwd_context.encrypt(password)
  
      def verify_password(self, password):
          return pwd_context.verify(password, self.password_hash)
  
      def generate_auth_token(self, expiration=1800):
          s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
          return s.dumps({'id': self.id, "admin": self.admin, "username": self.username})
  
      @staticmethod
      def verify_auth_token(token):
          s = Serializer(app.config['SECRET_KEY'])
          try:
              data = s.loads(token)
          except SignatureExpired:
              return None  # valid token, but expired
          except BadSignature:
              return None  # invalid token
          user = User.query.get(data['id'])
          return user
  
      @staticmethod
      def get_required_attributes():
          return ['username', 'password', 'email']
  
      @staticmethod
      def get_admin_accounts():
          return User.query.filter_by(admin=True).all()
  
subject: Make token valid for 30 minutes