add role to user auth API
This commit is contained in:
parent
886a15945d
commit
1b9bb3a83f
|
@ -962,14 +962,20 @@ def create_app():
|
||||||
if not type(hblink_req['id']) == int:
|
if not type(hblink_req['id']) == int:
|
||||||
user = hblink_req['id']
|
user = hblink_req['id']
|
||||||
u = User.query.filter_by(username=user).first()
|
u = User.query.filter_by(username=user).first()
|
||||||
|
|
||||||
if not u:
|
if not u:
|
||||||
msg = jsonify(auth=False,
|
msg = jsonify(auth=False,
|
||||||
reason='User not found')
|
reason='User not found')
|
||||||
response = make_response(msg, 401)
|
response = make_response(msg, 401)
|
||||||
if u:
|
if u:
|
||||||
|
u_role = UserRoles.query.filter_by(user_id=u.id).first()
|
||||||
password = user_manager.verify_password(hblink_req['password'], u.password)
|
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:
|
if password:
|
||||||
response = jsonify(auth=True)
|
response = jsonify(auth=True, role=role)
|
||||||
else:
|
else:
|
||||||
msg = jsonify(auth=False,
|
msg = jsonify(auth=False,
|
||||||
reason='Incorrect password')
|
reason='Incorrect password')
|
||||||
|
|
Loading…
Reference in New Issue