added normal user
This commit is contained in:
parent
e42a97eca4
commit
214f389fe2
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue