Newer
Older
:copyright: (c) 2017 European Spallation Source ERIC
:license: BSD 2-Clause, see LICENSE for more details.
"""
from flask import current_app, Blueprint, jsonify, request
from flask_ldap3_login import AuthenticationResponseStatus
from flask_login import login_required, current_user
"""Return users information
.. :quickref: User; Get users information
"""
return get_generic_model(models.User, order_by=models.User.username)
def get_user_profile():
"""Return the current user profile
.. :quickref: User; Get current user profile
"""
return jsonify(current_user.to_dict()), 200
:jsonparam username: username to login
:jsonparam password: password
raise utils.CSEntryError("Body should be a JSON object")
username = data["username"]
password = data["password"]
raise utils.CSEntryError(
"Missing mandatory field (username or password)", status_code=422
)
response = ldap_manager.authenticate(username, password)
if response.status == AuthenticationResponseStatus.success:
current_app.logger.debug(f"{username} successfully logged in")
response.user_dn, response.user_id, response.user_info, response.user_groups
)
payload = {"access_token": tokens.generate_access_token(identity=user.id)}
raise utils.CSEntryError("Invalid credentials", status_code=401)