An ebook/comic library service and web client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.8 KiB

  1. """
  2. User related SQLALchemy models
  3. """
  4. from atheneum import db
  5. class User(db.Model): # pylint: disable=too-few-public-methods
  6. """
  7. Represents a user in the system
  8. """
  9. __tablename__ = 'user'
  10. ROLE_USER = 'USER'
  11. ROLE_ADMIN = 'ADMIN'
  12. id = db.Column(db.Integer, primary_key=True)
  13. name = db.Column(db.Unicode(60), unique=True, nullable=False)
  14. role = db.Column(
  15. 'role',
  16. db.Unicode(32),
  17. nullable=False,
  18. default=ROLE_USER, )
  19. password_hash = db.Column('password_hash', db.Unicode(128), nullable=False)
  20. password_revision = db.Column(
  21. 'password_revision', db.SmallInteger, default=0, nullable=False)
  22. creation_time = db.Column('creation_time', db.DateTime, nullable=False)
  23. last_login_time = db.Column('last_login_time', db.DateTime)
  24. version = db.Column('version', db.Integer, default=1, nullable=False)
  25. class UserToken(db.Model): # pylint: disable=too-few-public-methods
  26. """
  27. Represents a token used alongside a user to authenticate operations
  28. """
  29. __tablename__ = 'user_token'
  30. user_token_id = db.Column('id', db.Integer, primary_key=True)
  31. user_id = db.Column(
  32. 'user_id',
  33. db.Integer,
  34. db.ForeignKey('user.id', ondelete='CASCADE'),
  35. nullable=False,
  36. index=True)
  37. token = db.Column('token', db.Unicode(36), nullable=False)
  38. note = db.Column('note', db.Unicode(128), nullable=True)
  39. enabled = db.Column('enabled', db.Boolean, nullable=False, default=True)
  40. expiration_time = db.Column('expiration_time', db.DateTime, nullable=True)
  41. creation_time = db.Column('creation_time', db.DateTime, nullable=False)
  42. last_edit_time = db.Column('last_edit_time', db.DateTime)
  43. last_usage_time = db.Column('last_usage_time', db.DateTime)
  44. version = db.Column('version', db.Integer, default=1, nullable=False)