0
로그인을 위해 Google 외부 서비스를 사용하여 Tornado에 로그인 및 로그 아웃 처리기를 작성했습니다.토네이도 로그 아웃이 작동하지 않습니다.
핸들러는 다음과 같습니다. 사용자가 자신이 로그인되지 않은 브라우저의 뒤로 버튼을 클릭하면, 로그 아웃 할 때 즉 내가 것이라고, 내가 다시 그 것
###############################################################################
# Manage login requests using Google authentication
###############################################################################
class AuthLoginHandler(BaseHandler, tornado.auth.GoogleMixin):
@tornado.web.asynchronous
def get(self):
if self.get_argument("openid.mode", None):
self.get_authenticated_user(self.async_callback(self._on_auth))
return
self.authenticate_redirect()
# Authentication-OK callback.
# Save user info on the first connection.
# Only save a last-login timestamp otherwise.
def _on_auth(self, user):
if not user:
raise tornado.web.HTTPError(500, "Google auth failed")
str_time = datetime.datetime.now().isoformat()
usr = self.db.get("SELECT * FROM users WHERE email=%s", user["email"])
if not usr:
# Create user entry in the WSN-database
self.lock_tables("write", ['users'])
usr_id = self.db.execute("INSERT INTO users (email, name, last_access) \
VALUES (%s,%s,%s)",
user["email"], user["name"], str_time)
self.unlock_tables()
else:
self.lock_tables("write", ['users'])
usr_id = usr["id"]
self.db.execute("UPDATE users SET last_access=%s WHERE id=%s",
str_time, usr_id)
self.unlock_tables()
self.set_secure_cookie("user", str(usr_id))
self.info("Hello <b>" + user["name"] + "</b>!")
self.redirect(self.get_argument("next", "/"))
# Do not log Login info
def _log(self):
pass
################################################################################
# Logout handler. Simply clear the "user" cookie and redirect to homepage.
################################################################################
class AuthLogoutHandler(BaseHandler, tornado.auth.GoogleMixin):
def get(self):
self.clear_cookie("user")
self.notice("You have successfully logged out")
self.redirect("/")
버튼이 작동하지 않습니다 ... 대신 사용자가 로그 아웃하면 뒤로 버튼을 클릭하면 항상 로그인 한 것처럼 웹 페이지를 탐색 할 수 있습니다.
제안 사항이 있으십니까? 고맙습니다.
예 사용자가 자동으로 이동합니다. Google 계정의 속성입니다. – sharkbait