ResponseObject.py 17 KB

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