diff --git a/code/auth-service/app.py b/code/auth-service/app.py index ad8e6e5618c3d7033ca360e7b8f660da4ca04a94..d30ff3539dd91df3c0829381daacf2d24ebc2f64 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 0497e0ebfeb1e81c1f8314723f0aff1a4310630c..89664aa617c5720171087da762c3034830978142 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()