models.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. from pydantic import BaseModel
  2. from typing import Optional
  3. import datetime
  4. SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
  5. ALGORITHM = "HS256"
  6. class Token(BaseModel):
  7. access_token: str
  8. token_type: str
  9. class del_user(BaseModel):
  10. access_token: str
  11. del_name: str
  12. class User(BaseModel):
  13. id: int
  14. username: str
  15. password: str
  16. changPwdTime: Optional[datetime.datetime] = None
  17. isAdmin: Optional[bool] = None
  18. roleType: Optional[str] = None
  19. isEnable: Optional[bool] = True
  20. updateTime: Optional[datetime.datetime] = None
  21. token: Optional[str] = None
  22. class user_authority(BaseModel):
  23. ai_prediction_isView : int
  24. ai_prediction_isAdd : int
  25. ai_prediction_isEdit : int
  26. ai_prediction_isDel : int
  27. channel_isView : int
  28. channel_isAdd : int
  29. channel_isEdit : int
  30. channel_isDel : int
  31. device_isView : int
  32. device_isAdd : int
  33. device_isEdit : int
  34. device_isDel : int
  35. event_isView : int
  36. event_isAdd : int
  37. event_isEdit : int
  38. event_isDel : int
  39. index_isView : int
  40. index_isAdd : int
  41. index_isEdit : int
  42. index_isDel : int
  43. performance_isView : int
  44. performance_isAdd : int
  45. performance_isEdit : int
  46. performance_isDel : int
  47. record_isView : int
  48. record_isAdd : int
  49. record_isEdit : int
  50. record_isDel : int
  51. setting_device_isView : int
  52. setting_device_isAdd : int
  53. setting_device_isEdit : int
  54. setting_device_isDel : int
  55. setting_system_isView : int
  56. setting_system_isAdd : int
  57. setting_system_isEdit : int
  58. setting_system_isDel : int
  59. setting_system_isView : int
  60. setting_system_isAdd : int
  61. setting_system_isEdit : int
  62. setting_system_isDel : int
  63. tower_isView : int
  64. tower_isAdd : int
  65. tower_isEdit : int
  66. tower_isDel : int
  67. role_id:str
  68. id: str
  69. access_token: str
  70. def get_acl_from_module_name(self,module_name:str):
  71. result = {}
  72. result["id"]= module_name + "."+str(self.id)
  73. result["user_id"]= self.id
  74. exec("result['isView'] = self.{}".format(module_name+'_isView'))
  75. exec("result['isAdd'] = self.{}".format(module_name+'_isAdd'))
  76. exec("result['isEdit'] = self.{}".format(module_name+'_isEdit'))
  77. exec("result['isDel'] = self.{}".format(module_name+'_isDel'))
  78. result["role_id"]= self.role_id
  79. result["module_id"]= module_name
  80. print(result)
  81. return result
  82. # AuthJWT setting
  83. class Settings(BaseModel):
  84. authjwt_secret_key: str = SECRET_KEY
  85. authjwt_token_location: set = {"cookies"}
  86. authjwt_cookie_secure: bool = False
  87. authjwt_cookie_csrf_protect: bool = True