def get(self): if self.check_arguments('token'): self.end('ARG') return if self.check_arguments_empty('token'): self.end('ARG') return token = self.arguments['token'] try: if self.redis_token.exists(token): uid = self.redis_token.hget(token,'uid') new_token = User.gen_token(uid,self.host,self.remote_ip) new_sessionid = User.gen_sessionid(token) token_info = {'uid':uid,'sessionid':new_sessionid} self.redis_token.hmset(new_token,token_info) self.redis_token.expire(new_token,TOKEN_EXPIRE_TIME) self.redis_token.delete(token) session_info = {'uid':uid,'token':token} self.redis_session.hmset(new_sessionid,session_info) #self.expire(new_sessionid,SESSION_EXPIRE_TIME) INFO('UserLOginByTOken -- token[%s] -- session[%s] -- uid[%s]' % (new_token,new_sessionid,uid)) ret_dict = {'token':new_token,'sessionid':new_sessionid} self.end('SUC',**ret_dict) return else: self.end('KEY') return except RedisException: self.end('SVR') return
def get(self): if self.check_arguments('identify_id','password'): self.end('ARG') return if self.check_arguments_empty('identify_id','password'): self.end('ARG') return identify_id = self.arguments['identify_id'] password = self.arguments['password'] try: uid = User.gen_uid(identify_id) if password == self.redis_user.hget(uid,'password'): token = User.gen_token(identify_id,self.host,self.remote_ip) sessionid = User.gen_sessionid(token) token_info = {'uid':uid,'sessionid':sessionid} self.redis_token.hmset(token,token_info) self.redis_token.expire(token,TOKEN_EXPIRE_TIME) session_info = {'uid':uid,'token':token} self.redis_session.hmset(sessionid,session_info) INFO('Login -- token[%s] -- sessionid[%s] -- uid[%s]' % (token,sessionid,uid)) ret_dict = {'token':token,'sessionid':sessionid} self.end('SUC',**ret_dict) else: self.end('PWD') return except RedisException: self.end('SVR') return