diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/app/__init__.py b/src/app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/app/app.py b/src/app/app.py index 2ce5d98..0b4a79a 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -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, diff --git a/src/app/handlers/__init__.py b/src/app/handlers/__init__.py index b41aa75..92d0477 100644 --- a/src/app/handlers/__init__.py +++ b/src/app/handlers/__init__.py @@ -1,2 +1,3 @@ from .main_handler import MainHandler from .zmq_websocket_handler import ZMQWebSocketHandler +from .login_webapp_handler import LoginWebappHandler diff --git a/src/app/handlers/login_webapp_handler.py b/src/app/handlers/login_webapp_handler.py new file mode 100644 index 0000000..e3da974 --- /dev/null +++ b/src/app/handlers/login_webapp_handler.py @@ -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 diff --git a/src/app/templates/login.html b/src/app/templates/login.html new file mode 100644 index 0000000..a0e20a5 --- /dev/null +++ b/src/app/templates/login.html @@ -0,0 +1,14 @@ + + + + + Login page + + + + + +{% module Login(anchor_id, form_data) %} + + + \ No newline at end of file