コード例 #1
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
コード例 #2
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.")
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
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))
コード例 #7
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}')"
コード例 #8
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'))