def doCreateAccount(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doCreateAccount->rparams=', rparams) rparams['passwd'] = 'ty' + str(random.randint(100000, 999999)) loginType = AccountConst.USER_TYPE_DEVICE userId = AccountInfo.createNewUser(rparams, loginType, False) if userId > 0: AccountInfo.fillUserLoginInfoV3(rparams, mo, userId, True, True) TyContext.BiReport.report_bi_sdk_login( AccountConst.LOGIN_SUCC_EVENTIDS[loginType], userId, rparams['appId'], rparams['clientId'], str(rparams.get(AccountConst.LOGIN_BINDID_KEY[loginType], '')), 0, devId=rparams.get('deviceId', '')) else: mo.setResult('code', AccountConst.CODE_USER_GUEST_REG_FAILE) mo.setResult('info', '用户账号建立失败')
def __do_login_double_check__(cls, tuyooId, rparams, mo): doubleUsers = TyContext.Configure.get_global_item_hashset('doublue.user.list', []) devid = rparams.get('deviceId', '') if devid and devid.find('monitor_') >= 0 or devid.find('robot') >= 0: return False if tuyooId in doubleUsers: rparams['passwd'] = 'ty' + str(random.randint(100000, 999999)) loginType = AccountConst.USER_TYPE_DEVICE userId = AccountInfo.createNewUser(rparams, loginType) TyContext.ftlog.info('__do_login_double_check__ old uerid=', tuyooId, ' new userid=', userId) AccountInfo.fillUserLoginInfoV3(rparams, mo, userId, True, True) TyContext.BiReport.report_bi_sdk_login( AccountConst.LOGIN_SUCC_EVENTIDS[loginType], userId, rparams['appId'], rparams['clientId'], str(rparams.get(AccountConst.LOGIN_BINDID_KEY[loginType], '')), 0, devId=rparams.get('deviceId', '')) return True return False
def doLoginByDevId(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doLoginByDevId->rparams=', rparams) userId = cls.__find_userid_by_devid_map_v3__(rparams['deviceId']) TyContext.ftlog.info(cls.__name__, 'doLoginByDevIdAfter1 userid=', userId, '->rparams=', rparams) if userId <= 0 and rparams.get('mac', ''): macmd5 = rparams.get('macmd5', '') if macmd5: userId = cls.__find_userid_by_devid_map_v2__(macmd5) loginType = AccountConst.USER_TYPE_DEVICE TyContext.ftlog.info(cls.__name__, 'doLoginByDevIdAfter2 userid=', userId, '->rparams=', rparams) if userId > 0: cls._do_check_login(rparams, userId, mo, loginType) else: # 游客初次登陆注册,注册后,返回初次注册的信息 rparams['passwd'] = 'ty' + str(random.randint(100000, 999999)) userId = AccountInfo.createNewUser(rparams, loginType) if userId > 0: AccountInfo.fillUserLoginInfoV3(rparams, mo, userId, True, True) TyContext.BiReport.report_bi_sdk_login( AccountConst.LOGIN_SUCC_EVENTIDS[loginType], userId, rparams['appId'], rparams['clientId'], str(rparams.get(AccountConst.LOGIN_BINDID_KEY[loginType], '')), 0, devId=rparams.get('deviceId', '')) else: if userId == -1: mo.setResult('code', AccountConst.CODE_USER_DEV_REG_FAILE) mo.setResult('info', '您的IP地址异常,暂时无法注册新账号,请电话联系客服:400-8098-000') # 由于客户端没有正确读取info内容,临时加上tips,等新包上线后删掉tips参数 mo.setResult('tips', '您的IP地址异常,暂时无法注册新账号') return mo.setResult('code', AccountConst.CODE_USER_GUEST_REG_FAILE) mo.setResult('info', '设备用户注册失败') clientIp = TyContext.UserSession.get_session_client_ip(int(userId)) TyContext.ftlog.info("UNIVERSAL_LOG_LOGIN", "userId=", userId, 'clientIp=', clientIp, 'version=', 'v3', 'type=', 'doLoginByDevId', 'login_params=', rparams)
def doSnsLogin(cls, rpath): # todo 验签 mo = TyContext.Cls_MsgPack() rparams = TyContext.RunHttp.convertArgsToDict() rparams['snsId'] = AccountVerify.decode_item(rparams['snsId']) snsId = rparams.get('snsId') prefix = snsId.split(':')[0] isOk = None try: method = snsv4_login_map.get(prefix) if not method: isOk = True else: isOk = method(rparams, snsId) except: isOk = False if not isOk: mo.setResult('info', '三方登陆失败') mo.setResult('code', 1) return mo userId = AccountLogin.__find_userid_by_snsid__(snsId) is_create = False if userId <= 0: # 效验该deviceId是否存在第三方sns刷号嫌疑 isFlag, retMsg = AccountLogin._check_deviceid_sns_forbidden( rparams) if isFlag: mo.setResult('code', AccountConst.CODE_USER_SNS_REG_FAILE) mo.setResult('info', retMsg) return mo rparams['passwd'] = 'ty' + str(random.randint(100000, 999999)) if snsId.startswith('360'): rparams['lang'] = "zh_hans" is_create = True userId = AccountInfo.createNewUser(rparams, AccountConst.USER_TYPE_SNS, False) if userId <= 0: mo.setResult('code', AccountConst.CODE_USER_GUEST_REG_FAILE) mo.setResult('info', '用户账号建立失败') return mo appId = rparams['appId'] else: rparams['userId'] = userId try: del rparams['name'] except: pass AccountInfo.doSetUserInfo(rparams, mo, False) AccountLogin._do_check_login(rparams, userId, mo, AccountConst.USER_TYPE_SNS, is_create) # add to userBindSet snsId = rparams.get('snsId') AccountModel.add_snsid_to_userbind_set(userId, snsId) retMsg = TyContext.Cls_MsgPack() if mo.getErrorInfo(): retMsg.setResult('info', mo.getErrorInfo()) retMsg.setResult('code', mo.getErrorCode()) return retMsg token = AccountModel.reset_user_token(userId, 'sns') retMsg.setResult('token', token) retMsg.setResult('code', 0) return retMsg
def doBindByMobile(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doBindByMobile->rparams=', rparams) clientId = rparams['clientId'] chkMobile = str(rparams['mobile']) appId = rparams['appId'] chkUserId = str(rparams['userId']) bindOrderId = rparams['bindOrderId'] if 'bindOrderId' in rparams else '' userIdByMap = cls.__find_userid_by_mobile__(chkMobile) if userIdByMap > 0: if userIdByMap == int(chkUserId): TyContext.RedisUserKeys.execute('HMSET', 'bindOrder:' + bindOrderId, 'state', AccountConst.MOBILE_BIND_BOUND, 'userId', userIdByMap) mo.setResult('code', AccountConst.CODE_USER_MOBILE_BINDED) mo.setResult('info', '无需重复绑定(手机号已绑定)') return TyContext.RedisUserKeys.execute('HMSET', 'bindOrder:' + bindOrderId, 'state', AccountConst.MOBILE_BIND_OCCUPIED, 'userId', chkMobile) mo.setResult('code', AccountConst.CODE_USER_MOBILE_BINDED) mo.setResult('info', '该手机号已被使用,请绑定其它手机号') return if chkUserId == '0': passwd = 'ty' + str(random.randint(100000, 999999)) rparams['passwd'] = passwd chkUserId = AccountInfo.createNewUser( rparams, AccountConst.USER_TYPE_MOBILE) if chkUserId <= 0: TyContext.RedisUserKeys.execute( 'HSET', 'bindOrder:' + bindOrderId, 'state', AccountConst.MOBILE_BIND_FAILED) mo.setResult('code', AccountConst.CODE_USER_MOBILE_REG_FAILE) mo.setResult('info', '手机用户注册失败') return smscontent = TyContext.Configure.get_global_item_json( 'smsdown_content', decodeutf8=True) content = smscontent['sendpwd'] % passwd if not TyContext.SmsDown.sendSms(chkMobile, content): TyContext.ftlog.error( 'AccountBind->doBindByMobile send mobile' ' passwd by sms failed! userid=', chkUserId, 'mobile=', chkMobile, 'appId=', appId, 'clientId=', clientId) chkUserId = str(chkUserId) TyContext.RedisUserKeys.execute('SET', 'mobilemap:' + chkMobile, chkUserId) TyContext.RedisUser.execute(chkUserId, 'HMSET', 'user:'******'bindMobile', chkMobile, 'clientId', clientId, 'isbind', AccountConst.USER_TYPE_MOBILE) if len(bindOrderId) > 0: TyContext.RedisUserKeys.execute('HMSET', 'bindOrder:' + bindOrderId, 'state', AccountConst.MOBILE_BIND_SUCCESS, 'userId', chkUserId) # ftlog.info('sdkUserRegisterMobile in userId=', chkUserId, 'mobile=', chkMobile, 'clientId=', clientId, 'appId=', appId) mo.setResult('code', AccountConst.CODE_USER_SUCCESS) mo.setResult('info', '手机号绑定成功') Friend.onUserRegisterMobile(appId, int(chkUserId), chkMobile) cls.__bind_success_callback_(appId, 'bindphone', {'userId': chkUserId})
def doProcessSnsID(cls, rparams, mo): TyContext.ftlog.info(cls.__name__, 'doProcessSnsID->rparams=', rparams) snsId = rparams['snsId'] # 360SDKv1.0.4版本上传的是access_token区分以前360版本上传的code # 长度判断是为了兼容360社交登陆 if snsId.startswith('360'): if Account360.doGetUserInfo(rparams, snsId) != True: mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '360登录验证失败!') # TyContext.BiReport.report_bi_sdk_login( # TyContext.BIEventId.SDK_LOGIN_BY_SNSID_FAIL, 0, # rparams['appId'], rparams['clientId'], snsId, # AccountConst.CODE_USER_SNS_GETINFO_ERROR) return else: snsId = rparams['snsId'] elif snsId.startswith('ucsid'): if AccountUC.doGetUserInfo(rparams, snsId) != True: mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'UC登录验证失败!') # TyContext.BiReport.report_bi_sdk_login( # TyContext.BIEventId.SDK_LOGIN_BY_SNSID_FAIL, 0, # rparams['appId'], rparams['clientId'], snsId, # AccountConst.CODE_USER_SNS_GETINFO_ERROR) return else: snsId = rparams['snsId'] elif snsId.startswith('qtld:'): if not AccountQtld.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'qtld登录验证失败!') # TyContext.BiReport.report_bi_sdk_login( # TyContext.BIEventId.SDK_LOGIN_BY_SNSID_FAIL, 0, # rparams['appId'], rparams['clientId'], snsId, # AccountConst.CODE_USER_SNS_GETINFO_ERROR) return elif snsId.startswith('wx:'): if not AccountWeixin.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'wx登录验证失败!') # TyContext.BiReport.report_bi_sdk_login( # TyContext.BIEventId.SDK_LOGIN_BY_SNSID_FAIL, 0, # rparams['appId'], rparams['clientId'], snsId, # AccountConst.CODE_USER_SNS_GETINFO_ERROR) return else: snsId = rparams['snsId'] elif snsId.startswith('yy'): if not AccountYYgame.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'yy 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('meizu'): if not AccountMeizu.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'meizu 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('JRTT'): if not AccountJRTT.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'jinritoutiao 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith("fb"): if not AccountFaceBook.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'facebook 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith("xy"): if not AccountXY.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'XY苹果助手 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('aisi'): if not AccountAiSi.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'AiSi 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('haimawan'): if not AccountHaiMaWan.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '海马玩 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('youkuh5'): if not AccountYouku.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '优酷登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('huabeidianhua'): if not AccountHuabeidianhua.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '华北电话 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('itools'): if not AccountiTools.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'iTools 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('kuaiyongpingguo'): if not AccountKuaiYongPingGuo.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'kuaiyongpingguo 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('anzhi'): if not AccountAnZhi.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '安智 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('iiapple'): if not AccountIIApple.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'iiapple 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('mumayi'): if not AccountMumayi.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'mumayi 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('pyw'): # 朋友玩没有账号验证接口,所有id都认为合法 if not AccountPengyouwan.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'pengyouwan 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('m4399'): # 朋友玩没有账号验证接口,所有id都认为合法 if not AccountM4399.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '4399 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('coolpad'): if not AccountCoolpad.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'coolpad 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('zhuoyi'): if not AccountZhuoyi.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'zhuoyi 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('jolo'): if not AccountJolo.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'jolo 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('papa'): if not AccountPapa.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'papa 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('kuaiwan'): if not AccountKuaiwan.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'kuaiwan 登陆验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('changba'): if not AccountChangba.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'changba 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('nubia'): if not AccountNubia.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'nubia 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('ysdk'): if not AccountYsdk.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '应用宝YSDK 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('letv'): if not AccountLetv.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'Letv 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('bdgame'): if not AccountBDGame.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'bdgame 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('yiwan'): if not AccountYiwan.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '益玩 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('jusdk'): if not AccountJusdk.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'Jusdk 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('lizi'): if not AccountLizi.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '口袋栗子 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('vivo'): if not AccountVivo.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'Vivo 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('lenovo'): if not AccountLenovo.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'Lenovo 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('hejiaoyu'): if not AccountHejiaoyu.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '和教育 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('muzhiwan'): if not AccountMZWOnline.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '拇指玩 登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('zhangyue'): if not AccountZhangyue.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '掌阅登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('vivounion'): if not AccountVivounion.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', 'vivo union登录验证失败!') return elif snsId.startswith('momo'): if not AccountMomo.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '陌陌登录验证失败!') return else: snsId = rparams['snsId'] elif snsId.startswith('liebao'): if not AccountLiebao.doGetUserInfo(rparams, snsId): mo.setResult('code', AccountConst.CODE_USER_PARAM_ERROR) mo.setResult('info', '猎豹登陆验证失败!') return else: snsId = rparams['snsId'] userId = cls.__find_userid_by_snsid__(snsId) is_create = False if userId <= 0: # 效验该deviceId是否存在第三方sns刷号嫌疑 isFlag, retMsg = cls._check_deviceid_sns_forbidden(rparams) if isFlag: mo.setResult('code', AccountConst.CODE_USER_SNS_REG_FAILE) mo.setResult('info', retMsg) return rparams['passwd'] = 'ty' + str(random.randint(100000, 999999)) if snsId.startswith('360'): rparams['lang'] = "zh_hans" is_create = True userId = AccountInfo.createNewUser(rparams, AccountConst.USER_TYPE_SNS, False) if userId <= 0: mo.setResult('code', AccountConst.CODE_USER_GUEST_REG_FAILE) mo.setResult('info', '用户账号建立失败') return appId = rparams['appId'] cls.__newaccount_success_callback_(appId, 'newsnsid', {'appId': appId, 'userId': userId, 'snsId': snsId}) else: rparams['userId'] = userId # 2015/2/10 only set name on creating new user try: del rparams['name'] except: pass AccountInfo.doSetUserInfo(rparams, mo, False) # 补丁:保存微信openid到用户信息 # 已经在AccountWeixin中将openid对于的用户信息保存到UserKey数据库中 if snsId.startswith('wx:'): wxopenid = rparams['wxopenid'] TyContext.RedisUser.execute(userId, 'HSET', 'user:%d' % userId, 'wxopenid', wxopenid) TyContext.RedisUserKeys.execute('HSET', 'wxopenid:%s' % wxopenid, 'userId', userId) cls._do_check_login(rparams, userId, mo, AccountConst.USER_TYPE_SNS, is_create) clientIp = TyContext.UserSession.get_session_client_ip(int(userId)) TyContext.ftlog.info("UNIVERSAL_LOG_LOGIN", "userId=", userId, 'clientIp=', clientIp, 'version=', 'v3', 'type=', 'doProcessSnsID', 'login_params=', rparams)