def responseInvalidSession(self): meta = getEmptyMetaDict() data = {} meta["status"] = "failure" meta["message"] = "Session is timeout" meta["error_code"] = kErrorInvalidSession self.dumpJSON(getFullResponseDictionary(meta, data))
def activateOperation(self): meta = getEmptyMetaDict() if self.checkKey(): meta["status"] = "success" else: meta["status"] = "failure" self.dumpJSON(getFullResponseDictionary(meta, {}))
def responseInvalidSid(self): meta = getEmptyMetaDict() data = {} meta["status"] = "failure" meta["message"] = "Invalid sid" meta["error_code"] = kErrorInvalidSID self.dumpJSON(getFullResponseDictionary(meta, data))
def responseInvalidPassword(self): meta = getEmptyMetaDict() data = {} meta["status"] = "failure" meta["message"] = "Invalid Userid/Password" meta["error_code"] = kErrorInvalidUserPassword self.dumpJSON(getFullResponseDictionary(meta, data))
def loginOperation(self): meta = getEmptyMetaDict() data = {} if self.checkKey(): userid = self.request.get("userid") password = self.request.get("password") logging.info(userid + " " + password) global sessionStore # Init session store for the first time if not sessionStore: sessionStore = SessionStore() if sessionStore.find(userid): # Found existing userid logging.info("Found existing session") foundSession = sessionStore.getSession(userid) if (not foundSession.checkIsExpired()) and ( foundSession.isLogin): # Not expired and isLogin self.responseParseResult( QuestParser.API_account_loginResponse( foundSession, sessionStore.getSID(userid)), kErrorInvalidSession) # self.dumpJSON(QuestParser.API_account_loginResponse(foundSession, sessionStore.getSID(userid))) sessionStore.printOut() return logging.info("Start a new session") newQuestSession = QuestSession(userid, password) newQuestSession.login() sid = "" if newQuestSession.isLogin: sessionStore.add(userid, password, newQuestSession) sid = sessionStore.getSID(userid) self.responseParseResult( QuestParser.API_account_loginResponse( newQuestSession, sid), 0) # Must be success sessionStore.printOut() else: # Login failed errorCodeFromLib = newQuestSession.currentErrorCode errorCodeAPI = 0 if errorCodeFromLib == QuestClass.kErrorInvalidUserPassword: errorCodeAPI = kErrorInvalidUserPassword else: errorCodeAPI = kErrorOther self.responseParseResult( QuestParser.API_account_loginResponse( newQuestSession, sid), errorCodeAPI) else: self.responseInvalidKey()
def loginOperation(self): meta = getEmptyMetaDict() data = {} if self.checkKey(): userid = self.request.get("userid") password = self.request.get("password") logging.info(userid + " " + password) global sessionStore # Init session store for the first time if not sessionStore: sessionStore = SessionStore() if sessionStore.find(userid): # Found existing userid logging.info("Found existing session") foundSession = sessionStore.getSession(userid) if (not foundSession.checkIsExpired()) and (foundSession.isLogin): # Not expired and isLogin self.responseParseResult( QuestParser.API_account_loginResponse(foundSession, sessionStore.getSID(userid)), kErrorInvalidSession, ) # self.dumpJSON(QuestParser.API_account_loginResponse(foundSession, sessionStore.getSID(userid))) sessionStore.printOut() return logging.info("Start a new session") newQuestSession = QuestSession(userid, password) newQuestSession.login() sid = "" if newQuestSession.isLogin: sessionStore.add(userid, password, newQuestSession) sid = sessionStore.getSID(userid) self.responseParseResult( QuestParser.API_account_loginResponse(newQuestSession, sid), 0 ) # Must be success sessionStore.printOut() else: # Login failed errorCodeFromLib = newQuestSession.currentErrorCode errorCodeAPI = 0 if errorCodeFromLib == QuestClass.kErrorInvalidUserPassword: errorCodeAPI = kErrorInvalidUserPassword else: errorCodeAPI = kErrorOther self.responseParseResult(QuestParser.API_account_loginResponse(newQuestSession, sid), errorCodeAPI) else: self.responseInvalidKey()
def logoutOperation(self): meta = getEmptyMetaDict() data = {} if self.checkKey(): sid = self.request.get("sid") global sessionStore if sessionStore.find(sid): userid = sessionStore.getUserID(sid) session = sessionStore.getSession(sid) session.logout() if sessionStore.removeWithSID(sid): sessionStore.printOut() meta["status"] = "success" meta["message"] = "%s has logged out" % userid data["sid"] = sid else: meta["status"] = "failure" meta["message"] = "logout %s sid failed" % userid data["sid"] = sid self.dumpJSON(getFullResponseDictionary(meta, data)) else: self.responseInvalidSid() else: self.responseInvalidKey()