added normal user

This commit is contained in:
Tim Gröger 2020-01-17 01:05:58 +01:00
parent e42a97eca4
commit 214f389fe2
5 changed files with 40 additions and 0 deletions

View File

@ -20,7 +20,9 @@ CORS(app)
from geruecht import routes from geruecht import routes
from geruecht.baruser.routes import baruser from geruecht.baruser.routes import baruser
from geruecht.finanzer.routes import finanzer from geruecht.finanzer.routes import finanzer
from geruecht.user.routes import user
LOGGER.info("Registrate bluebrints") LOGGER.info("Registrate bluebrints")
app.register_blueprint(baruser) app.register_blueprint(baruser)
app.register_blueprint(finanzer) app.register_blueprint(finanzer)
app.register_blueprint(user)

View File

@ -77,6 +77,7 @@ def _baradd():
type = 'amount' type = 'amount'
dic = user.toJSON() dic = user.toJSON()
dic['amount'] = abs(all) dic['amount'] = abs(all)
dic['type'] = type
return jsonify(dic) return jsonify(dic)
return jsonify({"error", "permission denied"}), 401 return jsonify({"error", "permission denied"}), 401

View File

@ -8,6 +8,7 @@ from flask import request, jsonify
def login(user, password): def login(user, password):
return user.login(password) return user.login(password)
@app.route("/valid") @app.route("/valid")
def _valid(): def _valid():
token = request.headers.get("Token") token = request.headers.get("Token")
@ -25,6 +26,7 @@ def _valid():
return jsonify(accToken.user.toJSON()) return jsonify(accToken.user.toJSON())
return jsonify({"error": "permission denied"}), 401 return jsonify({"error": "permission denied"}), 401
@app.route("/login", methods=['POST']) @app.route("/login", methods=['POST'])
def _login(): def _login():
""" Login User """ Login User
@ -44,6 +46,7 @@ def _login():
LOGGER.info("search {} in database".format(username)) LOGGER.info("search {} in database".format(username))
try: try:
user = userController.loginUser(username, password) user = userController.loginUser(username, password)
user.password = password
token = accesTokenController.createAccesToken(user) token = accesTokenController.createAccesToken(user)
dic = user.toJSON() dic = user.toJSON()
dic["token"] = token dic["token"] = token

View File

34
geruecht/user/routes.py Normal file
View File

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