コード例 #1
0
ファイル: user_role.py プロジェクト: JetQin/etl
class User(BaseModel):
    """ User Model for storing user related details """
    __tablename__ = "ETL_USER"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), unique=True)
    password_hash = db.Column(db.String(100))
    email = db.Column(db.String(255), unique=True, nullable=False)
    created_time = db.Column(db.DateTime, nullable=False, default=datetime.now())
    roles = db.relationship('Role', secondary=roles, cascade="save-update, merge, delete", lazy='subquery', backref=db.backref('users', lazy=True))

    @property
    def password(self):
        raise AttributeError('password: write-only field')

    @password.setter
    def password(self, password):
        self.password_hash = flask_bcrypt.generate_password_hash(password).decode('utf-8')

    def check_password(self, password):
        return flask_bcrypt.check_password_hash(self.password_hash, password)

    def as_dict(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns if c.name != 'password'}

    def __repr__(self):
        return "<User(id='%d', username='******', email='%s')>" % (self.id, self.username, self.email)
コード例 #2
0
ファイル: user_role.py プロジェクト: JetQin/etl
class Role(BaseModel):
    """ User Model for storing user related details """
    __tablename__ = "ETL_ROLE"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), unique=True, nullable=False)
    description = db.Column(db.String(100), unique=True)
    created_time = db.Column(db.DateTime, nullable=False, default=datetime.now())

    def __repr__(self):
        return "<Role(id='%d', name='%s')>" % (self.id, self.name)
コード例 #3
0
class User(Base, UserMixin):
    email = db.Column(db.String, unique=True)
    password = db.Column(db.String(255))
    active = db.Column(db.Boolean)
    created = db.Column(db.DateTime, default=datetime.utcnow)

    roles = db.relationship('Role',
                            secondary='user_role_assoc',
                            backref='users')

    def __repr__(self):
        return '<User(%s, %s)>' % (self.id, self.email)

    def __unicode__(self):
        return self.email
コード例 #4
0
class Base(db.Model):
    __abstract__ = True
    id = db.Column(db.Integer, primary_key=True)

    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()
コード例 #5
0
ファイル: revoke_token.py プロジェクト: JetQin/etl
class RevokeToken(db.Model):

    __tablename__ = "ETL_REVOKE_TOKEN"

    id = db.Column(db.Integer, primary_key=True)
    jti = db.Column(db.String(36), nullable=False)
    token_type = db.Column(db.String(10), nullable=False)
    user_identity = db.Column(db.String(50), nullable=False)
    revoked = db.Column(db.Boolean, nullable=False)
    expires = db.Column(db.DateTime, nullable=False)

    def to_dict(self):
        return {
            'token_id': self.id,
            'jti': self.jti,
            'token_type': self.token_type,
            'user_identity': self.user_identity,
            'revoked': self.revoked,
            'expires': self.expires
        }
コード例 #6
0
class UserRoleAssoc(db.Model):
    __tablename__ = 'user_role_assoc'
    user_id = db.Column(db.ForeignKey('user.id'), primary_key=True)
    role_id = db.Column(db.ForeignKey('role.id'), primary_key=True)
コード例 #7
0
class Role(Base, RoleMixin):
    name = db.Column(db.String)
    description = db.Column(db.String)

    def __repr__(self):
        return '<Role(%s, %s)>' % (self.id, self.name)
コード例 #8
0
ファイル: user_role.py プロジェクト: JetQin/etl
import flask_bcrypt
from datetime import datetime
from starter import db
from model.base_model import BaseModel


roles = db.Table('ETL_USER_ROLE',
                             db.Column('USER_ID', db.Integer, db.ForeignKey('ETL_USER.id'), primary_key=True),
                             db.Column('ROLE_ID', db.Integer, db.ForeignKey('ETL_ROLE.id'), primary_key=True))


class User(BaseModel):
    """ User Model for storing user related details """
    __tablename__ = "ETL_USER"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), unique=True)
    password_hash = db.Column(db.String(100))
    email = db.Column(db.String(255), unique=True, nullable=False)
    created_time = db.Column(db.DateTime, nullable=False, default=datetime.now())
    roles = db.relationship('Role', secondary=roles, cascade="save-update, merge, delete", lazy='subquery', backref=db.backref('users', lazy=True))

    @property
    def password(self):
        raise AttributeError('password: write-only field')

    @password.setter
    def password(self, password):
        self.password_hash = flask_bcrypt.generate_password_hash(password).decode('utf-8')

    def check_password(self, password):