I wrote the login and logout handlers in Tornado, using for the login the Google external service.
The handlers are the following:
###############################################################################
# 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("/")I would that, when a user is logged out, clicking on the back button of the browser he was not logged in. In other words I would that the back button doesn't work... instead, if I logged out the user, if he click the back button he can navigate in the web pages like he was always logged in..
Any suggestions? Thank you.
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I wrote the login and logout handlers in Tornado, using for the login the Google external service.
--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.