[Plugin] Fixed return values in auth and users routes

This commit is contained in:
Ferdinand Thiessen 2020-10-31 15:20:28 +01:00
parent 278111bf5e
commit e5b39a6ef6
3 changed files with 18 additions and 9 deletions

View File

@ -1,3 +1,8 @@
#!/usr/bin/python3 #!/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 from flaschengeist.app import create_app
application = create_app() application = create_app()

View File

@ -2,8 +2,8 @@
Allow management of authentication, login, logout, etc. Allow management of authentication, login, logout, etc.
""" """
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from http.client import CREATED, NO_CONTENT
from werkzeug.exceptions import Forbidden, BadRequest, Unauthorized from werkzeug.exceptions import Forbidden, BadRequest, Unauthorized
from flaschengeist import logger from flaschengeist import logger
@ -49,7 +49,7 @@ def login():
# Lets cleanup the DB # Lets cleanup the DB
sessionController.clear_expired() sessionController.clear_expired()
return jsonify({"session": session, "user": user}) return {"session": session, "user": user}, CREATED
@auth_bp.route("/auth", methods=["GET"]) @auth_bp.route("/auth", methods=["GET"])
@ -125,7 +125,7 @@ def set_lifetime(token, current_session, **kwargs):
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
Returns: Returns:
HTTP-200 (empty) or HTTP error HTTP-204 or HTTP error
""" """
session = sessionController.get_session(token, current_session._user) session = sessionController.get_session(token, current_session._user)
if not session: if not session:
@ -136,7 +136,7 @@ def set_lifetime(token, current_session, **kwargs):
lifetime = request.get_json()["value"] lifetime = request.get_json()["value"]
logger.debug("set lifetime {{ {} }} to access token {{ {} }}".format(lifetime, token)) logger.debug("set lifetime {{ {} }} to access token {{ {} }}".format(lifetime, token))
sessionController.set_lifetime(session, lifetime) sessionController.set_lifetime(session, lifetime)
return "" return "", NO_CONTENT
except (KeyError, TypeError): except (KeyError, TypeError):
raise BadRequest raise BadRequest

View File

@ -2,8 +2,10 @@
Provides routes used to manage users Provides routes used to manage users
""" """
from http.client import NO_CONTENT, CREATED
from flaschengeist.config import config 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 werkzeug.exceptions import BadRequest, Forbidden, MethodNotAllowed
from flaschengeist import logger from flaschengeist import logger
@ -44,9 +46,9 @@ def register():
data = request.get_json() data = request.get_json()
if not data: if not data:
raise BadRequest 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"]) @users_bp.route("/users", methods=["GET"])
@ -98,11 +100,12 @@ def delete_user(userid, current_session):
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
Returns: Returns:
HTTP-200 or HTTP error HTTP-204 or HTTP error
""" """
logger.debug("Delete user {{ {} }}".format(userid)) logger.debug("Delete user {{ {} }}".format(userid))
user = userController.get_user(userid) user = userController.get_user(userid)
userController.delete(user) userController.delete(user)
return "", NO_CONTENT
@users_bp.route("/users/<userid>", methods=["PUT"]) @users_bp.route("/users/<userid>", methods=["PUT"])
@ -120,7 +123,7 @@ def edit_user(userid, current_session):
current_session: Session sent with Authorization Header current_session: Session sent with Authorization Header
Returns: Returns:
HTTP-200 or HTTP error HTTP-204 or HTTP error
""" """
logger.debug("Modify information of user {{ {} }}".format(userid)) logger.debug("Modify information of user {{ {} }}".format(userid))
user = userController.get_user(userid) user = userController.get_user(userid)
@ -148,3 +151,4 @@ def edit_user(userid, current_session):
userController.modify_user(user, password, new_password) userController.modify_user(user, password, new_password)
userController.update_user(user) userController.update_user(user)
return "", NO_CONTENT