def put(self): admin = User.find_by_id(get_jwt_identity()) data = request.get_json() user = User.find_by_id(data['user_id']) if not user.is_admin: return {"msg": "Sie haben nicht die notwendigen Rechte."}, 403 if not user: return {"msg": "User konnte nicht gefunden werden."}, 404 else: for key, value in data.items(): user[key] = data[key] try: user.save() return { "msg": "User {username}/{vorname} wurde geupdatet.".format( username=user.username, vorname=user.vorname) } except: return {"msg": "Ein Fehler ist beim Speichern aufgetreten."}, 500
def add_claims_to_jwt(identity): from app.api.user.models import User user = User.find_by_id(identity) if user.is_admin: return {'roles': "admin"} return {'roles': "user"}
def post(self): response = {} user = User.find_by_id(get_jwt_identity()) if not user.admin: response['status'] = "ERROR" response['msg'] = "No admin rights" return response, 403 else: schema = UserSchema() result = schema.load(request.json) if not result.errors: if User.find_by_username(username=result.data['username']): response["status"] = "ERROR" response["msg"] = "Username existiert bereits" return response, 400 else: data = request.get_json() user = User(**data) user.save() response['status'] = "OK" response['msg'] = "User wurde angelegt" return response, 201 else: response['status'] = "ERROR" response['msg'] = result.errors return response, 300
def put(self): admin = User.find_by_id(get_jwt_identity()) systemSetting = SystemSetting.get_setting() if not admin.is_admin: return {"msg": "Sie haben nicht die notwendigen Rechte."}, 403 if not sysSetting: return {"msg": "Etwas ist schief gelaufen."}, 500 data = request.get_json() for key, value in data.items(): systemSetting[key] = data[key] try: sysSetting.save() return { "msg": "System Einstellungen wurden erfolgreich gespeichert." }, 201 except: return { "msg": "Etwas ist beim Speichern der System Einstellungen schief gelaufen" }, 500
def get(self): admin = User.find_by_id(get_jwt_identity()) if not user.is_admin: return {"msg": "Sie haben nicht die notwendigen Rechte."}, 403 users = User.get_all() return {"users": [user.json() for user in users]}
def get(self): user = User.find_by_id(get_jwt_identity()) schema = UserSchema() response = { "status": "OK", "user": schema.dump(user).data } return response, 200
def get(self): response = {} user = User.find_by_id(get_jwt_identity()) if not user.admin: response['status'] = "ERROR" response['msg'] = "No admin rights" return response, 403 else: schema = UserSchema(many=True) users = User.get_all() return schema.dump(users).data, 200
def get(self): systemSetting = SystemSetting.get_setting() admin = User.find_by_id(get_jwt_identity()) if not user.is_admin: return {"msg": "Sie haben nicht die notwendigen Rechte."}, 403 if not sysSetting: return {"msg": "Etwas ist schief gelaufen."}, 500 return {"sysSetting": systemSetting.json()}
def put(self): user_id = get_jwt_identity() user = User.query.filter_by(id=user_id) user.update(request.json) db.session.commit() user = User.find_by_id(get_jwt_identity()) schema = UserSchema() response = {"status": "OK", "user": schema.dump(user).data} return response, 200
def put(self): user = User.find_by_id(get_jwt_identity()) data = request.get_json() if not user: return {"msg": "Kein User gefunden."}, 404 else: for key, value in data.items(): user[key] = data[key] try: user.save() return {"msg": "Daten wurden gespeichert."}, 201 except: return { "msg": "Etwas ist beim Speichern der User-Daten schief gelaufen." }, 500
def post(self): response = {} admin = User.find_by_id(get_jwt_identity()) if not admin.is_admin: response['status'] = "ERROR" response[ 'message'] = "Sie haben nicht die nötigen Rechte. Bitte wenden sie sich an den Admin." return response, 403 data = request.get_json() if User.find_by_username(data['username']): response['status'] = "ERROR" response['message'] = "Username vergeben" return response, 500 user = User(**data) user.save() response['status'] = "OK" response['message'] = "User wurde angelegt" return response, 201
def get(self): user = User.find_by_id(get_jwt_identity()) if not user: return {"msg": "User nicht gefunden."}, 404 return {"user": user.json()}, 200