[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
# 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()

View File

@ -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

View File

@ -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/<userid>", 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