From bcdc84fb416820493e048fe28ca59e9090762ffb Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 15 Nov 2016 17:36:51 +0800 Subject: webui: Implement login support (password authentication) --- fg21sim/webui/handlers/base.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 fg21sim/webui/handlers/base.py (limited to 'fg21sim/webui/handlers/base.py') diff --git a/fg21sim/webui/handlers/base.py b/fg21sim/webui/handlers/base.py new file mode 100644 index 0000000..5a6e3a9 --- /dev/null +++ b/fg21sim/webui/handlers/base.py @@ -0,0 +1,30 @@ +# Copyright (c) 2016 Weitian LI +# MIT license + +""" +Base handler for other handlers +""" + + +import tornado.web +from tornado.options import options + + +class BaseRequestHandler(tornado.web.RequestHandler): + def get_current_user(self): + """ + Override the ``get_current_user()`` method to implement user + authentication. + + Determine the current user based on the value of a cookie. + + References + ---------- + - Tornado: Authentication and security + http://www.tornadoweb.org/en/stable/guide/security.html + """ + if (options.password is None) or (options.password == ""): + # Password not set, then all accesses are allowed + return True + else: + return self.get_secure_cookie("user") -- cgit v1.2.2