def check_param_mail(cls, rpath): mail = TyContext.RunHttp.getRequestParam('mail', '') mail = AccountVerify.decode_item(mail) mail = mail.strip().lower() if len(mail.split('@')) != 2: return True, cls.error_param_mail return False, mail
def check_param_mobile(cls, rpath): mobile = TyContext.RunHttp.getRequestParam('mobile', '') mobile = AccountVerify.decode_item(mobile) try: mobile = int(mobile) except: pass if len(str(mobile)) != 11: return True, cls.error_param_mobile return False, mobile
def check_param_password(cls, rpath, key='passwd', isSet=False): password = TyContext.RunHttp.getRequestParam(key, '') if password == '': # hack - 没有创建密码问题 liubo return False, password password = AccountVerify.decode_item(password) if len(password) < 6: return True, cls.error_param_password if isSet and not re.match(r'^[A-Za-z0-9@#$%^&+=]{6,20}$', password): return True, cls.error_param_setpassword return False, password
def doReportContacts(cls, rpath): isReturn, params = AccountCheck.normal_check(rpath) if isReturn: return params mo = TyContext.Cls_MsgPack() contacts = TyContext.RunHttp.getRequestParam('contacts', '') if contacts != '': contacts = AccountVerify.decode_item(contacts) TyContext.ftlog.info('doReportContacts appId=', params['appId'], 'userId=', params['userId'], 'contacts=', contacts) mo.setResult('code', 0) mo.setResult('info', 'success') return mo
def doYoukuLoginCallback(cls, rpath): mo = TyContext.Cls_MsgPack() loginkey = "8MY0XXTQacV2BqOy" qid = TyContext.RunHttp.getRequestParam('qid', '') server_id = TyContext.RunHttp.getRequestParam('server_id', '') time = TyContext.RunHttp.getRequestParam('time', '') sign = TyContext.RunHttp.getRequestParam('sign', '') isAdult = TyContext.RunHttp.getRequestParamInt('isAdult', 1) from tysdk.entity.user_common.verify_h5 import AccountVerify sign_str = "qid=%s&time=%s&server_id=%s%s" % (qid, time, server_id, loginkey) my_sign = AccountVerify.md5(sign_str) if not my_sign or my_sign != sign_str: mo.setResult('code', 1) mo.setResult('info', 'sign error') return mo
def normal_check(cls, rpath, check_sign=True): cls.__init_checker__() # 输入参数校验 if check_sign and AccountVerify.sing_verify(rpath) != True: return True, cls.error_sing params = {} # 检查登录参数 appId = TyContext.RunHttp.getRequestParamInt('appId', 0) if appId <= 0: return True, cls.error_param_appid params['appId'] = appId userId = TyContext.RunHttp.getRequestParamInt('userId', 0) if userId <= 0: return True, cls.error_param_userid params['userId'] = userId authorCode = TyContext.RunHttp.getRequestParam('authorCode', '') if not TyContext.AuthorCode.checkUserAuthorCode(userId, authorCode): return True, cls.error_param_authorcode clientId = TyContext.RunHttp.getRequestParam('clientId', '') try: datas = clientId.split('_') clientSystem = datas[0] clientVersion = float(datas[1]) clientChannel = datas[2] except: return True, cls.error_param_clientid params['clientId'] = clientId params['clientSystem'] = clientSystem params['clientVersion'] = clientVersion params['clientChannel'] = clientChannel return False, params
def login_check(cls, rpath, loginType, check_sign=True): cls.__init_checker__() # 输入参数校验 if check_sign and AccountVerify.sing_verify(rpath) != True: return True, cls.error_sing # 检查是否可以登录 loginForbid = TyContext.ServerControl.checkLoginForbid(rpath) if loginForbid != False: return True, loginForbid params = TyContext.RunHttp.convertArgsToDict() # params = {} # 检查登录参数 appId = TyContext.RunHttp.getRequestParamInt('appId', 0) if appId <= 0: return True, cls.error_param_appid params['appId'] = appId clientId = TyContext.RunHttp.getRequestParam('clientId', '') try: datas = clientId.split('_') clientSystem = datas[0] clientVersion = float(datas[1]) clientChannel = datas[2] except: return True, cls.error_param_clientid check_clientid_number = TyContext.Configure.get_global_item_int( 'check_clientid_num_before_login', 0) if appId < 10000 and check_clientid_number: if not TyContext.BiUtils.clientIdToNumber(appId, clientId): return True, cls.error_param_clientid params['clientId'] = clientId params['clientSystem'] = clientSystem params['clientVersion'] = clientVersion params['clientChannel'] = clientChannel uuid = TyContext.RunHttp.getRequestParam('uuid', '') if len(uuid) != 32: uuid = '' svninfo = TyContext.RunHttp.getRequestParam('svninfo', '') if svninfo: params['svninfo'] = svninfo # params['uuid'] = uuid # id_str = uuid # _devid = AccountVerify.md5(id_str) # params['deviceId'] = _devid _devid = params['deviceId'] TyContext.ftlog.debug('login_check uuid', uuid, 'calculated deviceId', _devid) params['phoneType'] = TyContext.RunHttp.getRequestParam( 'phoneType', '') params['detect_phonenumber'] = TyContext.RunHttp.getRequestParam( 'detect_phonenumber', '') password = None if loginType == 1: ''' 游客登录 ''' password = None if len(_devid) == 0: return True, cls.error_param_device params['deviceName'] = TyContext.RunHttp.getRequestParam( 'deviceName', '') elif loginType == 2: ''' 手机号登录 ''' isReturn, mobile = cls.check_param_mobile(rpath) if isReturn: return True, mobile params['mobile'] = mobile password = 1 elif loginType == 3: ''' tuyooid登录 ''' tuyooId = TyContext.RunHttp.getRequestParam('tuyooId', '') tuyooId = AccountVerify.decode_item(tuyooId) try: tuyooId = int(tuyooId) except: pass if tuyooId <= 10000: return True, cls.error_param_tuyooid params['tuyooId'] = tuyooId password = 1 elif loginType == 4: ''' 邮箱登录 ''' isReturn, mail = cls.check_param_mail(rpath) if isReturn: return True, mail params['mail'] = mail password = 1 elif loginType == 5: ''' snsid登录 ''' isReturn, snsId = cls.check_param_snsid(rpath) if isReturn: return True, snsId params['snsId'] = snsId params['snsToken'] = TyContext.RunHttp.getRequestParam('snsToken') params['snsAppId'] = TyContext.RunHttp.getRequestParam('snsAppId') password = None elif loginType == 6: ''' Account登录 ''' isReturn, account = cls.check_param_account(rpath) if isReturn: return True, account params['account'] = account password = 1 elif loginType == 7: ''' 新建账户 ''' pass if password != None: isReturn, passwd = cls.check_param_password(rpath) if isReturn: return True, passwd params['passwd'] = passwd return False, params
def check_param_account(cls, rpath): account = TyContext.RunHttp.getRequestParam('account', '') account = AccountVerify.decode_item(account) if len(account) <= 0 or len(account) > 32: return True, cls.error_param_account return False, account
def check_param_snsid(cls, rpath): snsId = TyContext.RunHttp.getRequestParam('snsId', '') snsId = AccountVerify.decode_item(snsId) if len(snsId.split(':')) != 2: return True, cls.error_param_snsid return False, snsId