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.

50 lines
1.9 KiB

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