Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ICAT
Datahub
Commits
59c8baff
Commit
59c8baff
authored
Aug 24, 2021
by
Marjolaine Bodin
Browse files
#522
login with different affiliation
parent
efe9e1e3
Pipeline
#53246
passed with stage
in 9 minutes and 14 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/actions/login.js
View file @
59c8baff
...
...
@@ -18,7 +18,11 @@ export function doSignIn(plugin, username, password) {
dispatch
({
type
:
LOG_IN
,
username
});
axios
.
post
(
`
${
ICATPLUS
.
server
}
/session`
,
{
plugin
,
username
,
password
})
.
post
(
`
${
ICATPLUS
.
server
}
/session`
,
{
plugin
,
username
,
password
,
})
.
then
(({
data
})
=>
{
if
(
!
data
||
!
data
.
sessionId
)
{
throw
new
Error
(
'
Invalid authentication response
'
);
...
...
@@ -51,13 +55,14 @@ export function doSignIn(plugin, username, password) {
};
}
export
function
doSilentRefreshFromSSO
()
{
export
function
doSilentRefreshFromSSO
(
affiliation
)
{
return
(
dispatch
)
=>
{
axios
.
post
(
`
${
ICATPLUS
.
server
}
/session`
,
{
plugin
:
ICAT
.
authentication
.
sso
.
plugin
,
username
:
null
,
password
:
keycloak
.
idToken
,
smisPk
:
affiliation
,
})
.
then
(({
data
})
=>
{
if
(
!
data
||
!
data
.
sessionId
)
{
...
...
@@ -90,44 +95,3 @@ export function doSilentRefreshFromSSO() {
});
};
}
export
function
switchAffiliation
(
name
)
{
return
(
dispatch
)
=>
{
axios
.
post
(
`
${
ICATPLUS
.
server
}
/session`
,
{
plugin
:
ICAT
.
authentication
.
sso
.
plugin
,
username
:
null
,
password
:
keycloak
.
idToken
,
smisPk
:
name
.
split
(
'
-
'
)[
1
],
})
.
then
(({
data
})
=>
{
if
(
!
data
||
!
data
.
sessionId
)
{
throw
new
Error
(
'
Invalid switch authentication response
'
);
}
const
{
sessionId
,
name
,
fullName
,
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
}
=
data
;
dispatch
({
type
:
LOGGED_IN
,
sessionId
,
name
,
fullName
,
isAdministrator
,
isInstrumentScientist
,
lifeTimeMinutes
,
affiliations
,
});
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
dispatch
({
type
:
LOGIN_ERROR
,
error
:
'
Switch authentication failed
'
});
});
};
}
src/components/Menu/AffiliationMenu.js
View file @
59c8baff
import
React
from
'
react
'
;
import
{
MenuItem
,
NavDropdown
}
from
'
react-bootstrap
'
;
import
{
useSelector
}
from
'
react-redux
'
;
import
{
useDispatch
,
useSelector
}
from
'
react-redux
'
;
import
{
dateFormatter
}
from
'
../Investigation/utils
'
;
import
{
switchAffiliation
}
from
'
../../actions/login
'
;
import
{
doSilentRefreshFromSSO
}
from
'
../../actions/login
'
;
function
AffiliationMenu
()
{
const
{
affiliations
}
=
useSelector
((
state
)
=>
state
.
user
);
const
dispatch
=
useDispatch
();
function
getAffiliationName
(
createTime
)
{
return
dateFormatter
(
createTime
,
'
DD/MM/YYYY
'
,
false
);
}
function
handleAffiliation
(
name
)
{
switchAffiliation
(
name
);
dispatch
(
doSilentRefreshFromSSO
(
name
.
split
(
'
-
'
)[
1
])
);
}
return
(
...
...
@@ -24,7 +25,7 @@ function AffiliationMenu() {
id
=
"
basic-nav-dropdown
"
>
{
affiliations
.
map
(({
name
,
createTime
})
=>
(
<
MenuItem
eventKey
=
{
name
}
onClick
=
{
handleAffiliation
(
name
)}
>
<
MenuItem
eventKey
=
{
name
}
onClick
=
{
()
=>
handleAffiliation
(
name
)}
>
{
getAffiliationName
(
createTime
)}
<
/MenuItem
>
))}
...
...
src/reducers/login.js
View file @
59c8baff
...
...
@@ -19,6 +19,7 @@ const initialState = {
isInstrumentScientist
:
false
,
isAuthenticating
:
false
,
isSessionExpired
:
false
,
affiliations
:
[],
error
:
null
,
};
...
...
@@ -49,6 +50,7 @@ const user = (state = initialState, action) => {
state
.
username
===
ICAT
.
authentication
.
anonymous
.
username
,
isAdministrator
:
action
.
isAdministrator
,
isInstrumentScientist
:
action
.
isInstrumentScientist
,
affiliations
:
action
.
affiliations
,
};
break
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment