text: from sqlalchemy.ext.declarative import declarative_base
  from sqlalchemy import Column, Integer, String
  from passlib.apps import custom_app_context as pwd_context
  from itsdangerous import (
      TimedJSONWebSignatureSerializer as Serializer,
      BadSignature,
      SignatureExpired)
  from base import Base
  from helpers import utils
  
  secret_key = utils.gen_random_text(32)
  
  
  class User(Base):
      __tablename__ = 'user'
      id = Column(Integer, primary_key=True)
      username = Column(String(250), index=True)
      password_hash = Column(String(250))
      name = Column(String(250), nullable=False)
      picture = Column(String(250))
  
      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(secret_key, expires_in=expiration)
          return s.dumps({'id': self.id})
  
      @staticmethod
      def verify_auth_token(token):
          s = Serializer(secret_key)
          try:
              data = s.loads(token)
          except SignatureExpired:
              # Valid Token, but expired
              return None
          except BadSignature:
              # Invalid Token
              return None
          user_id = data['id']
          return user_id
  
      @property
      def serialize(self):
          return {
              'id': self.id,
              'username': self.username,
              'name': self.name
          }
  