From 1b9bb3a83f647c385918bf273b03469603657bed Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Sat, 22 May 2021 18:01:31 -0700 Subject: [PATCH] add role to user auth API --- user_managment/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/user_managment/app.py b/user_managment/app.py index 5949bed..50accfb 100644 --- a/user_managment/app.py +++ b/user_managment/app.py @@ -962,14 +962,20 @@ def create_app(): if not type(hblink_req['id']) == int: user = hblink_req['id'] u = User.query.filter_by(username=user).first() + if not u: msg = jsonify(auth=False, reason='User not found') response = make_response(msg, 401) if u: + u_role = UserRoles.query.filter_by(user_id=u.id).first() password = user_manager.verify_password(hblink_req['password'], u.password) + if u_role.role_id == 2: + role = 'user' + if u_role.role_id == 1: + role = 'admin' if password: - response = jsonify(auth=True) + response = jsonify(auth=True, role=role) else: msg = jsonify(auth=False, reason='Incorrect password')