Use distinct cookie names across all the demo apps.
This commit is contained in:
parent
17ec459c85
commit
920f96db6b
|
@ -42,7 +42,7 @@ class Application(tornado.web.Application):
|
|||
|
||||
class BaseHandler(tornado.web.RequestHandler):
|
||||
def get_current_user(self):
|
||||
user_json = self.get_secure_cookie("user")
|
||||
user_json = self.get_secure_cookie("authdemo_user")
|
||||
if not user_json: return None
|
||||
return tornado.escape.json_decode(user_json)
|
||||
|
||||
|
@ -66,7 +66,7 @@ class AuthHandler(BaseHandler, tornado.auth.GoogleMixin):
|
|||
def _on_auth(self, user):
|
||||
if not user:
|
||||
raise tornado.web.HTTPError(500, "Google auth failed")
|
||||
self.set_secure_cookie("user", tornado.escape.json_encode(user))
|
||||
self.set_secure_cookie("authdemo_user", tornado.escape.json_encode(user))
|
||||
self.redirect("/")
|
||||
|
||||
|
||||
|
@ -77,7 +77,7 @@ class LogoutHandler(BaseHandler):
|
|||
# returning to this app will log them back in immediately with no
|
||||
# interaction (unless they have separately logged out of Google in
|
||||
# the meantime).
|
||||
self.clear_cookie("user")
|
||||
self.clear_cookie("authdemo_user")
|
||||
self.write('You are now logged out. '
|
||||
'Click <a href="/">here</a> to log back in.')
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
return self.application.db
|
||||
|
||||
def get_current_user(self):
|
||||
user_id = self.get_secure_cookie("user")
|
||||
user_id = self.get_secure_cookie("blogdemo_user")
|
||||
if not user_id: return None
|
||||
return self.db.get("SELECT * FROM authors WHERE id = %s", int(user_id))
|
||||
|
||||
|
@ -170,13 +170,13 @@ class AuthLoginHandler(BaseHandler, tornado.auth.GoogleMixin):
|
|||
return
|
||||
else:
|
||||
author_id = author["id"]
|
||||
self.set_secure_cookie("user", str(author_id))
|
||||
self.set_secure_cookie("blogdemo_user", str(author_id))
|
||||
self.redirect(self.get_argument("next", "/"))
|
||||
|
||||
|
||||
class AuthLogoutHandler(BaseHandler):
|
||||
def get(self):
|
||||
self.clear_cookie("user")
|
||||
self.clear_cookie("blogdemo_user")
|
||||
self.redirect(self.get_argument("next", "/"))
|
||||
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class Application(tornado.web.Application):
|
|||
|
||||
class BaseHandler(tornado.web.RequestHandler):
|
||||
def get_current_user(self):
|
||||
user_json = self.get_secure_cookie("user")
|
||||
user_json = self.get_secure_cookie("chatdemo_user")
|
||||
if not user_json: return None
|
||||
return tornado.escape.json_decode(user_json)
|
||||
|
||||
|
@ -142,13 +142,13 @@ class AuthLoginHandler(BaseHandler, tornado.auth.GoogleMixin):
|
|||
def _on_auth(self, user):
|
||||
if not user:
|
||||
raise tornado.web.HTTPError(500, "Google auth failed")
|
||||
self.set_secure_cookie("user", tornado.escape.json_encode(user))
|
||||
self.set_secure_cookie("chatdemo_user", tornado.escape.json_encode(user))
|
||||
self.redirect("/")
|
||||
|
||||
|
||||
class AuthLogoutHandler(BaseHandler):
|
||||
def get(self):
|
||||
self.clear_cookie("user")
|
||||
self.clear_cookie("chatdemo_user")
|
||||
self.write("You are now logged out")
|
||||
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ class Application(tornado.web.Application):
|
|||
|
||||
class BaseHandler(tornado.web.RequestHandler):
|
||||
def get_current_user(self):
|
||||
user_json = self.get_secure_cookie("user")
|
||||
user_json = self.get_secure_cookie("fbdemo_user")
|
||||
if not user_json: return None
|
||||
return tornado.escape.json_decode(user_json)
|
||||
|
||||
|
@ -92,17 +92,17 @@ class AuthLoginHandler(BaseHandler, tornado.auth.FacebookGraphMixin):
|
|||
self.authorize_redirect(redirect_uri=my_url,
|
||||
client_id=self.settings["facebook_api_key"],
|
||||
extra_params={"scope": "read_stream"})
|
||||
|
||||
|
||||
def _on_auth(self, user):
|
||||
if not user:
|
||||
raise tornado.web.HTTPError(500, "Facebook auth failed")
|
||||
self.set_secure_cookie("user", tornado.escape.json_encode(user))
|
||||
self.set_secure_cookie("fbdemo_user", tornado.escape.json_encode(user))
|
||||
self.redirect(self.get_argument("next", "/"))
|
||||
|
||||
|
||||
class AuthLogoutHandler(BaseHandler, tornado.auth.FacebookGraphMixin):
|
||||
def get(self):
|
||||
self.clear_cookie("user")
|
||||
self.clear_cookie("fbdemo_user")
|
||||
self.redirect(self.get_argument("next", "/"))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue