From d78d282ee43ca0720ca6ff89b4be753279d2b0db Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominic=20Daniel=20Kr=C3=A4mer?=
 <Dominicdaniel3107@gmail.com>
Date: Wed, 26 Jun 2024 12:03:39 +0200
Subject: [PATCH] update reponse message

---
 code/auth-service/app.py       | 27 ++++++++++++++++++++-------
 code/auth-service/authModel.py | 12 ++++++++++++
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/code/auth-service/app.py b/code/auth-service/app.py
index ad8e6e5..d30ff35 100644
--- a/code/auth-service/app.py
+++ b/code/auth-service/app.py
@@ -25,7 +25,7 @@ def login():
     # make a call to the model to authenticate
     authentication = authModel.authenticate(username, hashed_password)
     if authentication == False:
-        return Response("Authentication unsuccessful", status=401, mimetype='application/json')
+        return Response("Authentication unsuccessful. Wrong credentials.", status=401, mimetype='application/json')
     else:
         response = Response("Authentication successful", status=200, mimetype='application/json')
         response.headers["UserID"] = username
@@ -80,13 +80,13 @@ def user():
         if authModel.verify(token):
             if not authModel.isAdmin(token):
                 if authModel.admin_exists():
-                    return Response("Registration unsuccessful", status=403, mimetype='application/json')
+                    return Response("Registration unsuccessful. Not authorized.", status=403, mimetype='application/json')
                 else:
                     # If there's no admin user already, the first created users becomes an admin
                     is_admin = True
         else:
             if authModel.admin_exists():
-                return Response("Registration unsuccessful", status=401, mimetype='application/json')
+                return Response("Registration unsuccessful. Not authorized.", status=401, mimetype='application/json')
             else:
                 # If there's no admin user already, the first created users becomes an admin
                 is_admin = True
@@ -106,7 +106,7 @@ def user():
         if createResponse:
             return Response("Registration successful", status=200, mimetype='application/json')
         else:
-            return Response("Registration unsuccessful", status=409, mimetype='application/json')
+            return Response("Registration unsuccessful. Please adjust your credentials.", status=409, mimetype='application/json')
 
     elif request.method == 'DELETE':
         username = request.form.get("user")
@@ -155,9 +155,22 @@ def cleanupBlacklist():
         return Response("Deletion unsuccessful", status=409, mimetype='application/json')
 
 
-@app.route("/list")
-def listUser():
-    pass
+# @app.route("/list")
+# def listUser():
+#     token = ""
+#     authorizationHeader = request.headers.get('authorization')
+#     if authorizationHeader is not None:
+#         token = authorizationHeader.replace("Bearer ", "")
+#     if authModel.verify(token):
+#         if not authModel.isAdmin(token):
+#             return Response('List unsuccessful', status=403, mimetype='application/json')
+#     else:
+#         return Response("List unsuccessful", status=401, mimetype='application/json')
+    
+#     if authModel.list_users():
+#         return Response("")
+#     else:
+#         return Response("")
 
 
 @app.route('/health')
diff --git a/code/auth-service/authModel.py b/code/auth-service/authModel.py
index 0497e0e..89664aa 100644
--- a/code/auth-service/authModel.py
+++ b/code/auth-service/authModel.py
@@ -246,6 +246,18 @@ def cleanBlacklist():
             cur.close()
             conn.close()
 
+
+def list_users():
+    conn = None
+    try:
+        conn, cur = db_connect()
+        cur.execute("SELECT * FROM users")
+        return True
+    
+    except:
+        pass
+
+
 def db_setup():
     conn, cur = db_connect()
 
-- 
GitLab