From 0738cddcd65e1f67e7f59a1f1ca19030e3f9d523 Mon Sep 17 00:00:00 2001 From: joker-x Date: Sun, 6 Sep 2020 02:28:20 +0200 Subject: [PATCH] Routes /cas/login and /cas/logout --- client/src/lib/page.js | 15 ++++++++++++--- client/src/login/Login.js | 25 ++++++++++++++++++++++--- server/app-builder.js | 8 ++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/client/src/lib/page.js b/client/src/lib/page.js index d5222617..9854bf73 100644 --- a/client/src/lib/page.js +++ b/client/src/lib/page.js @@ -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,7 +450,11 @@ export class SectionContent extends Component { ensureAuthenticated() { if (!mailtrainConfig.isAuthenticated) { - this.navigateTo('/login?next=' + encodeURIComponent(window.location.pathname)); + if (mailtrainConfig.authMethod == 'cas') { + window.location.href=getUrl('cas/login?next=' + encodeURIComponent(window.location.pathname)); + } else { + this.navigateTo('/login?next=' + encodeURIComponent(window.location.pathname)); + } } } @@ -602,7 +611,7 @@ export class DropdownLink extends Component { const clsName = "dropdown-item" + (props.className ? " " + props.className : "") return ( - {props.children} + window.location.href=props.to}>{props.children} ); } } @@ -729,4 +738,4 @@ export function getLanguageChooser(t) { ); return languageChooser; -} \ No newline at end of file +} diff --git a/client/src/login/Login.js b/client/src/login/Login.js index 1942b639..4f562279 100644 --- a/client/src/login/Login.js +++ b/client/src/login/Login.js @@ -110,8 +110,8 @@ export default class Login extends Component { } else if (mailtrainConfig.externalPasswordResetLink) { passwordResetLink = {t('forgotYourPassword?')}; } - - return ( + if (mailtrainConfig.authMethod != 'cas') { + return (
{t('signIn')} @@ -126,6 +126,25 @@ export default class Login extends Component {
- ); + ); + } else { + if (mailtrainConfig.isAuthenticated) { + return ( +
+ {t('logOut')} CAS + {{t('logOut')}} + {passwordResetLink} +
+ ); + } else { + return ( +
+ {t('signIn')} CAS + {{t('signIn')}} + {passwordResetLink} +
+ ); + } + } } } diff --git a/server/app-builder.js b/server/app-builder.js index da1a89da..e72bb671 100644 --- a/server/app-builder.js +++ b/server/app-builder.js @@ -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));