ResponseService.py 16 KB

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