From 214f389fe21e7acb97be55c403549a9e1976d383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 17 Jan 2020 01:05:58 +0100 Subject: [PATCH] added normal user --- geruecht/__init__.py | 2 ++ geruecht/baruser/routes.py | 1 + geruecht/routes.py | 3 +++ geruecht/user/__init__.py | 0 geruecht/user/routes.py | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 geruecht/user/__init__.py create mode 100644 geruecht/user/routes.py diff --git a/geruecht/__init__.py b/geruecht/__init__.py index 12caada..943228c 100644 --- a/geruecht/__init__.py +++ b/geruecht/__init__.py @@ -20,7 +20,9 @@ CORS(app) from geruecht import routes from geruecht.baruser.routes import baruser from geruecht.finanzer.routes import finanzer +from geruecht.user.routes import user LOGGER.info("Registrate bluebrints") app.register_blueprint(baruser) app.register_blueprint(finanzer) +app.register_blueprint(user) diff --git a/geruecht/baruser/routes.py b/geruecht/baruser/routes.py index 591281c..bc704a7 100644 --- a/geruecht/baruser/routes.py +++ b/geruecht/baruser/routes.py @@ -77,6 +77,7 @@ def _baradd(): type = 'amount' dic = user.toJSON() dic['amount'] = abs(all) + dic['type'] = type return jsonify(dic) return jsonify({"error", "permission denied"}), 401 diff --git a/geruecht/routes.py b/geruecht/routes.py index 4343f19..6db7239 100644 --- a/geruecht/routes.py +++ b/geruecht/routes.py @@ -8,6 +8,7 @@ from flask import request, jsonify def login(user, password): return user.login(password) + @app.route("/valid") def _valid(): token = request.headers.get("Token") @@ -25,6 +26,7 @@ def _valid(): return jsonify(accToken.user.toJSON()) return jsonify({"error": "permission denied"}), 401 + @app.route("/login", methods=['POST']) def _login(): """ Login User @@ -44,6 +46,7 @@ def _login(): LOGGER.info("search {} in database".format(username)) try: user = userController.loginUser(username, password) + user.password = password token = accesTokenController.createAccesToken(user) dic = user.toJSON() dic["token"] = token diff --git a/geruecht/user/__init__.py b/geruecht/user/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/geruecht/user/routes.py b/geruecht/user/routes.py new file mode 100644 index 0000000..af4341b --- /dev/null +++ b/geruecht/user/routes.py @@ -0,0 +1,34 @@ +from flask import Blueprint, request, jsonify +from geruecht.controller import userController, accesTokenController +from geruecht.model import USER +from datetime import datetime + +user = Blueprint("user", __name__) + +@user.route("/user/main") +def _main(): + + token = request.headers.get("Token") + accToken = accesTokenController.validateAccessToken(token, USER) + if accToken: + accToken.user = userController.getUser(accToken.user.uid) + retVal = accToken.user.toJSON() + retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + return jsonify(retVal) + return jsonify({"error": "permission denied"}), 401 + +@user.route("/user/addAmount", methods=['POST']) +def _addAmount(): + + token = request.headers.get("Token") + accToken = accesTokenController.validateAccessToken(token, USER) + if accToken: + data = request.get_json() + amount = int(data['amount']) + date = datetime.now() + userController.addAmount(accToken.user.uid, amount, year=date.year, month=date.month) + accToken.user = userController.getUser(accToken.user.uid) + retVal = accToken.user.toJSON() + retVal['creditList'] = {credit.year: credit.toJSON() for credit in accToken.user.geruechte} + return jsonify(retVal) + return jsonify({"error": "permission denied"}), 401 \ No newline at end of file