Initial Commit für das Grundgerüst der Anwendung, bestehend aus der Dev-Container Konfiguration, der Docker und docker-Compose Definitionen sowie der Verzeichnisse App_Server für die Backend-Programme sowie Client für die browserseitigen GUI-Komponenten
This commit is contained in:
1 parent
10549934ea
commit
1ba78992a6
63 files changed
+5410
No files matched your search
@@ -0,0 +1,235 @@
|
||||
from approot import login_manager
|
||||
from auth.model import (
|
||||
APP_ADMIN,
|
||||
APP_DOZENT,
|
||||
APP_USER,
|
||||
SYS_ADMIN,
|
||||
Application,
|
||||
Role,
|
||||
User,
|
||||
applications,
|
||||
roles,
|
||||
users,
|
||||
)
|
||||
from flask import current_app as app
|
||||
from flask import jsonify, request
|
||||
from flask_login import login_required, login_user, logout_user
|
||||
|
||||
from .model.errors import ApplicationError, AutorisationError
|
||||
|
||||
print("auth-routes")
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
def user_loader(userid):
|
||||
user: User | None = User.query.filter(User.userid == userid).first()
|
||||
return user
|
||||
|
||||
|
||||
@app.post("/auth/checklogin")
|
||||
def checklogin():
|
||||
"""
|
||||
Hier wird nur die Authentifizierung überprüft.
|
||||
Evtl. Autorisierungen anhand der User-Rollen und App-Berechtigungen müssen später bei den
|
||||
Funktionsaufrufen erfolgen
|
||||
"""
|
||||
data = request.json
|
||||
user: User = users.check_login(data["userid"], data["password"])
|
||||
if user is None:
|
||||
error = ApplicationError(
|
||||
"Login oder Kennwort stimmen nicht!",
|
||||
"Anmeldung wurde verweigert",
|
||||
htmlstatus=403,
|
||||
)
|
||||
return jsonify(error.error), error.htmlstatus
|
||||
if not user.has_roles([SYS_ADMIN, APP_ADMIN, APP_USER, APP_DOZENT]):
|
||||
error = ApplicationError(
|
||||
"Sie haben nicht die passende Rolle zur Nutzung dieser Anwendung.",
|
||||
"Der Zugang wird verweigert",
|
||||
htmlstatus=403,
|
||||
)
|
||||
return jsonify(error.error), error.htmlstatus
|
||||
login_user(user)
|
||||
result = user.to_dict()
|
||||
result["isSysAdmin"] = user.is_SysAdmin()
|
||||
return jsonify(result), 200
|
||||
|
||||
|
||||
@app.post("/auth/changepassword")
|
||||
@login_required
|
||||
def changepassword():
|
||||
data = request.json
|
||||
status = 200
|
||||
result = {"Message": "", "Success": True}
|
||||
try:
|
||||
users.changepassword(
|
||||
data["Userid"],
|
||||
data["OldPassword"],
|
||||
data["NewPassword1"],
|
||||
data["NewPassword2"],
|
||||
)
|
||||
except Exception as ex:
|
||||
error = ApplicationError(str(ex), htmlstatus=400)
|
||||
return error.error, error.htmlstatus
|
||||
|
||||
return jsonify(result), status
|
||||
|
||||
|
||||
@app.get("/auth/logout")
|
||||
def logout():
|
||||
logout_user()
|
||||
return jsonify({"logout": True}), 200
|
||||
|
||||
|
||||
@app.get("/auth/getusers")
|
||||
@login_required
|
||||
def getusers():
|
||||
"""
|
||||
Die Rückgabe wird in 'users.get_users()' (s.u.) anhand er App-Berechtigung und der
|
||||
Rollen gefiltert.
|
||||
"""
|
||||
userquery = users.get_users()
|
||||
result = []
|
||||
user: User
|
||||
for user in userquery:
|
||||
result.append(user.to_relationaldict())
|
||||
return jsonify(result), 200
|
||||
|
||||
|
||||
@app.get("/auth/getapplications")
|
||||
@login_required
|
||||
def getapplications():
|
||||
"""
|
||||
Die Rückgabe wird in 'applications.get_applications()' (s.u.) anhand er App-Berechtigung und der
|
||||
Rollen gefiltert.
|
||||
"""
|
||||
appquery = applications.get_applications()
|
||||
result = []
|
||||
app: Application
|
||||
for app in appquery:
|
||||
result.append(app.to_dict())
|
||||
return jsonify(result), 200
|
||||
|
||||
|
||||
@app.get("/auth/getroles")
|
||||
@login_required
|
||||
def getroles():
|
||||
rolelist = roles.get_roles()
|
||||
result = []
|
||||
role: Role
|
||||
for role in rolelist:
|
||||
result.append(role.to_dict())
|
||||
return jsonify(result), 200
|
||||
|
||||
|
||||
@app.post("/auth/updaterole")
|
||||
@login_required
|
||||
def updaterole():
|
||||
data = request.json
|
||||
try:
|
||||
roles.updaterole(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
if str(ex) == "404":
|
||||
return jsonify("Rolle nicht gefunden"), 404
|
||||
else:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/deleteroles")
|
||||
@login_required
|
||||
def deleteroles():
|
||||
data = request.json
|
||||
try:
|
||||
roles.deleteroles(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/updateapplication")
|
||||
@login_required
|
||||
def updateapplication():
|
||||
data = request.json
|
||||
try:
|
||||
applications.updateapplication(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/deleteapplications")
|
||||
@login_required
|
||||
def deleteapplications():
|
||||
data = request.json
|
||||
try:
|
||||
applications.deleteapplications(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return str(ex), 400
|
||||
return {}, 200
|
||||
|
||||
|
||||
@app.post("/auth/updateapplicationroles")
|
||||
@login_required
|
||||
def updateapplicationroles():
|
||||
data = request.json
|
||||
try:
|
||||
applications.updateapplicationroles(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/updateuser")
|
||||
@login_required
|
||||
def updateuser():
|
||||
data = request.json
|
||||
try:
|
||||
users.updateuser(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
if str(ex) == "404":
|
||||
return jsonify("Benutzer nicht gefunden"), 404
|
||||
else:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/applyuserapprole")
|
||||
@login_required
|
||||
def applyuserapprole():
|
||||
data = request.json
|
||||
try:
|
||||
users.applyuserapprole(data)
|
||||
except AutorisationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return jsonify(str(ex)), 400
|
||||
return jsonify({}), 200
|
||||
|
||||
|
||||
@app.post("/auth/deleteusers")
|
||||
@login_required
|
||||
def deleteusers():
|
||||
data = request.json
|
||||
try:
|
||||
users.deleteusers(data)
|
||||
except ApplicationError as ex:
|
||||
return jsonify(ex.error), ex.htmlstatus
|
||||
except Exception as ex:
|
||||
return jsonify(str(ex)), 400
|
||||
return {}, 200
|
||||
|
||||
|
||||
print("########## auth.routes importiert")
|
||||
Reference in new issue
Block a user