Esempio n. 1
0
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)
Esempio n. 2
0
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
Esempio n. 3
0
 def email(cls):
     return db.Column(db.String(512), nullable=False, unique=True)
Esempio n. 4
0
 def password(cls):
     return db.Column(db.String(512), nullable=False)
Esempio n. 5
0
 def username(cls):
     return db.Column(db.String(512), nullable=False, unique=True)
Esempio n. 6
0
 def description(cls):
     return db.Column(db.String(2048))
Esempio n. 7
0
 def resource_type(cls):
     return db.Column(db.String(81), nullable=False)
Esempio n. 8
0
 def resource(cls):
     return db.Column(db.String(1024), nullable=False)
Esempio n. 9
0
 def code(cls):
     return db.Column(db.String(81), default='0000')