From 82982189137ecb29c901fda75981365cab1be26b Mon Sep 17 00:00:00 2001 From: x01dc Date: Mon, 9 Mar 2026 13:19:58 +0100 Subject: [PATCH] added account check at startup --- .../startup/post_startup.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/csaxs_bec/bec_ipython_client/startup/post_startup.py b/csaxs_bec/bec_ipython_client/startup/post_startup.py index 4f8b145..d560a94 100644 --- a/csaxs_bec/bec_ipython_client/startup/post_startup.py +++ b/csaxs_bec/bec_ipython_client/startup/post_startup.py @@ -111,3 +111,34 @@ bec._beamline_mixin._bl_info_register(OperatorInfo) # SETUP PROMPTS bec._ip.prompts.session_name = _session_name bec._ip.prompts.status = 1 + +# ACCOUNT MISMATCH CHECK +import os + +def _check_account_mismatch(): + try: + active = bec.active_account # e.g. "p23092" + system_user = os.getenv("USER") or os.getlogin() # e.g. "e23092" + if active[1:] != system_user[1:]: + print(f""" +\033[91m\033[1m + ██╗ ██╗ █████╗ ██████╗ ███╗ ██╗██╗███╗ ██╗ ██████╗ + ██║ ██║██╔══██╗██╔══██╗████╗ ██║██║████╗ ██║██╔════╝ + ██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║ ███╗ + ██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║ ██║ + ╚███╔███╔╝██║ ██║██║ ██║██║ ╚████║██║██║ ╚████║╚██████╔╝ + ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═══╝ ╚═════╝ + + ACCOUNT MISMATCH DETECTED! + BEC active account : {active} + System user : {system_user} + + Data read and written by the BEC client does not match the data account! + Please verify you are logged in with the correct account. +\033[0m""") + except Exception: + logger.warning("Failed to verify account match.") + + +if _args.session.lower() == "lamni" or _args.session.lower() == "flomni" or _args.session.lower() == "omny": + _check_account_mismatch() \ No newline at end of file