class SUP_Permission_Menu_Model(db.Model): """Permission And menu Link""" __tablename__ = 'permission_menu' id = db.Column(db.Integer, primary_key=True) permissionId = db.Column(db.ForeignKey(Support_Permission_Models.id)) menuId = db.Column(db.ForeignKey(Support_Menu_Models.id))
class SUP_User_Role_Models(db.Model): """User And Role Link Table""" __tablename__ = 'user_role' id = db.Column(db.Integer, primary_key=True) UserId = db.Column(db.ForeignKey(Support_User_Models.id)) RoleId = db.Column(db.ForeignKey(Support_Role_Models.id)) def to_json(self): json_data = { "id": self.UserId, "username": self.support_user.username, "roleName": self.support_role.roleName, "roleDesc": self.support_role.roleDesc } return json_data
class Support_Role_Models(db.Model): """Role List""" __tablename__ = "support_role" id = db.Column(db.Integer, primary_key=True) roleName = db.Column(db.String(32), unique=True, nullable=False) roleDesc = db.Column(db.String(128)) roleList1 = db.relationship("SUP_Permission_Role_Models", backref='support_role', lazy='dynamic') roleList2 = db.relationship("SUP_User_Role_Models", backref='support_role', lazy='dynamic') def to_json(self): json_data = { "id": self.id, "roleName": self.roleName, "roleDesc": self.roleDesc, } return json_data
class SUP_Permission_Role_Models(db.Model): """ Role And Permission Link""" __tablename__ = 'permission_role' id = db.Column(db.Integer, primary_key=True) permissionId = db.Column(db.ForeignKey(Support_Permission_Models.id)) roleId = db.Column(db.ForeignKey(Support_Role_Models.id)) def to_json(self): json_data = { "id": self.id, "roleId": self.support_role.id, "permissionId": self.support_permission.id, "roleName": self.support_role.roleName, "roleDesc": self.support_role.roleDesc, "permissionName": self.support_permission.name, "permissionPdesc": self.support_permission.pdesc } return json_data
class Support_Operation_Models(db.Model): """Operation List""" __tablename__ = "support_operation" id = db.Column(db.Integer, primary_key=True) odesc = db.Column(db.String(128)) name = db.Column(db.String(32), unique=True, nullable=False) operation = db.Column(db.String(128)) Operation_list = db.relationship("SUP_Permission_Operation_Models", backref='support_operation', lazy='dynamic') def to_json(self): json_data = { "id": self.id, "odesc": self.odesc, "name": self.name, "operation": self.operation } return json_data
class Support_Permission_Models(db.Model): """Permission List""" __tablename__ = "support_permission" id = db.Column(db.Integer, primary_key=True) pdesc = db.Column(db.String(128)) name = db.Column(db.String(32), unique=True, nullable=False) Permission_to_list1 = db.relationship("SUP_Permission_Operation_Models", backref='support_permission', lazy='dynamic') Permission_to_list2 = db.relationship("SUP_Permission_Role_Models", backref="support_permission", lazy='dynamic') Permission_to_list3 = db.relationship("SUP_Permission_Menu_Model", backref="support_permission", lazy='dynamic') def to_json(self): json_data = {"id": self.id, "pdesc": self.pdesc, "name": self.name} return json_data
class Support_User_Models(db.Model): """User List""" __tablename__ = "support_user" id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(32), unique=True, nullable=False) password = db.Column(db.String(128)) phone = db.Column(db.String(11)) email = db.Column(db.String(32)) mark = db.Column(db.String(128)) lastLogin = db.Column(db.String(32)) loginIp = db.Column(db.String(32)) imageUrl = db.Column(db.String(128)) regTime = db.Column(db.String(32)) locked = db.Column(db.Boolean) user_List = db.relationship("SUP_User_Role_Models", backref='support_user', lazy='dynamic') def to_json(self): json_data = { "id": self.id, "username": self.username, "phone": self.phone, "email": self.email, "mark": self.mark, "lastLogin": self.lastLogin, "loginIp": self.loginIp, "imageUrl": self.imageUrl, "regTime": self.regTime, "locked": self.locked } return json_data @property def password_bash(self): """ 读取信息 :return: """ raise AttributeError("This property can only be set. not read.") @password_bash.setter def password_bash(self, value): """ 设置属性 user.password = '******' :param value: 设置属性时的数据 value就是"XXX" 源始明文密码 :return: """ self.password = generate_password_hash(value) def check_password(self, passwd): """ 检验密码的正确证 :param passwd: 用户登录时填写的原始密码 :return: 如果正确返回True,否则返回False """ return check_password_hash(self.password, passwd) # 为token串设置有效期为:3600 * 24 * 7 def generate_auth_token(self, expiration=3600 * 24 * 7): """ :param expiration: :return: """ s = Serializer(current_app.config['SECRET_KEY'], expires_in=expiration) token = s.dumps({'id': self.id, 'name': self.username}).decode('ascii') return token
class SUP_Permission_Operation_Models(db.Model): """Permission Link Table""" __tablename__ = "permission_operation" id = db.Column(db.Integer, primary_key=True) PermissionId = db.Column(db.ForeignKey(Support_Permission_Models.id)) OperationID = db.Column(db.ForeignKey(Support_Operation_Models.id))