1 class Role(UserMixin, db.Model): 2 __tablename__ = ‘Role‘ 3 id = db.Column(db.Integer, primary_key=True) 4 username = db.Column(db.String(64), nullable=True) 5 role = db.Column(db.String(64), nullable=True) 6 password = db.Column(db.String(64), nullable=True) 7 password_hash = db.Column(db.String(128), nullable=True) 8 9 role_art = db.relationship(‘Article‘, backref=‘roleart‘) 10 role_com = db.relationship(‘Comment‘, backref=‘rolecom‘) 11 12 @property 13 def password(self): 14 raise AttributeError(‘password is not readable attribute‘) #没有可读的明文密码属性 15 16 @password.setter #设置 哈希后的密码值 17 def password(self, password): 18 self.password_hash = generate_password_hash(password) 19 20 def verify_password(self, password): 21 return check_password_hash(self.password_hash, password)
时间: 2024-11-05 07:42:01