Create handler for login

This commit is contained in:
Bálint Bokros 2017-11-27 18:48:50 +01:00
parent 4a810b4229
commit e0d13840f0
6 changed files with 44 additions and 1 deletions

0
src/__init__.py Normal file
View File

0
src/app/__init__.py Normal file
View File

View File

@ -7,13 +7,14 @@ from tornado.web import Application
from tornado.ioloop import IOLoop
from config import WEB_PORT
from handlers import MainHandler, ZMQWebSocketHandler
from handlers import MainHandler, ZMQWebSocketHandler, LoginWebappHandler
import ui_modules
if __name__ == '__main__':
routes = [
(r'/', MainHandler),
(r'/ws', ZMQWebSocketHandler),
(r'/login', LoginWebappHandler),
]
application = Application(
routes,

View File

@ -1,2 +1,3 @@
from .main_handler import MainHandler
from .zmq_websocket_handler import ZMQWebSocketHandler
from .login_webapp_handler import LoginWebappHandler

View File

@ -0,0 +1,27 @@
import json
from tornado.web import RequestHandler, MissingArgumentError
# from buttons import fsm
from sql_injection_fsm import fsm
class LoginWebappHandler(RequestHandler):
anchor_id = 'anchor_login'
def get(self, *args, **kwargs):
self.render('login.html', anchor_id=self.anchor_id, form_data=(
('email', 'email_input', 'Email address', 'Enter email'),
('password', 'password_input', 'Password', 'Password'),
))
def post(self, *args, **kwargs):
try:
message = {
'anchor': self.anchor_id,
'data': {k: self.get_body_argument(k) for k in ('email', 'password')}
}
fsm.trigger(self.anchor_id, message=json.dumps(message))
except MissingArgumentError:
self.write_error(status_code=400, message='Incomplete request')
# TODO: return real data if not in a tutorial

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login page</title>
<link rel="stylesheet" href="{{ static_url('vendor/css/bootstrap.min.css') }}">
</head>
<body>
{% module Login(anchor_id, form_data) %}
</body>
</html>