add role to user auth API

This commit is contained in:
KF7EEL 2021-05-22 18:01:31 -07:00
parent 886a15945d
commit 1b9bb3a83f
1 changed files with 7 additions and 1 deletions

View File

@ -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')