Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hanling user "logged in" state in a more robust way in login_info #1513

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mxcubeweb/core/components/user/usermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,17 @@ def force_signout_user(self, username):
self.app.server.emit("forceSignout", room=socketio_sid, namespace="/hwr")

def login_info(self):
if not current_user.is_anonymous:
session_manager: LimsSessionManager = self.app.lims.get_session_manager()
# update_operator will update the login status of current_user, and make
# sure that the is_anonymous has the correct value.
# Update operator calls lims.select_session that raises an exception if
# there are no valid LIMS sessions.
try:
self.update_operator()
except Exception:
pass

if not current_user.is_anonymous:
session_manager: LimsSessionManager = self.app.lims.get_session_manager()
login_type = (
"User" if HWR.beamline.lims.is_user_login_type() else "Proposal"
)
Expand Down
9 changes: 2 additions & 7 deletions mxcubeweb/routes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ def unauth_handler():

@server.flask.before_request
def before_request():
# logging.getLogger("MX3.HWR").debug('Remote Addr: %s', request.remote_addr)
# logging.getLogger("MX3.HWR").debug('Path: %s', request.full_path)
# logging.getLogger("MX3.HWR").debug('scheme: %s', request.scheme)
# logging.getLogger("MX3.HWR").debug('Headers: %s', request.headers)

if not flask_login.current_user.is_anonymous:
flask_login.current_user.last_request_timestamp = datetime.now()
app.usermanager.update_user(flask_login.current_user)
Expand All @@ -77,7 +72,7 @@ def exceptions(e):
tb = traceback.format_exc()
timestamp = time.strftime("[%Y-%b-%d %H:%M]")
logging.getLogger("MX3.HWR").debug(
"%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s",
"%s %s %s %s %s 501 INTERNAL SERVER ERROR\n%s",
timestamp,
request.remote_addr,
request.method,
Expand All @@ -86,6 +81,6 @@ def exceptions(e):
tb,
)

return tb
return jsonify({"error": "Server error"}), 501

return bp
Loading