def handleHttp(dict_param: dict): """app登陆""" objRsp = cResp() agentId = dict_param.get("agentId", "") password = dict_param.get("password", "") token = dict_param.get("token", "") if not agentId: raise exceptionLogic(errorLogic.client_param_invalid) if password or token: if password: strPwd = PwdEncrypt().create_md5(password) objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(agentId) objAgentData = yield from classDataBaseMgr.getInstance( ).getAgentData(agentId) if objPlayerData is None: raise exceptionLogic(errorLogic.player_data_not_found) sql = "select status from dj_agent_apply where agentId=%s" with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn: result = yield from conn.execute(sql, [agentId]) if result.rowcount <= 0: raise exceptionLogic(errorLogic.agent_data_not_found) else: for var_row in result: status = var_row.status if status == 1: raise exceptionLogic(errorLogic.agent_id_under_review) if objAgentData is None: raise exceptionLogic(errorLogic.agent_data_not_found) if objPlayerData.iUserType != 2: raise exceptionLogic(errorLogic.agent_data_not_found) if strPwd != objPlayerData.strPassword: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(agentId, objLock) raise exceptionLogic(errorLogic.login_pwd_not_valid) if timeHelp.getNow() < objPlayerData.iLockEndTime: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(agentId, objLock) raise exceptionLogic(errorLogic.player_id_invalid) else: # objAgentData.strAppToken = generate_token(agentId) objAgentData.strToken = generate_token(agentId) objPlayerData.iStatus = 0 objPlayerData.iLockStartTime = 0 objPlayerData.iLockEndTime = 0 objPlayerData.strLockReason = "" objPlayerData.iLastLoginTime = timeHelp.getNow() yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) else: certify_token(agentId, token) objPlayerData = yield from classDataBaseMgr.getInstance( ).getPlayerData(agentId) objAgentData = yield from classDataBaseMgr.getInstance( ).getAgentData(agentId) if objPlayerData is None: raise exceptionLogic(errorLogic.user_data_not_found) sql = "select status from dj_agent_apply where agentId=%s" with (yield from classSqlBaseMgr.getInstance().objDbMysqlMgr) as conn: result = yield from conn.execute(sql, [agentId]) if result.rowcount <= 0: raise exceptionLogic(errorLogic.agent_data_not_found) else: for var_row in result: status = var_row.status if status == 1: raise exceptionLogic(errorLogic.agent_id_under_review) if objAgentData is None: raise exceptionLogic(errorLogic.agent_data_not_found) if objPlayerData.iUserType != 2: raise exceptionLogic(errorLogic.agent_data_not_found) # if token != objAgentData.strAppToken: if token != objAgentData.strToken: raise exceptionLogic(errorLogic.login_token_not_valid) if timeHelp.getNow() < objAgentData.iLockEndTime: raise exceptionLogic(errorLogic.player_id_invalid) else: objAgentData.iStatus = 0 objAgentData.iLockStartTime = 0 objAgentData.iLockEndTime = 0 objAgentData.strLockReason = "" yield from classDataBaseMgr.getInstance().setAgentData(objAgentData) unReadNum = yield from classSqlBaseMgr.getInstance( ).getAgentMsgUnReadNum(agentId) # 构造回包 objRsp.data = cData() objRsp.data.agentId = objPlayerData.strAccountId objRsp.data.token = objAgentData.strToken objRsp.data.cid = objAgentData.iCid objRsp.data.headAddress = objPlayerData.strHeadAddress objRsp.data.count = unReadNum return classJsonDump.dumps(objRsp) else: raise exceptionLogic(errorLogic.client_param_invalid)
def handleHttp(dict_param: dict): """登陆""" objRsp = cResp() # TODO 多设备同时登陆 source = dict_param.get('source', 'pc') strAccountId = dict_param.get("accountId", "") strPassword = dict_param.get("password", "") strToken = dict_param.get("token", "") if not all([strAccountId, source]): raise exceptionLogic(errorLogic.client_param_invalid) if strToken or strPassword: if strPassword: strPwd = PwdEncrypt().create_md5(strPassword) objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(strAccountId) if objPlayerData is None: raise exceptionLogic(errorLogic.player_data_not_found) if strPwd != objPlayerData.strPassword: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(strAccountId, objLock) raise exceptionLogic(errorLogic.login_pwd_not_valid) if timeHelp.getNow() < objPlayerData.iLockEndTime: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(strAccountId, objLock) raise exceptionLogic(errorLogic.player_id_invalid) else: if source == 'pc': objPlayerData.strToken = generate_token(strAccountId) elif source == 'app': objPlayerData.strAppToken = generate_token(strAccountId) else: raise exceptionLogic(errorLogic.client_param_invalid) objPlayerData.iStatus = 0 objPlayerData.iLockStartTime = 0 objPlayerData.iLockEndTime = 0 objPlayerData.strLockReason = "" objPlayerData.strLastDeviceName = "" #macAddr objPlayerData.iLastLoginTime = timeHelp.getNow() objPlayerData.strLastLoginIp = dict_param.get("srcIp", "") yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) #yield from update_status(strAccountId, 'ACTIVE') unReadNum = yield from classSqlBaseMgr.getInstance( ).getSysMsgUnReadNum(strAccountId) else: certify_token(strAccountId, strToken) objPlayerData, objLock = yield from classDataBaseMgr.getInstance( ).getPlayerDataByLock(strAccountId) if objPlayerData is None: raise exceptionLogic(errorLogic.player_data_not_found) if source == 'pc': if strToken != objPlayerData.strToken: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(strAccountId, objLock) raise exceptionLogic(errorLogic.login_token_not_valid) elif source == 'app': if strToken != objPlayerData.strAppToken: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(strAccountId, objLock) raise exceptionLogic(errorLogic.login_token_not_valid) else: raise exceptionLogic(errorLogic.client_param_invalid) if timeHelp.getNow() < objPlayerData.iLockEndTime: yield from classDataBaseMgr.getInstance( ).releasePlayerDataLock(strAccountId, objLock) raise exceptionLogic(errorLogic.player_id_invalid) else: objPlayerData.iStatus = 0 objPlayerData.iLockStartTime = 0 objPlayerData.iLockEndTime = 0 objPlayerData.strLockReason = "" objPlayerData.iLastLoginTime = timeHelp.getNow() objPlayerData.strLastLoginIp = dict_param.get("srcIp", "") objPlayerData.strLastDeviceName = "" #macAddr yield from classDataBaseMgr.getInstance().setPlayerDataByLock( objPlayerData, objLock) # yield from update_status(strAccountId, 'ACTIVE') unReadNum = yield from classSqlBaseMgr.getInstance( ).getSysMsgUnReadNum(strAccountId) else: raise exceptionLogic(errorLogic.client_param_invalid) # 构造回包 objRsp.data = cData() if source == "pc": objRsp.data.token = objPlayerData.strToken elif source == "app": objRsp.data.token = objPlayerData.strAppToken objRsp.data.accountId = objPlayerData.strAccountId objRsp.data.nick = objPlayerData.strNick objRsp.data.coin = "%.2f" % round(objPlayerData.iCoin / 100, 2) objRsp.data.headAddress = objPlayerData.strHeadAddress objRsp.data.unReadNum = unReadNum objRsp.data.phoneNum = objPlayerData.strPhone objRsp.data.realName = objPlayerData.strRealName objRsp.data.sex = objPlayerData.strSex objRsp.data.born = objPlayerData.strBorn objRsp.data.address = objPlayerData.dictAddress objRsp.data.userType = objPlayerData.iUserType objRsp.data.mac = objPlayerData.strLastDeviceName if objPlayerData.strTradePassword: objRsp.data.tradePwd = 1 else: objRsp.data.tradePwd = 0 objRsp.data.email = objPlayerData.strEmail objRsp.data.bankCard = objPlayerData.arrayBankCard #日志 dictLogin = { 'billType': 'loginBill', 'accountId': objPlayerData.strAccountId, 'agentId': objPlayerData.strAgentId, 'loginTime': timeHelp.getNow(), 'coin': objPlayerData.iCoin, 'vipLevel': objPlayerData.iLevel, 'loginDevice': objPlayerData.strLastDeviceModal, 'loginIp': objPlayerData.strLastLoginIp, 'vipExp': objPlayerData.iLevelValidWater, } logging.getLogger('bill').info(json.dumps(dictLogin)) return classJsonDump.dumps(objRsp)
def handleHttp(dict_param: dict): """注册""" #TODO 去掉限制注册的提示 #if not procVariable.debug: # raise exceptionLogic(errorLogic.player_reg_limited) objRsp = cResp() strAccountId = dict_param.get("accountId", "") strPassword = dict_param.get("password", "") iCid = dict_param.get("cid", 0) source = dict_param.get('source', '') if iCid: try: iCid = int(iCid) agentId = yield from classDataBaseMgr.getInstance().getAgentCodeMapping(iCid) except Exception as e: logging.error(repr(e)) raise exceptionLogic(errorLogic.client_param_invalid) else: agentId = "" if not all([strAccountId, strPassword, source]): raise exceptionLogic(errorLogic.client_param_invalid) if precompile.ChineseOrEmptyCharRegex.search(strAccountId): raise exceptionLogic(errorLogic.player_pwd_length_out_of_range) if precompile.Password.search(strPassword) is None: raise exceptionLogic(errorLogic.player_pwd_length_out_of_range) objPlayerData = yield from classDataBaseMgr.getInstance().getPlayerData(strAccountId) if objPlayerData is None: #注册pinbo objPlayerData = classUserData() objPlayerData.strAccountId = strAccountId objPlayerData.strNick = strAccountId objPlayerData.iRegTime = timeHelp.getNow() objPlayerData.iLastLoginTime = timeHelp.getNow() objPlayerData.strAgentId = agentId #objPlayerData.iRandomSecert = random.randint() objPlayerData.strPassword = PwdEncrypt().create_md5(strPassword) if source == 'pc': objPlayerData.strToken = generate_token(strAccountId) elif source == 'app': objPlayerData.strAppToken = generate_token(strAccountId) objPlayerData.strLastLoginIp = dict_param.get("srcIp","") if procVariable.debug: objPlayerData.iCoin += 100000 objPlayerData.iGuessCoin += 50000 #后注册pinbo yield from register_pinbo(strAccountId) SysMsgData = welcomeMsg(strAccountId) yield from classDataBaseMgr.getInstance().addSystemMsg(SysMsgData) yield from asyncio.sleep(0.5) unReadNum = yield from classSqlBaseMgr.getInstance().getSysMsgUnReadNum(strAccountId) yield from initActiveData(strAccountId) yield from classDataBaseMgr.getInstance().setPlayerDataByLock(objPlayerData, new=True) else: raise exceptionLogic(errorLogic.player_id_already_exist) # 构造回包 objRsp.data = cData() objRsp.data.accountId = strAccountId if source == 'pc': objRsp.data.token = objPlayerData.strToken elif source == 'app': objRsp.data.token = objPlayerData.strAppToken objRsp.data.nick = objPlayerData.strNick objRsp.data.headAddress = "" objRsp.data.coin = "%.2f"%round(objPlayerData.iCoin/100, 2) objRsp.data.unReadNum = unReadNum objRsp.data.phoneNum = objPlayerData.strPhone objRsp.data.tradePwd = 0 objRsp.data.email = objPlayerData.strEmail objRsp.data.bankCard = objPlayerData.arrayBankCard # objRsp.data.pinbo_id=pinbo_id #初始化所有活动 yield from initActiveData(strAccountId) # 日志 dictReg = { 'billType': 'regBill', 'accountId': objPlayerData.strAccountId, 'regTime': timeHelp.getNow(), 'regIp':objPlayerData.strLastLoginIp, 'channel':objPlayerData.iPlatform, 'regDevice':objPlayerData.strLastDeviceName, 'agentId':objPlayerData.strAgentId } logging.getLogger('bill').info(json.dumps(dictReg)) # 日志 dictLogin = { 'billType': 'loginBill', 'accountId': objPlayerData.strAccountId, 'agentId': objPlayerData.strAgentId, 'loginTime': timeHelp.getNow(), 'coin': objPlayerData.iCoin, 'vipLevel': objPlayerData.iLevel, 'loginDevice': objPlayerData.strLastDeviceModal, 'loginIp': objPlayerData.strLastLoginIp, 'vipExp': objPlayerData.iLevelValidWater, } logging.getLogger('bill').info(json.dumps(dictLogin)) return classJsonDump.dumps(objRsp)
def handleHttp(request: dict): # 登陆 accountId = request.get('accountId', '') password = request.get('password', '') if not all([accountId, password]): logging.debug(exceptionLogic(errorLogic.client_param_invalid)) raise exceptionLogic(errorLogic.client_param_invalid) try: conn = classSqlBaseMgr.getInstance() sql = select([tb_admin]).where(tb_admin.c.accountId == accountId) listRest = yield from conn._exeCute(sql) objUser = yield from listRest.fetchone() if objUser is None: logging.debug(errorLogic.wrong_accountId_or_password) raise exceptionLogic(errorLogic.wrong_accountId_or_password) if not check_password(objUser['passwordHash'], password): logging.debug(errorLogic.wrong_accountId_or_password) raise exceptionLogic(errorLogic.wrong_accountId_or_password) sql = select([tb_role.c.id]).where(tb_role.c.id == objUser['role_id']) listRest = yield from conn._exeCute(sql) role_id = yield from listRest.fetchone() token = generate_token(objUser['accountId']) sql = update(tb_admin).where(tb_admin.c.accountId == accountId).values( token=token) yield from conn._exeCuteCommit(sql) # sql=select([tb_action.c.action_name]).where(tb_action.c.id.in_(select([tb_role_action.c.action_id]).where(tb_role_action.c.role_id==role_id))) sql = "SELECT dj_admin_action.action_name FROM dj_admin_action WHERE dj_admin_action.id IN (SELECT dj_admin_role_action.action_id FROM dj_admin_role_action WHERE dj_admin_role_action.role_id ={})".format( role_id[0]) listNames = yield from conn._exeCute(sql) objNames = yield from listNames.fetchall() action_names = [] for x in objNames: action_names.append(x['action_name']) #构建回包 resp = cResp() data = cData() data.accountId = objUser['accountId'] data.token = token data.role_id = objUser['role_id'] data.create_time = objUser['create_time'] data.action_names = action_names resp.data = data resp.ret = errorLogic.success[0] fileName = __name__ nameList = fileName.split('.') methodName = nameList.pop() # 日志 dictActionBill = { 'billType': 'adminActionBill', 'accountId': request.get('accountId', ''), 'action': "登录", 'actionTime': getNow(), 'actionMethod': methodName, 'actionDetail': "登录", 'actionIp': request.get('srcIp', ''), } logging.getLogger('bill').info(json.dumps(dictActionBill)) return classJsonDump.dumps(resp) except exceptionLogic as e: logging.exception(e) raise e except Exception as e: raise e