diff --git a/etiquette.py b/etiquette.py index 5a12e82..19cdf10 100644 --- a/etiquette.py +++ b/etiquette.py @@ -178,7 +178,7 @@ def get_register(): @decorators.required_fields(['username', 'password']) def post_login(): if session_manager.get(request): - flask.abort(403, 'You\'re already signed in.') + return jsonify.make_json_response({'error': 'You\'re already signed in'}, status=403) username = request.form['username'] password = request.form['password'] @@ -186,43 +186,46 @@ def post_login(): user = P.get_user(username=username) user = P.login(user.id, password) except (exceptions.NoSuchUser, exceptions.WrongLogin): - flask.abort(422, 'Wrong login.') + return jsonify.make_json_response({'error': 'Wrong login'}, status=422) session = sessions.Session(request, user) session_manager.add(session) - response = flask.Response('redirect', status=302, headers={'Location': '/'}) - return response + return jsonify.make_json_response({}) @site.route('/register', methods=['POST']) @session_manager.give_token @decorators.required_fields(['username', 'password_1', 'password_2']) def post_register(): if session_manager.get(request): - flask.abort(403, 'You\'re already signed in.') + return jsonify.make_json_response({'error': 'You\'re already signed in'}, status=403) username = request.form['username'] password_1 = request.form['password_1'] password_2 = request.form['password_2'] if password_1 != password_2: - flask.abort(422, 'Passwords do not match.') + return jsonify.make_json_response({'error': 'Passwords do not match'}, status=422) try: user = P.register_user(username, password_1) except exceptions.UsernameTooShort as e: - flask.abort(422, 'Username shorter than minimum of %d' % P.config['min_username_length']) + error = 'Username shorter than minimum of %d' % P.config['min_username_length'] except exceptions.UsernameTooLong as e: - flask.abort(422, 'Username longer than maximum of %d' % P.config['max_username_length']) + error = 'Username longer than maximum of %d' % P.config['max_username_length'] except exceptions.InvalidUsernameChars as e: - flask.abort(422, 'Username contains invalid characters %s' % e.args[0]) + error = 'Username contains invalid characters %s' % e.args[0] except exceptions.PasswordTooShort as e: - flask.abort(422, 'Password is shorter than minimum of %d' % P.config['min_password_length']) + error = 'Password is shorter than minimum of %d' % P.config['min_password_length'] except exceptions.UserExists as e: - flask.abort(422, 'User %s already exists' % e.args[0]) + error = 'User %s already exists' % e.args[0] + else: + error = None + + if error is not None: + return jsonify.make_json_response({'error': error}, status=422) session = sessions.Session(request, user) session_manager.add(session) - response = flask.Response('redirect', status=302, headers={'Location': '/'}) - return response + return jsonify.make_json_response({}) @site.route('/logout', methods=['GET', 'POST']) @session_manager.give_token diff --git a/static/common.css b/static/common.css index 3a909ff..342239a 100644 --- a/static/common.css +++ b/static/common.css @@ -169,16 +169,29 @@ li font-family: monospace; line-height: 1.3; } -.callback_message_positive, .callback_message_negative +#message_area +{ + overflow-y: auto; + background-color: rgba(0, 0, 0, 0.1); + width: 100%; + height: 100%; + max-height: 300px; + display: flex; + flex-direction: column; + justify-content center; + align-items: center; + flex: 2; +} +.message_positive, .message_negative { width: 80%; margin: 4px; } -.callback_message_positive +.message_positive { background-color: #afa; } -.callback_message_negative +.message_negative { background-color: #faa; } diff --git a/static/common.js b/static/common.js index 0c63338..4923a0a 100644 --- a/static/common.js +++ b/static/common.js @@ -29,9 +29,9 @@ function post(url, data, callback) { if (request.readyState == 4) { - var text = request.responseText; if (callback != null) { + var text = request.responseText; console.log(text); callback(JSON.parse(text)); } @@ -90,4 +90,4 @@ function entry_with_history_hook(box, button) { box.entry_history_pos = -1; } -} \ No newline at end of file +} diff --git a/templates/login.html b/templates/login.html index be8a169..4779919 100644 --- a/templates/login.html +++ b/templates/login.html @@ -8,33 +8,6 @@ @@ -51,24 +60,86 @@ button {{header.make_header(session=session)}}
-
- Log in - - - -
-
- Register - - - - -
+
+ Log in + + + +
+
+ Register + + + + +
+
+
diff --git a/templates/photo.html b/templates/photo.html index 34a80f6..73de407 100644 --- a/templates/photo.html +++ b/templates/photo.html @@ -192,13 +192,13 @@ function receive_callback(response) var tagname = response["tagname"]; if ("error" in response) { - message_positivity = "callback_message_negative"; + message_positivity = "message_negative"; message_text = '"' + tagname + '" ' + response["error"]; } else if ("action" in response) { var action = response["action"]; - message_positivity = "callback_message_positive"; + message_positivity = "message_positive"; if (action == "add_tag") { message_text = "Added tag " + tagname; diff --git a/templates/search.html b/templates/search.html index 602b74a..ddc89a8 100644 --- a/templates/search.html +++ b/templates/search.html @@ -21,7 +21,7 @@ form display: flex; flex-direction: column; justify-content: center; - align-content: center; + align-items: center; } .search_warning { diff --git a/templates/tags.html b/templates/tags.html index f029a40..faf89db 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -104,7 +104,7 @@ function edit_tags(action, tagname, callback) var url = "/tags"; data = new FormData(); data.append(action, tagname); - return post(url, data, callback); + return post(url, data, callback); } function delete_tag_synonym(tagname, callback) { @@ -131,13 +131,13 @@ function receive_callback(responses) var tagname = response["tagname"]; if ("error" in response) { - message_positivity = "callback_message_negative"; + message_positivity = "message_negative"; message_text = '"' + tagname + '" ' + response["error"]; } else if ("action" in response) { var action = response["action"]; - message_positivity = "callback_message_positive"; + message_positivity = "message_positive"; if (action == "new_tag") {message_text = "Created tag " + tagname;}