示例#1
0
class Permissions(BaseModel):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=True, unique=True)

    def __repr__(self):
        return '<Permissions %r>' % self.name
示例#2
0
class Functions(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False, unique=True)
    slug = db.Column(db.String(40))
    permissions = db.relationship('Permissions', secondary=function_permissions, lazy='subquery',
                                  backref=db.backref('funcitons', lazy=True))

    def __repr__(self):
        return '<Functions %r>' % self.name
示例#3
0
class User(db.Model, UserMixin):
    """[User]
    Parameters
    ----------
    username: [string]
        Unique username.
    email: [email]
        Unique email.
    image_file: [string]
        File path for the chosen profile picture.
        Default image is default.jpg.
    _password: [string]
        Hashed password.
        Extra functions are there to hash the password then store it.

    Relationships
    -------------
    None.
    """
    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    username = db.Column(db.String(50), unique=True, nullable=False)
    email = db.Column(db.String(50), unique=True, nullable=False)

    image_file = db.Column(db.String(30),
                           nullable=False,
                           default='default.jpg')

    _password = db.Column(db.String(128), nullable=False)

    def __repr__(self):
        return (f"User('{self.username}': '{self.email}')")

    @hybrid_property
    def password(self):
        return self._password

    @password.setter
    def password(self, password):
        self._password = bcrypt.generate_password_hash(password)

    def verify_password(self, password):
        return bcrypt.check_password_hash(self._password, password)

    @classmethod
    def __declare_last__(cls):
        # check_deliverability can be set to True
        # after the developer updated the release on PyPI.
        # https://github.com/xeBuz/Flask-Validator/issues/79
        ValidateEmail(User.email,
                      allow_smtputf8=True,
                      check_deliverability=True,
                      throw_exception=True,
                      message="The e-mail is invalid.")
示例#4
0
class Roles(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False, unique=True)
    description = db.Column(db.String(300))
    permissions = db.relationship('Permissions',
                                  secondary=role_permissions,
                                  lazy='subquery',
                                  backref=db.backref('roles', lazy=True))

    def __repr__(self):
        return '<Roles %r>' % self.name
示例#5
0
class BaseModel(db.Model):
    __abstract__ = True
    created_at = db.Column(db.DateTime, default=db.func.now())
    updated_at = db.Column(db.DateTime, onupdate=db.func.now())
    created_by = db.Column(db.Integer, nullable=True)
    updated_by = db.Column(db.Integer, nullable=True)
    # For soft delete function
    deleted_at = db.Column(db.DateTime, nullable=True)
    status = db.Column(db.String(300))
示例#6
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(120), unique=True, nullable=False)
    image_file = db.Column(db.String(20),
                           nullable=False,
                           default='default.jpg')
    password = db.Column(db.String(60), nullable=False)

    def get_reset_token(self, expires_sec=1800):
        s = Serializer(current_app.config['SECRET_KEY'], expires_sec)
        return s.dumps({'user_id': self.id}).decode('utf-8')

    @staticmethod
    def verify_reset_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            user_id = s.loads(token)['user_id']
        except:
            return None
        return User.query.get(user_id)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}', '{self.image_file}')"
示例#7
0
class Users(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(300), nullable=False, unique=True)
    first_name = db.Column(db.String(300), nullable=False,)
    last_name = db.Column(db.String(300))
    email = db.Column(db.String(300), nullable=False, unique=True)
    password = db.Column(db.String(300))
    roles = db.relationship('Roles', secondary=user_role, lazy='subquery',
                            backref=db.backref('users', lazy=True))
    permissions = db.relationship('Permissions', secondary=user_permission, lazy='subquery',
                                  backref=db.backref('users', lazy=True))

    def __repr__(self):
        return '<Users %r>' % self.username
示例#8
0
from boilerplate import db
from boilerplate.common.models import BaseModel


function_permissions = db.Table('function_permissions',
                                db.Column('function_id', db.Integer, db.ForeignKey(
                                    'functions.id'), primary_key=True),
                                db.Column('permission_id', db.Integer, db.ForeignKey(
                                    'permissions.id'), primary_key=True)
                                )


class Functions(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(40), nullable=False, unique=True)
    slug = db.Column(db.String(40))
    permissions = db.relationship('Permissions', secondary=function_permissions, lazy='subquery',
                                  backref=db.backref('funcitons', lazy=True))

    def __repr__(self):
        return '<Functions %r>' % self.name
示例#9
0
class UserDetails(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(300))
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
示例#10
0
from boilerplate import db
from boilerplate.common.models import BaseModel

user_role = db.Table('user_role',
                     db.Column('user_id', db.Integer, db.ForeignKey(
                         'users.id'), primary_key=True),
                     db.Column('role_id', db.Integer, db.ForeignKey(
                         'roles.id'), primary_key=True)
                     )

user_permission = db.Table('user_permission',
                           db.Column('user_id', db.Integer, db.ForeignKey(
                               'users.id'), primary_key=True),
                           db.Column('permission_id', db.Integer, db.ForeignKey(
                               'permissions.id'), primary_key=True)
                           )


class Users(BaseModel):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(300), nullable=False, unique=True)
    first_name = db.Column(db.String(300), nullable=False,)
    last_name = db.Column(db.String(300))
    email = db.Column(db.String(300), nullable=False, unique=True)
    password = db.Column(db.String(300))
    roles = db.relationship('Roles', secondary=user_role, lazy='subquery',
                            backref=db.backref('users', lazy=True))
    permissions = db.relationship('Permissions', secondary=user_permission, lazy='subquery',
                                  backref=db.backref('users', lazy=True))

    def __repr__(self):