diff --git a/flaschengeist.wsgi b/flaschengeist.wsgi index 62158bc..069b135 100644 --- a/flaschengeist.wsgi +++ b/flaschengeist.wsgi @@ -1,3 +1,8 @@ #!/usr/bin/python3 +# If you use a virtual env, this might become handy: +# activate_this = '/path/to/env/bin/activate_this.py' +# with open(activate_this) as file_: +# exec(file_.read(), dict(__file__=activate_this)) + from flaschengeist.app import create_app application = create_app() diff --git a/flaschengeist/plugins/auth/__init__.py b/flaschengeist/plugins/auth/__init__.py index b65dc87..ef84ae7 100644 --- a/flaschengeist/plugins/auth/__init__.py +++ b/flaschengeist/plugins/auth/__init__.py @@ -2,8 +2,8 @@ Allow management of authentication, login, logout, etc. """ - from flask import Blueprint, request, jsonify +from http.client import CREATED, NO_CONTENT from werkzeug.exceptions import Forbidden, BadRequest, Unauthorized from flaschengeist import logger @@ -49,7 +49,7 @@ def login(): # Lets cleanup the DB sessionController.clear_expired() - return jsonify({"session": session, "user": user}) + return {"session": session, "user": user}, CREATED @auth_bp.route("/auth", methods=["GET"]) @@ -125,7 +125,7 @@ def set_lifetime(token, current_session, **kwargs): current_session: Session sent with Authorization Header Returns: - HTTP-200 (empty) or HTTP error + HTTP-204 or HTTP error """ session = sessionController.get_session(token, current_session._user) if not session: @@ -136,7 +136,7 @@ def set_lifetime(token, current_session, **kwargs): lifetime = request.get_json()["value"] logger.debug("set lifetime {{ {} }} to access token {{ {} }}".format(lifetime, token)) sessionController.set_lifetime(session, lifetime) - return "" + return "", NO_CONTENT except (KeyError, TypeError): raise BadRequest diff --git a/flaschengeist/plugins/users/__init__.py b/flaschengeist/plugins/users/__init__.py index d79cc5c..87875cf 100644 --- a/flaschengeist/plugins/users/__init__.py +++ b/flaschengeist/plugins/users/__init__.py @@ -2,8 +2,10 @@ Provides routes used to manage users """ +from http.client import NO_CONTENT, CREATED + from flaschengeist.config import config -from flask import Blueprint, request, jsonify +from flask import Blueprint, request, jsonify, make_response from werkzeug.exceptions import BadRequest, Forbidden, MethodNotAllowed from flaschengeist import logger @@ -44,9 +46,9 @@ def register(): data = request.get_json() if not data: raise BadRequest - logger.debug("Register new User...") - return jsonify(userController.register(data)) + logger.debug("Register new User...") + return make_response(jsonify(userController.register(data)), CREATED) @users_bp.route("/users", methods=["GET"]) @@ -98,11 +100,12 @@ def delete_user(userid, current_session): current_session: Session sent with Authorization Header Returns: - HTTP-200 or HTTP error + HTTP-204 or HTTP error """ logger.debug("Delete user {{ {} }}".format(userid)) user = userController.get_user(userid) userController.delete(user) + return "", NO_CONTENT @users_bp.route("/users/", methods=["PUT"]) @@ -120,7 +123,7 @@ def edit_user(userid, current_session): current_session: Session sent with Authorization Header Returns: - HTTP-200 or HTTP error + HTTP-204 or HTTP error """ logger.debug("Modify information of user {{ {} }}".format(userid)) user = userController.get_user(userid) @@ -148,3 +151,4 @@ def edit_user(userid, current_session): userController.modify_user(user, password, new_password) userController.update_user(user) + return "", NO_CONTENT