class User(db.Model, UserMixin, MailMixin, ModelMixin): __tablename__ = 'user' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(512), unique=True) email = db.Column(db.String(512), unique=True) password = db.Column(db.String(512), nullable=False) is_superuser = db.Column(db.Boolean, default=False) is_confirmed = db.Column(db.Boolean, default=False) register_time = db.Column(db.DateTime, default=datetime.now()) last_login = db.Column(db.DateTime, default=datetime.now()) groups = db.relationship(Group, secondary=user_group, lazy='dynamic', backref=db.backref('users', lazy='dynamic')) def __str__(self): return self.username def __repr__(self): return '<User %r>' % self.username def set_password(self, raw_password): self.password = generate_password_hash(raw_password) def check_password(self, raw_password): return check_password_hash(self.password, raw_password)
class Group(db.Model): __tablename__ = 'group' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(512), nullable=False, unique=True) def __str__(self): return self.name def __repr__(self): return '<Group %r>' % self.name
def email(cls): return db.Column(db.String(512), nullable=False, unique=True)
def password(cls): return db.Column(db.String(512), nullable=False)
def username(cls): return db.Column(db.String(512), nullable=False, unique=True)
def description(cls): return db.Column(db.String(2048))
def resource_type(cls): return db.Column(db.String(81), nullable=False)
def resource(cls): return db.Column(db.String(1024), nullable=False)
def code(cls): return db.Column(db.String(81), default='0000')