| | |
| | | sex = Column(String(1)) |
| | | permission = Column(String(16), default="general") |
| | | age = Column(Integer) |
| | | sync_flag = Column(String(36)) |
| | | created_at = Column(DateTime, default=datetime.now()) |
| | | updated_at = Column(DateTime, default=datetime.now(), onupdate=datetime.now()) |
| | | |
| | |
| | | # 'phoneNumber': self.phone_number |
| | | } |
| | | |
| | | if len(self.organizations) > 0: |
| | | json['dept'] = [organization.to_json() for organization in self.organizations] |
| | | |
| | | # json['dept'] = [organization.to_json() for organization in self.organizations] |
| | | |
| | | |
| | | json['groups'] = [group.to_dict() for group in self.groups] |
| | | |
| | | roles = [] |
| | | |
| | | # if len(self.roles) > 0: |
| | | roles = [role.to_json() for role in self.roles] |
| | | organization_roles = [role.to_json() for organization in self.organizations for role in |
| | | organization.roles] |
| | | for role in organization_roles: |
| | | if role not in roles: |
| | | roles.append(role) |
| | | json['roles'] = roles |
| | | roles = {role.id: role.to_dict() for role in self.roles} |
| | | # ogt_set = set() |
| | | # for ogt in self.organizations: |
| | | # if ogt.id in ogt_set: |
| | | # continue |
| | | # print(ogt.id) |
| | | # ogt_set.add(ogt.id) |
| | | # for role in ogt.roles: |
| | | # roles[role.id] = role.to_dict() |
| | | # parent_ogt = ogt.parent |
| | | # while parent_ogt: |
| | | # if parent_ogt.id not in ogt_set: |
| | | # ogt_set.add(ogt.id) |
| | | # for role in parent_ogt.roles: |
| | | # roles[role.id] = role.to_dict() |
| | | # parent_ogt = parent_ogt.parent |
| | | # else: |
| | | # break |
| | | |
| | | json['roles'] = list(roles.values()) |
| | | json['depts'] = [i.to_base_json() for i in self.organizations] |
| | | return json |
| | | |
| | | |
| | | def to_login_json(self): |
| | | json = { |
| | |
| | | |
| | | |
| | | def encrypted_password(self, password): |
| | | return cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") |
| | | return cipher_suite.encrypt(str(password).encode("utf-8")).decode("utf-8") |
| | | |
| | | def decrypted_password(self): |
| | | return cipher_suite.decrypt(self.password).decode("utf-8") |
| | |
| | | "app_type": self.app_type, |
| | | 'status': self.status, |
| | | } |
| | | @staticmethod |
| | | def encrypted_password(password): |
| | | return cipher_suite.encrypt(password.encode("utf-8")).decode("utf-8") |
| | | |
| | | @staticmethod |
| | | def decrypted_password(password): |
| | | return cipher_suite.decrypt(password).decode("utf-8") |
| | | |
| | | |
| | | class UserTokenModel(Base): |
| | | __tablename__ = "user_token" |
| | | id = Column(String(16), primary_key=True) |
| | | account = Column(String(255)) |
| | | password = Column(String(255)) |
| | | access_token = Column(String(1000)) |
| | | refresh_token = Column(String(1000)) |
| | | created_at = Column(DateTime, default=datetime.now()) |
| | | updated_at = Column(DateTime, default=datetime.now()) |
| | | |
| | | def to_json(self): |
| | | return { |
| | | 'id': self.id, |
| | | 'account': self.username, |
| | | 'createTime': self.created_at, |
| | | 'updateTime': self.updated_at, |
| | | 'password': self.password, |
| | | 'access_token': self.access_token, |
| | | 'refresh_token': self.refresh_token, |
| | | } |
| | | |
| | | |
| | | |
| | | class UserApiTokenModel(Base): |
| | | __tablename__ = "user_api_token" |
| | | id = Column(Integer, primary_key=True) |
| | | user_id = Column(Integer) |
| | | token = Column(String(40), index=True) |
| | | created_at = Column(DateTime, default=datetime.now()) |
| | | updated_at = Column(DateTime, default=datetime.now()) |
| | | expires_at = Column(DateTime) |
| | | is_active = Column(Integer, default=1) |
| | | |
| | | def to_json(self): |
| | | return { |
| | | 'id': self.id, |
| | | 'account': self.username, |
| | | 'createTime': self.created_at, |
| | | 'updateTime': self.updated_at, |
| | | 'password': self.password, |
| | | 'access_token': self.access_token, |
| | | 'refresh_token': self.refresh_token, |
| | | } |