Skip to content

Commit

Permalink
Now sends login_type to anonymous users in login_info
Browse files Browse the repository at this point in the history
This information is needed to display appropriate text when signing in with user-based login.
Previously the same text was shown for both user-based and proposal-based login types.
  • Loading branch information
mockoocy committed Feb 18, 2025
1 parent d354801 commit 8766305
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 7 additions & 3 deletions mxcubeweb/core/components/user/usermanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ def login_info(self):
except Exception:
pass

login_type = "User" if HWR.beamline.lims.is_user_login_type() else "Proposal"

if current_user.is_anonymous:
self._signout()
logging.getLogger("MX3.HWR").info("Logged out")
res = {"loggedIn": False, "useSSO": self.app.CONFIG.sso.USE_SSO}
return {
"loggedIn": False,
"useSSO": self.app.CONFIG.sso.USE_SSO,
"loginType": login_type,
}

session_manager: LimsSessionManager = self.app.lims.get_session_manager()

Expand All @@ -294,8 +300,6 @@ def login_info(self):
):
self.app.lims.select_session(session_manager.active_session.session_id)

login_type = "User" if HWR.beamline.lims.is_user_login_type() else "Proposal"

res = {
"synchrotronName": HWR.beamline.session.synchrotron_name,
"beamlineName": HWR.beamline.session.beamline_name,
Expand Down
12 changes: 11 additions & 1 deletion ui/src/components/LoginForm/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import { logIn } from '../../actions/login';

const SSO_PATH = '/mxcube/api/v0.1/login/ssologin';

/** */
function getSignInText(useSSO, loginType) {
if (useSSO) {
return 'Sign in with SSO';
}
return loginType === 'User' ? 'Sign in' : 'Sign in with proposal';
}

function LoginForm() {
const dispatch = useDispatch();

Expand All @@ -26,6 +34,8 @@ function LoginForm() {
} = useForm({ defaultValues: { username: '', password: '' } });

const useSSO = useSelector((state) => state.login.useSSO);
const loginType = useSelector((state) => state.login.loginType);
const signInText = getSignInText(useSSO, loginType);

async function handleSubmit(data) {
if (useSSO) {
Expand Down Expand Up @@ -116,7 +126,7 @@ function LoginForm() {
{loading && (
<img className={styles.loader} src={loader} width="25" alt="" />
)}
Sign in with {useSSO ? 'SSO' : 'proposal'}
{signInText}
</Button>

{!loading && showErrorPanel && (
Expand Down

0 comments on commit 8766305

Please sign in to comment.