Esempio n. 1
0
class Student(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    s_name = db.Column(db.String(16), unique=True)
    _s_password = db.Column(db.String(256))
    s_permission = db.Column(db.Integer, default=PERMISSION_STUDENT_LEARN)

    @property
    def s_password(self):
        raise Exception("can't access")

    @s_password.setter
    def s_password(self, password):
        self._s_password = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self._s_password, password)

    def check_permission(self, permission):
        return self.s_permission & permission == permission

    def save(self):
        try:
            db.session.add(self)
            db.session.commit()
        except Exception as e:
            print(e)
            return False
        else:
            return True
Esempio n. 2
0
class AdminUser(BaseModel):
    username = db.Column(db.String(32), unique=True)
    _password = db.Column(db.String(256))
    phone = db.Column(db.String(32), unique=True)
    is_delete = db.Column(db.Boolean, default=False)
    permission = db.Column(db.Integer, default=PERMISSION_NONE)

    # set password
    @property
    def password(self):
        raise ValueError("password can't read")

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

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

    # 检查权限
    def verify_permission(self, permission):
        if (BLACK_USER & self.permission) == BLACK_USER:
            return False
        else:
            return permission & self.permission == permission
Esempio n. 3
0
class User(db.Model):
    id = db.Column(db.Integer,primary_key=True)
    username = db.Column(db.String(255),unique=True,nullable=False)
    password_hash = db.Column(db.String(255),nullable=False)
    email = db.Column(db.String(255),unique=True,nullable=False)
    create_time = db.Column(db.DATETIME,nullable=False,default=datetime.now)
    activation = db.Column(db.Boolean,default=False)
    gender = db.Column(db.String(10),default='秘密')
    signature = db.Column(db.Text,default='飒飒大苏打')
    avatar = db.Column(db.String(300),default='')

    # 保护字段
    @property
    def password(self):
        raise AttributeError('密码是不可读属性')

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

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

    # 生产token
    def generate_token(self):
        s = Serializer(current_app.config['SECRET_KEY'],expires_in=current_app.config['EXPIRES_IN_TOKEN'])
        return s.dumps({'id': self.id})

    # 校验
    @staticmethod
    def check_token(token):
        s = Serializer(current_app.config['SECRET_KEY'])
        try:
            data = s.loads(token)
        except:
            return False

        user = User.query.get(data.get('id'))
        if user is None:
            return False
        if not user.activation:
            user.activation = True
            db.session.add(user)
        return True
Esempio n. 4
0
class City(BaseModel):
    # 字母
    letter = db.Column(db.Integer, db.ForeignKey(Letter.id))
    c_id = db.Column(db.Integer, default=0)
    c_parentId = db.Column(db.Integer, default=0)
    c_regionName = db.Column(db.String(16))
    c_cityCode = db.Column(db.Integer, default=0)
    c_pinYin = db.Column(db.String(64))
Esempio n. 5
0
class AdminUser(BaseModel):
    __table_args__ = {'extend_existing': True}
    username = db.Column(db.String(32), unique=True)
    _password = db.Column(db.String(256))
    is_super = db.Column(db.Boolean, default=False)
    is_delete = db.Column(db.Boolean, default=False)
    permission = db.Column(db.Integer, default=PERMISSION_COMMON)

    # set password
    @property
    def password(self):
        raise ValueError("password can't read")

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

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

    # 检查权限
    def verify_permission(self, permission):
        return self.is_super or permission & self.permission == permission
Esempio n. 6
0
class BaseModel(db.Model):
    __abstract__ = True

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

    def save(self):
        try:
            db.session.add(self)
            db.session.commit()
            return True
        except Exception as e:
            print(e)
            return False

    def delete(self):
        try:
            db.session.delete(self)
            db.session.commit()
            return True
        except Exception as e:
            print(e)
            return False
Esempio n. 7
0
class Animal(db.Model):

    id = db.Column(db.Integer, autoincrement=True, primary_key=True)
    a_name = db.Column(db.String(32))
Esempio n. 8
0
class Letter(BaseModel):
    letter = db.Column(db.String(1), unique=True)
Esempio n. 9
0
class Movie(BaseModel):
    __tablename__ = "movies"
    showname = db.Column(db.String(64))
    shownameen = db.Column(db.String(256))
    director = db.Column(db.String(64))
    leadingRole = db.Column(db.String(256))
    movie_type = db.Column(db.String(64))
    country = db.Column(db.String(64))
    language = db.Column(db.String(64))
    duration = db.Column(db.Integer, default=90)  # 电影时长
    screeningmodel = db.Column(db.String(32))
    openday = db.Column(db.DateTime)  # 上映日期
    flag = db.Column(db.Boolean, default=False)  # t推荐
    is_delete = db.Column(db.Boolean, default=True)  # 逻辑删除
Esempio n. 10
0
class Student(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20), nullable=False)
    age = db.Column(db.Integer, nullable=False)
Esempio n. 11
0
class Animal(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20))