A multipurpose python flask API server and administration SPA
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.

47 lines
1.8 KiB

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