models.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. from pydantic import BaseModel
  2. from typing import Optional
  3. import datetime
  4. from pymysql import NULL
  5. SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
  6. ALGORITHM = "HS256"
  7. class Token(BaseModel):
  8. access_token: str
  9. token_type: str
  10. class del_user(BaseModel):
  11. access_token: str
  12. del_name: str
  13. class User(BaseModel):
  14. id: int
  15. username: str
  16. password: str
  17. changPwdTime: Optional[datetime.datetime] = None
  18. isAdmin: Optional[bool] = 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. tower_isView : int
  60. tower_isAdd : int
  61. tower_isEdit : int
  62. tower_isDel : int
  63. ai_prediction_id:int
  64. channel_id:int
  65. device_id:int
  66. event_id:int
  67. index_id:int
  68. performance_id:int
  69. record_id:int
  70. setting_device_id:int
  71. setting_system_id:int
  72. tower_id:int
  73. role_id:str
  74. access_token: str
  75. def get_acl_from_module_name(self,module_name:str):
  76. result = {}
  77. exec("result['id'] = self.{}".format(module_name+'_id'))
  78. exec("result['isView'] = self.{}".format(module_name+'_isView'))
  79. exec("result['isAdd'] = self.{}".format(module_name+'_isAdd'))
  80. exec("result['isEdit'] = self.{}".format(module_name+'_isEdit'))
  81. exec("result['isDel'] = self.{}".format(module_name+'_isDel'))
  82. result["role_id"]= self.role_id
  83. result["module_id"]= module_name
  84. print(result)
  85. return result
  86. # AuthJWT setting
  87. class Settings(BaseModel):
  88. authjwt_secret_key: str = SECRET_KEY
  89. authjwt_token_location: set = {"cookies"}
  90. authjwt_cookie_secure: bool = False
  91. authjwt_cookie_csrf_protect: bool = True