| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 | from django.shortcuts import HttpResponseimport simplejson as json# 后面尽量尽量使用这个JSON响应类,模板未Controller/OauthManage.pyclass ResponseObject(object):    def __init__(self, lang='en'):        self.lang = lang    def data(self, code, res={}):        data_en = {            0: 'Success',            4: 'Operation failed',            5: 'Please try again one minute later!',            9: 'User accounts is not exist',            10: res,            13: 'This device does not exist !',            14: 'This device does not belong to the user',            15: 'You have not opened this service',            44: 'System error! Can not send email',            48: 'System object error!',            54: 'Data is already exist!',            55: 'Data is not exist!',            60: 'The app info has already exist',            89: 'You have already obtained the verification code, please check it or get it again after 5 minutes.',            90: 'If you have too many times to log in, please try it in 10 seconds.',            99: ' ERROR Incorrect username or password',            101: 'The user account of the mobile phone has already existed!',            102: 'The user account of the mobile phone does not exist!',            103: 'The mailbox user account has already existed!',            104: 'The mailbox user account does not exist!',            105: 'The input username is empty!',            106: 'Create User Error',            107: 'The username format does not conform to the rules!',            108: 'The mailbox format does not conform to the rules! ',            109: 'The password format does not conform to the rules!',            110: 'Because the user is not activated, the user is an invalid user!',            111: 'The password you entered is incorrect!',            112: 'Unknown error can not update the password!',            113: 'This userID does not exist!',            114: 'Delete user failure error',            115: 'The userID of the user to delete does not exist!',            116: 'Update User information failed',            117: 'The userID you provide does not exist!',            118: 'You do not enter the password two times!',            120: 'The verification code has expired, please get the verification code again!',            121: 'The verification code is wrong!',            122: 'Please get the verification code first!',            140: 'Unable to Logout',            150: 'The superID is None or superID is equal to userID',            160: 'The All Equipment has been shared by the User!',            170: 'A part of the equipment has been shared!',            171: 'Delete Equipment sharing failed',            172: 'There is no Equipment for this User!',            173: 'The UID does not exist!',            174: 'The user equipment has already existed!',            175: 'The user equipment has already binding!',            176: 'Delete equipment error',            177: 'Update equipment error',            178: 'ADD equipment error',            179: 'Device name cannot be repeated',            190: 'The rid does not exist!',            191: 'The roleName does not exist!',            192: 'Delete role error',            193: 'An unknown error causes the role can not be deleted!',            194: 'Update role error',            195: 'An unknown error causes the role can not be updated!',            196: 'The User already has this role!',            197: 'The user failed to add a new role',            198: 'The user does not have this role!',            199: 'The user can not delete this role',            200: 'The role assigns new permissions to failure',            201: 'Some of the permissions you have provided do not exist!',            202: 'Delete user rights failure',            203: 'Delete role permissions fail',            204: 'Failure to clear all users Rights',            205: 'All permissions to clear the role fail',            206: 'Some of the permissions you have provided have already existed!',            207: 'Some of the permissions you provide have already existed, and some of the permissions do not exist!',            300: 'Unable to get Token!',            301: 'Add Token to database error!',            302: 'Update Token to database error',            303: 'There is a problem in the Token format!',            305: 'The Token format is wrong and the related parameter is None!',            304: 'The token base64 Decode Error',            306: 'The signature in the token is invalid!',            307: 'The Token has expired!',            308: 'The Refresh Token has expired.',            309: 'This token is not valid because there is no token in the database!',            310: 'The userID in the token is None!',            311: 'The token is None!',            312: 'tokenID_id is None!',            313: 'If the user landed on someone else, if not, please login and modify the password.',            403: 'API ERROR!',            404: 'You don not have permission to access this!',            414: 'Client error ! Please confirm the request path!',            424: 'Database Error !',            444: 'Please confirm the correctness of the parameters!',            500: 'Query Database Error:',            501: 'Update database error!',            502: 'In the database, the parameter fields do not exist!',            600: 'You do not have permission to query all user information!',            601: 'You have no permission to delete user!',            602: 'You have no permission to modify the user information!',            603: 'The User account does not have permission to do this!',            604: 'You do not have permission to query all user equipmnet information!',            605: 'You have no permission to upload OTA files!',            606: 'The user has not assigned the role!',            607: 'The user does not have permission to add a new role!',            608: 'You have no rights to assign roles to users!',            609: 'You have no authority to delete the user\'s role!',            610: 'You have no permissions to query the roles of all users!',            611: 'You have no permissions to add a new permission!',            612: 'You have no permissions to query the perms of all users!',            613: 'You have no permissions to query the permissions of all roles!',            614: 'You do not have the authority to delete the user\'s rights!',            615: 'The superAdmin(userID) account does not exist!',            616: 'The User(userID) account does not exist!',            800: 'Request KEY is None!',            801: 'Wrong request KEY!',            802: 'The content parameter contains an non - modifiable field!',            803: 'The content parameter format is wrong',            804: 'One of the parameters of content or sharedAll must be provided!',            805: 'One of the parameters of content or unsharedAll must be provided!',            806: 'The content parameter is incomplete!',            807: 'The role has already existed!',            808: 'Add a new role to the wrong',            815: 'The permissions have already existed!',            816: 'Add a new permissions error',            817: 'The permissions do not exist!',            818: 'The deletion of the permissions failed',            700: 'Upload file error',            701: 'The file does not exist!',            702: 'Open the file error',            704: 'The Execl file contains n tables!',            705: 'The Execl file or TXT file contains some error data!',            706: 'The file content format is wrong!',            707: 'Other unknown errors',            900: 'There is no information about this version!',            901: 'Getting URL failure!',            902: 'The code does not exist!',            903: 'The name of the file does not meet the conditions!',            904: 'The equipment version information has already existed.',            905: 'Add equipment version information failed',            906: 'Cause of file operation error',            907: 'The download file does not exist!',            908: 'CRC32 Error',            910: 'There are too many downloads. Please wait a moment...',            1000: 'Sorry, the link has expired!',            1001: 'The link is wrong!',            1002: 'Send mail Fail!',            1003: 'The link content format does not conform to the rules!',            1004: 'You have applied for reset password operation, please confirm it by mail.',            1021: 'Sending SMS verification code error',            1022: 'Network error occurs when the authentication code is sent',            1023: 'Send phone voice verification code error',            10002: 'The user landed else where before, if not, please modify the user account and password!',        }        data_cn = {            0: '成功',            4: '操作失败',            5: '请一分钟后再尝试',            9: '用户账号不存在',            10: res,            13: '该设备不存在',            14: '该设备不属于您',            15: '您尚未打开此服务',            44: '系统错误!无法发送电子邮件',            48: '系统对象错误',            54: '数据已存在!',            55: '数据不存在!',            60: 'APP信息已经存在',            89: '您已经获得了验证码,请在5分钟后检查或再次确认。',            90: '登录次数过多,请在10秒内尝试。',            99: '用户名或密码错误',            101: '手机的用户账号已经存在!',            102: '手机的用户账号不存在!',            103: '邮箱用户帐户已经存在!',            104: '邮箱用户帐户不存在!',            105: '输入用户名为空!',            106: '创建用户错误',            107: '用户名格式不符合规则!',            108: '邮箱格式不符合规则!',            109: '密码格式不符合规则!',            110: '因为用户未激活,用户是无效用户!',            111: '您输入的密码不正确!',            112: '未知错误不能更新密码!',            113: '此用户标识不存在!',            114: '删除用户失败错误',            115: '删除用户的用户名不存在!',            116: '更新用户信息失败',            117: '您提供的用户标识不存在!',            118: '你不输入密码两次!',            120: '验证码已经过期,请再次获得验证码!',            121: '验证码错了!',            122: '请先拿到验证码!',            140: '无法注销',            150: '超级用户不存在或者用户id错误',            160: '所有设备已被用户共享!',            170: '部分设备已经共享!',            171: '删除设备共享失败',            172: '这个用户没有设备!',            173: '设备UID不存在!',            174: '用户设备已经存在!',            175: '用户设备已经绑定了!',            176: '删除设备错误',            177: '更新设备错误',            178: '添加设备错误',            179: '设备名称不能重复',            190: '角色rid不存在!',            191: '角色名不存在!',            192: '删除角色错误',            193: '未知的错误导致角色不能被删除!',            194: '更新角色错误',            195: '未知的错误导致角色无法更新!',            196: '该用户已经拥有这个角色!',            197: '该用户未能添加新角色。',            198: '该用户没有这个角色!',            199: '该用户不能删除此角色',            200: '为角色分配新权限失败。',            201: '您提供的某些权限不存在!',            202: '删除用户权限失败',            203: '删除角色权限失败',            204: '未能清除所有用户权限',            205: '清除角色所有的权限失败',            206: '您提供的某些权限已经存在!',            207: '您提供的某些权限已经存在,并且某些权限不存在!',            300: '无法获取令牌!',            301: '添加令牌到数据库错误!',            302: '更新令牌到数据库错误',            303: '令牌格式有问题!',            305: '令牌格式是错误的,相关参数是不存在的!',            304: '令牌Base64解码错误',            306: '令牌中的签名无效!',            307: '令牌已经过期!',            308: '刷新令牌已过期。',            309: '此令牌无效,因为数据库中没有标记!',            310: '令牌中的用户名不存在!',            311: '令牌为空!',            312: '令牌id为空!',            313: '账号在其它地方进行过登录,如果不是本人操作,请登录并修改密码。',            403: 'API错误!',            404: '您没有访问的权限!',            414: '客户端错误!请确认请求路径!',            424: '数据库错误!',            444: '请确认参数的正确性!',            500: '查询数据库错误!',            501: '更新数据库错误!',            502: '在数据库中,参数字段不存在!',            600: '您没有权限查询所有用户信息!',            601: '您没有权限删除用户!',            602: '您没有修改用户信息的权限!',            603: '用户帐户没有权限执行此操作!',            604: '您没有权限查询所有用户设备信息!',            605: '你没有上传OTA文件的权限!',            606: '用户没有分配角色!',            607: '用户没有添加新角色的权限!',            608: '您无权分配角色给用户!',            609: '您没有权限删除用户的角色!',            610: '您没有权限查询所有用户的角色!',            611: '您没有添加新权限的权限!',            612: '您没有查询所有用户的权限的权限!',            613: '您没有权限查询所有角色的权限!',            614: '您没有权限删除用户的权限!',            615: '超级管理员(USEID)帐户不存在!',            616: '用户(USERID)帐户不存在!',            800: '请求参数不存在!',            801: '错误的请求参数!',            802: 'content参数错误!',            803: 'content参数格式错误',            804: 'content或sharedAll参数没有传递',            805: 'content或unsharedAll参数没有传递',            806: 'content参数不完整!',            807: '角色已经存在!',            808: '添加新角色错误',            815: '权限已经存在!',            816: '新增权限错误',            817: '权限不存在',            818: '删除权限错误',            700: '上传文件错误',            701: '文件不存在',            702: '打开文件错误',            704: 'Excel文件包含n个表!',            705: 'Excel文件或TXT文件包含一些错误数据!',            706: '文件内容格式错误!',            707: '其他未知错误',            900: '版本信息不存在',            901: '获取链接失败',            902: 'code不存在!',            903: '文件名不符合条件!',            904: '设备版本信息已经存在。',            905: '添加设备版本信息失败',            906: '文件操作错误',            907: '下载文件不存在!',            908: 'CRC32 错误',            910: '下载太多了。请稍等…',            1000: '对不起,链接已经过期!',            1001: '链接错误!',            1002: '发送邮件失败!',            1003: '链接内容格式不符合规则!',            1004: '您已申请重置密码操作,请通过邮件确认。',            1021: '发送短信验证码错误',            1022: '当发送验证码时发生网络错误',            1023: '发送电话语音验证码错误',            10002: '用户登陆之前的其他地方,如果没有,请修改用户帐号和密码!',        }        if self.lang == 'cn':            msg = data_cn        else:            msg = data_en        try:            message = msg[code]        except Exception as e:            message = '系统错误,code不存在'        return {'result_code': code, 'reason': message, 'result': res}    def formal(self, code, res={}):        formal_data = self.data(code, res)        return json.dumps(formal_data,ensure_ascii=False)    def json(self, code, res={}):        result = self.formal(code, res)        return HttpResponse(result)
 |