Routes /cas/login and /cas/logout
This commit is contained in:
parent
28938b679b
commit
0738cddcd6
3 changed files with 42 additions and 6 deletions
|
@ -414,6 +414,11 @@ export class SectionContent extends Component {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
const queryParams = this.props.location.search;
|
||||
if (queryParams.indexOf('cas-login-success') > -1) this.setFlashMessage('success', 'Successful authentication');
|
||||
if (queryParams.indexOf('cas-logout-success') > -1) this.setFlashMessage('success', 'Successful logout');
|
||||
if (queryParams.indexOf('cas-login-error') > -1) this.setFlashMessage('danger', 'Fail authentication');
|
||||
|
||||
window.addEventListener('beforeunload', this.beforeUnloadHandler);
|
||||
this.historyUnblock = this.props.history.block('Changes you made may not be saved. Are you sure you want to leave this page?');
|
||||
}
|
||||
|
@ -445,9 +450,13 @@ export class SectionContent extends Component {
|
|||
|
||||
ensureAuthenticated() {
|
||||
if (!mailtrainConfig.isAuthenticated) {
|
||||
if (mailtrainConfig.authMethod == 'cas') {
|
||||
window.location.href=getUrl('cas/login?next=' + encodeURIComponent(window.location.pathname));
|
||||
} else {
|
||||
this.navigateTo('/login?next=' + encodeURIComponent(window.location.pathname));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerBeforeUnloadHandlers(handlers) {
|
||||
this.beforeUnloadListeners.register(handlers);
|
||||
|
@ -602,7 +611,7 @@ export class DropdownLink extends Component {
|
|||
|
||||
const clsName = "dropdown-item" + (props.className ? " " + props.className : "")
|
||||
return (
|
||||
<Link to={props.to} className={clsName}>{props.children}</Link>
|
||||
<Link to={props.to} className={clsName} onClick={() => window.location.href=props.to}>{props.children}</Link>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ export default class Login extends Component {
|
|||
} else if (mailtrainConfig.externalPasswordResetLink) {
|
||||
passwordResetLink = <a href={mailtrainConfig.externalPasswordResetLink}>{t('forgotYourPassword?')}</a>;
|
||||
}
|
||||
|
||||
if (mailtrainConfig.authMethod != 'cas') {
|
||||
return (
|
||||
<div>
|
||||
<Title>{t('signIn')}</Title>
|
||||
|
@ -127,5 +127,24 @@ export default class Login extends Component {
|
|||
</Form>
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
if (mailtrainConfig.isAuthenticated) {
|
||||
return (
|
||||
<div>
|
||||
<Title>{t('logOut')} CAS</Title>
|
||||
{<a href="/cas/logout" class="btn btn-primary">{t('logOut')}</a>}
|
||||
{passwordResetLink}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
<Title>{t('signIn')} CAS</Title>
|
||||
{<a href="/cas/login" class="btn btn-primary">{t('signIn')}</a>}
|
||||
{passwordResetLink}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -324,6 +324,14 @@ async function createApp(appType) {
|
|||
app.use('/rest', reportsRest);
|
||||
}
|
||||
install404Fallback('/rest');
|
||||
if (config.cas && config.cas.enabled === true) {
|
||||
app.get('/cas/login',
|
||||
passport.authenticateCas,
|
||||
function(req, res) {
|
||||
res.redirect('/?cas-login-success');
|
||||
});
|
||||
app.get('/cas/logout', passport.logoutCas);
|
||||
}
|
||||
}
|
||||
|
||||
app.use('/', await index.getRouter(appType));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue