diff options
| author | Aaron LI <aaronly.me@outlook.com> | 2016-11-15 17:36:51 +0800 | 
|---|---|---|
| committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-15 17:47:21 +0800 | 
| commit | bcdc84fb416820493e048fe28ca59e9090762ffb (patch) | |
| tree | 95a0d85429d1ba9011001f22bd59c3e06274008e /fg21sim/webui/handlers/login.py | |
| parent | 823fb20c83ff9dedcc5d804f32a0f80ab1810813 (diff) | |
| download | fg21sim-bcdc84fb416820493e048fe28ca59e9090762ffb.tar.bz2 | |
webui: Implement login support (password authentication)
Diffstat (limited to 'fg21sim/webui/handlers/login.py')
| -rw-r--r-- | fg21sim/webui/handlers/login.py | 40 | 
1 files changed, 40 insertions, 0 deletions
| diff --git a/fg21sim/webui/handlers/login.py b/fg21sim/webui/handlers/login.py new file mode 100644 index 0000000..4529005 --- /dev/null +++ b/fg21sim/webui/handlers/login.py @@ -0,0 +1,40 @@ +# Copyright (c) 2016 Weitian LI <liweitianux@live.com> +# MIT license + +""" +Login handler +""" + +from tornado.options import options +from tornado.escape import xhtml_escape + +from .base import BaseRequestHandler + + +class LoginHandler(BaseRequestHandler): +    """ +    Login page handler of the Web UI. + +    NOTE +    ---- +    Only check the password to authenticate the access, therefore, the +    default username "FG21SIM" is used. +    """ +    def get(self): +        if (options.password is None) or (options.password == ""): +            # Password is not set, just allow +            self.redirect(self.reverse_url("index")) +        elif self.current_user: +            # Already authenticated +            self.redirect(self.reverse_url("index")) +        else: +            self.render("login.html", error="") + +    def post(self): +        password = xhtml_escape(self.get_argument("password")) +        if password == options.password: +            self.set_secure_cookie("user", "FG21SIM") +            self.redirect(self.reverse_url("index")) +        else: +            # Password incorrect +            self.render("login.html", error="Incorrect password!") | 
