def upgradeByMobile(self, mi, request): gid = mi.get_param('gameId') nick = mi.get_param('nick', '') mobile = mi.get_param('mobile', '') passwd = mi.get_param('passwd', '') verifyCode = mi.get_param('verifyCode', '') if not Entity.logined(request): return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN) if not Entity.checkMobile(mobile): return MsgPack.Error(0, 1, 'mobile invalid') if not Entity.checkPassword(passwd): return MsgPack.Error(0, 2, 'password invalid') if not Entity.checkNick(nick): return MsgPack.Error(0, 6, 'nick invalid') userId = request.getSession().userId # 先判断是不是游客 userInfo = Account.getUserInfo(userId) if int(userInfo['idType']) != Const.IDTYPE_GUEST: return MsgPack.Error(0, 3, 'not guest') # 先查表,判断用户存不存在 if Account.getUserIDByUserName(mobile, Const.IDTYPE_MOBILE): return MsgPack.Error(0, 4, 'mobile exist') if not Mobile.checkVerifyCode(gid, mobile, verifyCode): return MsgPack.Error(0, 5, 'verifycode not right') # nick 唯一 if not Context.RedisMix.hash_setnx('game.%d.unique.nick' % gid, nick, 0): return MsgPack.Error(0, 7, 'nick not unique') if not Account.createUserName(Const.IDTYPE_MOBILE, mobile, userId): Context.RedisMix.hash_del('game.%d.unique.nick' % gid, nick) return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS) if not Account.deleteUserName(userInfo['userName'], Const.IDTYPE_GUEST): Context.Log.error(userId, 'DeleteUserName failed,userName:'******'userName']) Context.RedisMix.hash_set('game.%d.unique.nick' % gid, nick, userId) Account.updateUserInfo(userId, userName=mobile, nick=nick, idType=Const.IDTYPE_MOBILE, token=Entity.encodePassword(mobile, passwd)) return MsgPack(0)
def upgradeByUserName(self, mi, request): gid = mi.get_param('gameId') username = mi.get_param('userName', '') passwd = mi.get_param('passwd', '') if not Entity.logined(request): return MsgPack.Error(0, Const.E_NOT_LOGIN, Const.ES_NOT_LOGIN) if not Entity.checkUserName(username): return MsgPack.Error(0, 1, 'username invalid') if not Entity.checkPassword(passwd): return MsgPack.Error(0, 2, 'password invalid') nick = username if Context.KeywordFilter.isContains(nick): return MsgPack.Error(0, 3, 'keyword filter') userId = request.getSession().userId # 先判断是不是游客 userInfo = Account.getUserInfo(userId) if int(userInfo['idType']) != Const.IDTYPE_GUEST: return MsgPack.Error(0, 4, 'not guest') # 先查表,判断用户存不存在 if Account.getUserIDByUserName(username, Const.IDTYPE_USERNAME): return MsgPack.Error(0, 5, 'username exist') # nick 唯一 if not Context.RedisMix.hash_setnx('game.%d.unique.nick' % gid, username, 0): return MsgPack.Error(0, 6, 'nick not unique') if not Account.createUserName(Const.IDTYPE_USERNAME, username, userId): Context.RedisMix.hash_del('game.%d.unique.nick' % gid, username) return MsgPack.Error(0, Const.E_BAD_REDIS, Const.ES_BAD_REDIS) if not Account.deleteUserName(userInfo['userName'], Const.IDTYPE_GUEST): Context.Log.error(userId, 'DeleteUserName failed,userName:'******'userName']) Context.RedisMix.hash_set('game.%d.unique.nick' % gid, username, userId) Account.updateUserInfo(userId, userName=username, nick=nick, idType=Const.IDTYPE_USERNAME, token=Entity.encodePassword(username, passwd)) return MsgPack(0)