This commit is contained in:
Iván Eixarch 2020-09-16 08:55:13 +02:00 committed by GitHub
commit d98e2e5b56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 182 additions and 17 deletions

View file

@ -11,7 +11,7 @@ import {ActionLink, Button, DismissibleAlert, DropdownActionLink, Icon} from "./
import mailtrainConfig from "mailtrainConfig";
import styles from "./styles.scss";
import {getRoutes, renderRoute, Resolver, SectionContentContext, withPageHelpers} from "./page-common";
import {getBaseDir} from "./urls";
import {getBaseDir, getUrl} from "./urls";
import {createComponentMixin, withComponentMixins} from "./decorator-helpers";
import {getLang} from "../../../shared/langs";
@ -414,6 +414,12 @@ export class SectionContent extends Component {
}
componentDidMount() {
const t = this.props.t;
const queryParams = this.props.location.search;
if (queryParams.indexOf('cas-login-success') > -1) this.setFlashMessage('success', t('authenticationSuccessful'));
if (queryParams.indexOf('cas-logout-success') > -1) this.setFlashMessage('success', t('logoutSuccessful'));
if (queryParams.indexOf('cas-login-error') > -1) this.setFlashMessage('danger', t('authenticationFailed'));
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 +451,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));
}
}
}
@ -594,16 +604,23 @@ export class LinkButton extends Component {
export class DropdownLink extends Component {
static propTypes = {
to: PropTypes.string,
className: PropTypes.string
className: PropTypes.string,
forceReload: PropTypes.bool
}
render() {
const props = this.props;
const clsName = "dropdown-item" + (props.className ? " " + props.className : "")
return (
if (props.forceReload) {
return (
<Link to={props.to} className={clsName} onClick={() => window.location.href=props.to}>{props.children}</Link>
);
} else {
return (
<Link to={props.to} className={clsName}>{props.children}</Link>
);
);
}
}
}
@ -729,4 +746,4 @@ export function getLanguageChooser(t) {
);
return languageChooser;
}
}

View file

@ -110,8 +110,8 @@ export default class Login extends Component {
} else if (mailtrainConfig.externalPasswordResetLink) {
passwordResetLink = <a href={mailtrainConfig.externalPasswordResetLink}>{t('forgotYourPassword?')}</a>;
}
return (
if (mailtrainConfig.authMethod != 'cas') {
return (
<div>
<Title>{t('signIn')}</Title>
@ -126,6 +126,15 @@ export default class Login extends Component {
</ButtonRow>
</Form>
</div>
);
);
} else {
return (
<div>
<Title>{t('signIn')} CAS</Title>
{<a href="/cas/login" class="btn btn-primary">{t('signIn')}</a>}
{passwordResetLink}
</div>
);
}
}
}

View file

@ -96,7 +96,8 @@ class Root extends Component {
{getLanguageChooser(t)}
<NavDropdown menuClassName="dropdown-menu-right" label={mailtrainConfig.user.username} icon="user">
<DropdownLink to="/account"><Icon icon='user'/> {t('account')}</DropdownLink>
<DropdownActionLink onClickAsync={::this.logout}><Icon icon='sign-out-alt'/> {t('logOut')}</DropdownActionLink>
{mailtrainConfig.authMethod == 'cas' && <DropdownLink to="/cas/logout" forceReload><Icon icon="sign-out-alt"/> {t('logOut')}</DropdownLink>}
{mailtrainConfig.authMethod != 'cas' && <DropdownActionLink onClickAsync={::this.logout}><Icon icon='sign-out-alt'/> {t('logOut')}</DropdownActionLink>}
</NavDropdown>
</ul>
</>