Ver código fonte

simple login form

Davide Alberani 9 anos atrás
pai
commit
0a801f0b3e
2 arquivos alterados com 68 adições e 0 exclusões
  1. 49 0
      angular_app/login.html
  2. 19 0
      eventman_server.py

+ 49 - 0
angular_app/login.html

@@ -0,0 +1,49 @@
+<!doctype html>
+<html ng-app="eventManApp">
+    <head>
+        <title>EventMan{ager} - Login</title>
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <link href="/static/css/normalize.css" rel="stylesheet">
+        <link href="/static/css/bootstrap.css" rel="stylesheet">
+        <link href="/static/css/bootstrap-theme.css" rel="stylesheet">
+        <link href="/static/css/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
+        <link href="/static/css/eventman.css" rel="stylesheet">
+    </head>
+    
+    <!--
+        Copyright 2015 Davide Alberani <da@erlug.linux.it>
+                       RaspiBO <info@raspibo.org>
+
+        Licensed under the Apache License, Version 2.0 (the "License");
+        you may not use this file except in compliance with the License.
+        You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+    -->
+
+    <body>
+        <div class="container">
+            <div class="panel panel-primary table-striped top5">
+                <div class="panel-heading">Login</div>
+                <div class="panel-body">
+                    <form method="POST">
+                        <div class="input-group input-group-lg">
+                            <span class="input-group-addon" style="min-width:150px;">Username</span>
+                            <input type="text" id="username" name="username" class="form-control" placeholder="admin">
+                        </div>
+                        <div class="input-group input-group-lg top10">
+                            <span class="input-group-addon" style="min-width:150px;">Password</span>
+                            <input type="password" id="password" name="password" class="form-control" placeholder="eventman">
+                        </div>
+                        <button type="submit" class="btn btn-success top10">login</button>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </body>
+</html>

+ 19 - 0
eventman_server.py

@@ -524,6 +524,22 @@ class WebSocketEventUpdatesHandler(tornado.websocket.WebSocketHandler):
             logging.warn('WebSocketEventUpdatesHandler.on_close error closing websocket: %s', str(e))
 
 
+class LoginHandler(RootHandler):
+    """Handle user authentication requests."""
+    @gen.coroutine
+    def get(self, **kwds):
+        with open(self.angular_app_path + "/login.html", 'r') as fd:
+            self.write(fd.read())
+
+    @gen.coroutine
+    def post(self):
+        username = self.get_body_argument('username')
+        password = self.get_body_argument('password')
+        if username != 'admin' and password != 'eventman':
+            self.redirect('/login?failed=1')
+        self.redirect('/')
+
+
 def run():
     """Run the Tornado web application."""
     # command line arguments; can also be written in a configuration file,
@@ -560,10 +576,13 @@ def run():
             (r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params),
             (r"/settings", SettingsHandler, init_params),
             _ws_handler,
+            (r'/login', LoginHandler),
             (r'/(.*)', tornado.web.StaticFileHandler, {"path": "angular_app"})
         ],
         template_path=os.path.join(os.path.dirname(__file__), "templates"),
         static_path=os.path.join(os.path.dirname(__file__), "static"),
+        cookie_secret='__COOKIE_SECRET__',
+        login_url='/login',
         debug=options.debug)
     ssl_options = {}
     if os.path.isfile(options.ssl_key) and os.path.isfile(options.ssl_cert):