def login_handler(self): username = self.jdata.get("username") password = self.jdata.get("password") if not all([username, password]): return {"code": "LOGIN_FAIL", "message": "You need send username and password"} else: try: if not r.exists("user:"******":password"): return {"code": "LOGIN_FAIL", "message": "Username is not existed"} if password == r.get("user:"******":password"): if self.is_recv_boardcast: recv_connections.append(self) else: connections.append(self) self.user = username self.isLogin = True if not self.is_recv_boardcast: self.broadcast_login() r.sadd("online_user", username) #self.broadcast({"action": "login", "user": self.get_user(), "nickname": r.get("user:"******":nickname")}) return {"code": "LOGIN_SUCCESS", "message": "success", "nickname": r.get("user:"******":nickname")} else: return {"code": "LOGIN_FAIL", "message": "Username and password not match"} except Exception, e: print "Error:", e.message,traceback.format_exc() return {"code": "SERVER_ERROR", "message": "Server Error"}
def a_sadd(k, v): r.sadd(k, v)