ResponseObject.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. from django.shortcuts import HttpResponse
  2. import simplejson as json
  3. # 后面尽量尽量使用这个JSON响应类,模板未Controller/OauthManage.py
  4. class ResponseObject(object):
  5. def __init__(self, lang='en'):
  6. self.lang = lang
  7. def data(self, code, res={}):
  8. data_en = {
  9. 0: 'Success',
  10. 4: 'Operation failed',
  11. 5: 'Please try again one minute later!',
  12. 9: 'User accounts is not exist',
  13. 10: res,
  14. 13: 'This device does not exist !',
  15. 14: 'This device does not belong to the user',
  16. 15: 'You have not opened this service',
  17. 44: 'System error! Can not send email',
  18. 48: 'System object error!',
  19. 54: 'Data is already exist!',
  20. 55: 'Data is not exist!',
  21. 60: 'The app info has already exist',
  22. 89: 'You have already obtained the verification code, please check it or get it again after 5 minutes.',
  23. 90: 'If you have too many times to log in, please try it in 10 seconds.',
  24. 99: ' ERROR Incorrect username or password',
  25. 101: 'The user account of the mobile phone has already existed!',
  26. 102: 'The user account of the mobile phone does not exist!',
  27. 103: 'The mailbox user account has already existed!',
  28. 104: 'The mailbox user account does not exist!',
  29. 105: 'The input username is empty!',
  30. 106: 'Create User Error',
  31. 107: 'The username format does not conform to the rules!',
  32. 108: 'The mailbox format does not conform to the rules! ',
  33. 109: 'The password format does not conform to the rules!',
  34. 110: 'Because the user is not activated, the user is an invalid user!',
  35. 111: 'The password you entered is incorrect!',
  36. 112: 'Unknown error can not update the password!',
  37. 113: 'This userID does not exist!',
  38. 114: 'Delete user failure error',
  39. 115: 'The userID of the user to delete does not exist!',
  40. 116: 'Update User information failed',
  41. 117: 'The userID you provide does not exist!',
  42. 118: 'You do not enter the password two times!',
  43. 120: 'The verification code has expired, please get the verification code again!',
  44. 121: 'The verification code is wrong!',
  45. 122: 'Please get the verification code first!',
  46. 140: 'Unable to Logout',
  47. 150: 'The superID is None or superID is equal to userID',
  48. 160: 'The All Equipment has been shared by the User!',
  49. 170: 'A part of the equipment has been shared!',
  50. 171: 'Delete Equipment sharing failed',
  51. 172: 'There is no Equipment for this User!',
  52. 173: 'The UID does not exist!',
  53. 174: 'The user equipment has already existed!',
  54. 175: 'The user equipment has already binding!',
  55. 176: 'Delete equipment error',
  56. 177: 'Update equipment error',
  57. 178: 'ADD equipment error',
  58. 179: 'Device name cannot be repeated',
  59. 190: 'The rid does not exist!',
  60. 191: 'The roleName does not exist!',
  61. 192: 'Delete role error',
  62. 193: 'An unknown error causes the role can not be deleted!',
  63. 194: 'Update role error',
  64. 195: 'An unknown error causes the role can not be updated!',
  65. 196: 'The User already has this role!',
  66. 197: 'The user failed to add a new role',
  67. 198: 'The user does not have this role!',
  68. 199: 'The user can not delete this role',
  69. 200: 'The role assigns new permissions to failure',
  70. 201: 'Some of the permissions you have provided do not exist!',
  71. 202: 'Delete user rights failure',
  72. 203: 'Delete role permissions fail',
  73. 204: 'Failure to clear all users Rights',
  74. 205: 'All permissions to clear the role fail',
  75. 206: 'Some of the permissions you have provided have already existed!',
  76. 207: 'Some of the permissions you provide have already existed, and some of the permissions do not exist!',
  77. 300: 'Unable to get Token!',
  78. 301: 'Add Token to database error!',
  79. 302: 'Update Token to database error',
  80. 303: 'There is a problem in the Token format!',
  81. 305: 'The Token format is wrong and the related parameter is None!',
  82. 304: 'The token base64 Decode Error',
  83. 306: 'The signature in the token is invalid!',
  84. 307: 'The Token has expired!',
  85. 308: 'The Refresh Token has expired.',
  86. 309: 'This token is not valid because there is no token in the database!',
  87. 310: 'The userID in the token is None!',
  88. 311: 'The token is None!',
  89. 312: 'tokenID_id is None!',
  90. 313: 'If the user landed on someone else, if not, please login and modify the password.',
  91. 403: 'API ERROR!',
  92. 404: 'You don not have permission to access this!',
  93. 414: 'Client error ! Please confirm the request path!',
  94. 424: 'Database Error !',
  95. 444: 'Please confirm the correctness of the parameters!',
  96. 500: 'Query Database Error:',
  97. 501: 'Update database error!',
  98. 502: 'In the database, the parameter fields do not exist!',
  99. 600: 'You do not have permission to query all user information!',
  100. 601: 'You have no permission to delete user!',
  101. 602: 'You have no permission to modify the user information!',
  102. 603: 'The User account does not have permission to do this!',
  103. 604: 'You do not have permission to query all user equipmnet information!',
  104. 605: 'You have no permission to upload OTA files!',
  105. 606: 'The user has not assigned the role!',
  106. 607: 'The user does not have permission to add a new role!',
  107. 608: 'You have no rights to assign roles to users!',
  108. 609: 'You have no authority to delete the user\'s role!',
  109. 610: 'You have no permissions to query the roles of all users!',
  110. 611: 'You have no permissions to add a new permission!',
  111. 612: 'You have no permissions to query the perms of all users!',
  112. 613: 'You have no permissions to query the permissions of all roles!',
  113. 614: 'You do not have the authority to delete the user\'s rights!',
  114. 615: 'The superAdmin(userID) account does not exist!',
  115. 616: 'The User(userID) account does not exist!',
  116. 800: 'Request KEY is None!',
  117. 801: 'Wrong request KEY!',
  118. 802: 'The content parameter contains an non - modifiable field!',
  119. 803: 'The content parameter format is wrong',
  120. 804: 'One of the parameters of content or sharedAll must be provided!',
  121. 805: 'One of the parameters of content or unsharedAll must be provided!',
  122. 806: 'The content parameter is incomplete!',
  123. 807: 'The role has already existed!',
  124. 808: 'Add a new role to the wrong',
  125. 815: 'The permissions have already existed!',
  126. 816: 'Add a new permissions error',
  127. 817: 'The permissions do not exist!',
  128. 818: 'The deletion of the permissions failed',
  129. 700: 'Upload file error',
  130. 701: 'The file does not exist!',
  131. 702: 'Open the file error',
  132. 704: 'The Execl file contains n tables!',
  133. 705: 'The Execl file or TXT file contains some error data!',
  134. 706: 'The file content format is wrong!',
  135. 707: 'Other unknown errors',
  136. 900: 'There is no information about this version!',
  137. 901: 'Getting URL failure!',
  138. 902: 'The code does not exist!',
  139. 903: 'The name of the file does not meet the conditions!',
  140. 904: 'The equipment version information has already existed.',
  141. 905: 'Add equipment version information failed',
  142. 906: 'Cause of file operation error',
  143. 907: 'The download file does not exist!',
  144. 908: 'CRC32 Error',
  145. 910: 'There are too many downloads. Please wait a moment...',
  146. 1000: 'Sorry, the link has expired!',
  147. 1001: 'The link is wrong!',
  148. 1002: 'Send mail Fail!',
  149. 1003: 'The link content format does not conform to the rules!',
  150. 1004: 'You have applied for reset password operation, please confirm it by mail.',
  151. 1021: 'Sending SMS verification code error',
  152. 1022: 'Network error occurs when the authentication code is sent',
  153. 1023: 'Send phone voice verification code error',
  154. 10002: 'The user landed else where before, if not, please modify the user account and password!',
  155. }
  156. data_cn = {
  157. 0: '成功',
  158. 4: '操作失败',
  159. 5: '请一分钟后再尝试',
  160. 9: '用户账号不存在',
  161. 10: res,
  162. 13: '该设备不存在',
  163. 14: '该设备不属于您',
  164. 15: '您尚未打开此服务',
  165. 44: '系统错误!无法发送电子邮件',
  166. 48: '系统对象错误',
  167. 54: '数据已存在!',
  168. 55: '数据不存在!',
  169. 60: 'APP信息已经存在',
  170. 89: '您已经获得了验证码,请在5分钟后检查或再次确认。',
  171. 90: '登录次数过多,请在10秒内尝试。',
  172. 99: '用户名或密码错误',
  173. 101: '手机的用户账号已经存在!',
  174. 102: '手机的用户账号不存在!',
  175. 103: '邮箱用户帐户已经存在!',
  176. 104: '邮箱用户帐户不存在!',
  177. 105: '输入用户名为空!',
  178. 106: '创建用户错误',
  179. 107: '用户名格式不符合规则!',
  180. 108: '邮箱格式不符合规则!',
  181. 109: '密码格式不符合规则!',
  182. 110: '因为用户未激活,用户是无效用户!',
  183. 111: '您输入的密码不正确!',
  184. 112: '未知错误不能更新密码!',
  185. 113: '此用户标识不存在!',
  186. 114: '删除用户失败错误',
  187. 115: '删除用户的用户名不存在!',
  188. 116: '更新用户信息失败',
  189. 117: '您提供的用户标识不存在!',
  190. 118: '你不输入密码两次!',
  191. 120: '验证码已经过期,请再次获得验证码!',
  192. 121: '验证码错了!',
  193. 122: '请先拿到验证码!',
  194. 140: '无法注销',
  195. 150: '超级用户不存在或者用户id错误',
  196. 160: '所有设备已被用户共享!',
  197. 170: '部分设备已经共享!',
  198. 171: '删除设备共享失败',
  199. 172: '这个用户没有设备!',
  200. 173: '设备UID不存在!',
  201. 174: '用户设备已经存在!',
  202. 175: '用户设备已经绑定了!',
  203. 176: '删除设备错误',
  204. 177: '更新设备错误',
  205. 178: '添加设备错误',
  206. 179: '设备名称不能重复',
  207. 190: '角色rid不存在!',
  208. 191: '角色名不存在!',
  209. 192: '删除角色错误',
  210. 193: '未知的错误导致角色不能被删除!',
  211. 194: '更新角色错误',
  212. 195: '未知的错误导致角色无法更新!',
  213. 196: '该用户已经拥有这个角色!',
  214. 197: '该用户未能添加新角色。',
  215. 198: '该用户没有这个角色!',
  216. 199: '该用户不能删除此角色',
  217. 200: '为角色分配新权限失败。',
  218. 201: '您提供的某些权限不存在!',
  219. 202: '删除用户权限失败',
  220. 203: '删除角色权限失败',
  221. 204: '未能清除所有用户权限',
  222. 205: '清除角色所有的权限失败',
  223. 206: '您提供的某些权限已经存在!',
  224. 207: '您提供的某些权限已经存在,并且某些权限不存在!',
  225. 300: '无法获取令牌!',
  226. 301: '添加令牌到数据库错误!',
  227. 302: '更新令牌到数据库错误',
  228. 303: '令牌格式有问题!',
  229. 305: '令牌格式是错误的,相关参数是不存在的!',
  230. 304: '令牌Base64解码错误',
  231. 306: '令牌中的签名无效!',
  232. 307: '令牌已经过期!',
  233. 308: '刷新令牌已过期。',
  234. 309: '此令牌无效,因为数据库中没有标记!',
  235. 310: '令牌中的用户名不存在!',
  236. 311: '令牌为空!',
  237. 312: '令牌id为空!',
  238. 313: '账号在其它地方进行过登录,如果不是本人操作,请登录并修改密码。',
  239. 403: 'API错误!',
  240. 404: '您没有访问的权限!',
  241. 414: '客户端错误!请确认请求路径!',
  242. 424: '数据库错误!',
  243. 444: '请确认参数的正确性!',
  244. 500: '查询数据库错误!',
  245. 501: '更新数据库错误!',
  246. 502: '在数据库中,参数字段不存在!',
  247. 600: '您没有权限查询所有用户信息!',
  248. 601: '您没有权限删除用户!',
  249. 602: '您没有修改用户信息的权限!',
  250. 603: '用户帐户没有权限执行此操作!',
  251. 604: '您没有权限查询所有用户设备信息!',
  252. 605: '你没有上传OTA文件的权限!',
  253. 606: '用户没有分配角色!',
  254. 607: '用户没有添加新角色的权限!',
  255. 608: '您无权分配角色给用户!',
  256. 609: '您没有权限删除用户的角色!',
  257. 610: '您没有权限查询所有用户的角色!',
  258. 611: '您没有添加新权限的权限!',
  259. 612: '您没有查询所有用户的权限的权限!',
  260. 613: '您没有权限查询所有角色的权限!',
  261. 614: '您没有权限删除用户的权限!',
  262. 615: '超级管理员(USEID)帐户不存在!',
  263. 616: '用户(USERID)帐户不存在!',
  264. 800: '请求参数不存在!',
  265. 801: '错误的请求参数!',
  266. 802: 'content参数错误!',
  267. 803: 'content参数格式错误',
  268. 804: 'content或sharedAll参数没有传递',
  269. 805: 'content或unsharedAll参数没有传递',
  270. 806: 'content参数不完整!',
  271. 807: '角色已经存在!',
  272. 808: '添加新角色错误',
  273. 815: '权限已经存在!',
  274. 816: '新增权限错误',
  275. 817: '权限不存在',
  276. 818: '删除权限错误',
  277. 700: '上传文件错误',
  278. 701: '文件不存在',
  279. 702: '打开文件错误',
  280. 704: 'Excel文件包含n个表!',
  281. 705: 'Excel文件或TXT文件包含一些错误数据!',
  282. 706: '文件内容格式错误!',
  283. 707: '其他未知错误',
  284. 900: '版本信息不存在',
  285. 901: '获取链接失败',
  286. 902: 'code不存在!',
  287. 903: '文件名不符合条件!',
  288. 904: '设备版本信息已经存在。',
  289. 905: '添加设备版本信息失败',
  290. 906: '文件操作错误',
  291. 907: '下载文件不存在!',
  292. 908: 'CRC32 错误',
  293. 910: '下载太多了。请稍等…',
  294. 1000: '对不起,链接已经过期!',
  295. 1001: '链接错误!',
  296. 1002: '发送邮件失败!',
  297. 1003: '链接内容格式不符合规则!',
  298. 1004: '您已申请重置密码操作,请通过邮件确认。',
  299. 1021: '发送短信验证码错误',
  300. 1022: '当发送验证码时发生网络错误',
  301. 1023: '发送电话语音验证码错误',
  302. 10002: '用户登陆之前的其他地方,如果没有,请修改用户帐号和密码!',
  303. }
  304. if self.lang == 'cn':
  305. msg = data_cn
  306. else:
  307. msg = data_en
  308. try:
  309. message = msg[code]
  310. except Exception as e:
  311. message = '系统错误,code不存在'
  312. return {'result_code': code, 'reason': message, 'result': res}
  313. def formal(self, code, res={}):
  314. formal_data = self.data(code, res)
  315. return json.dumps(formal_data,ensure_ascii=False)
  316. def json(self, code, res={}):
  317. result = self.formal(code, res)
  318. return HttpResponse(result)