From: Ben Darnell Date: Sat, 28 Mar 2015 16:34:14 +0000 (-0400) Subject: Remove authentication from chat demo. X-Git-Tag: v4.2.0b1~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bade3746ed68baea5420ed588b886f8b106c4076;p=thirdparty%2Ftornado.git Remove authentication from chat demo. Google OpenID authentication is shutting down soon and its replacement requires app registration, so it's better to make this demo like the websocket one to show off long-polling concepts without auth-related complexity. --- diff --git a/demos/chat/chatdemo.py b/demos/chat/chatdemo.py index 984e1c727..bd4d7b085 100755 --- a/demos/chat/chatdemo.py +++ b/demos/chat/chatdemo.py @@ -15,7 +15,6 @@ # under the License. import logging -import tornado.auth import tornado.escape import tornado.ioloop import tornado.web @@ -73,25 +72,15 @@ class MessageBuffer(object): global_message_buffer = MessageBuffer() -class BaseHandler(tornado.web.RequestHandler): - def get_current_user(self): - user_json = self.get_secure_cookie("chatdemo_user") - if not user_json: return None - return tornado.escape.json_decode(user_json) - - -class MainHandler(BaseHandler): - @tornado.web.authenticated +class MainHandler(tornado.web.RequestHandler): def get(self): self.render("index.html", messages=global_message_buffer.cache) -class MessageNewHandler(BaseHandler): - @tornado.web.authenticated +class MessageNewHandler(tornado.web.RequestHandler): def post(self): message = { "id": str(uuid.uuid4()), - "from": self.current_user["first_name"], "body": self.get_argument("body"), } # to_basestring is necessary for Python 3's json encoder, @@ -105,8 +94,7 @@ class MessageNewHandler(BaseHandler): global_message_buffer.new_messages([message]) -class MessageUpdatesHandler(BaseHandler): - @tornado.web.authenticated +class MessageUpdatesHandler(tornado.web.RequestHandler): @gen.coroutine def post(self): cursor = self.get_argument("cursor", None) @@ -122,36 +110,15 @@ class MessageUpdatesHandler(BaseHandler): global_message_buffer.cancel_wait(self.future) -class AuthLoginHandler(BaseHandler, tornado.auth.GoogleMixin): - @gen.coroutine - def get(self): - if self.get_argument("openid.mode", None): - user = yield self.get_authenticated_user() - self.set_secure_cookie("chatdemo_user", - tornado.escape.json_encode(user)) - self.redirect("/") - return - self.authenticate_redirect(ax_attrs=["name"]) - - -class AuthLogoutHandler(BaseHandler): - def get(self): - self.clear_cookie("chatdemo_user") - self.write("You are now logged out") - - def main(): parse_command_line() app = tornado.web.Application( [ (r"/", MainHandler), - (r"/auth/login", AuthLoginHandler), - (r"/auth/logout", AuthLogoutHandler), (r"/a/message/new", MessageNewHandler), (r"/a/message/updates", MessageUpdatesHandler), ], cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__", - login_url="/auth/login", template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=True, diff --git a/demos/chat/templates/index.html b/demos/chat/templates/index.html index 70549797b..a8708b7c9 100644 --- a/demos/chat/templates/index.html +++ b/demos/chat/templates/index.html @@ -6,10 +6,6 @@ -
{% for message in messages %} diff --git a/demos/chat/templates/message.html b/demos/chat/templates/message.html index c48a634ee..aa817fdfa 100644 --- a/demos/chat/templates/message.html +++ b/demos/chat/templates/message.html @@ -1 +1 @@ -
{{ message["from"] }}: {% module linkify(message["body"]) %}
+
{% module linkify(message["body"]) %}