Commit 599717d0 authored by Magnus Westergaard's avatar Magnus Westergaard
Browse files

DEICH-5341: Immediately log out and display alert on front page if someone...

DEICH-5341: Immediately log out and display alert on front page if someone younger than 15 logs in using ID-porten.
parent cfa93dc8
const alerts = {
IDPORTEN_UNDER_15: {
type: "warning",
message:
"Du er under 15 år og kan dessverre ikke registrere deg selv som voksen på deichman.no. Du har derfor blitt automatisk logget ut av ID-porten.",
link: "/registrer-deg/selvreg/barn",
linkText: "Registrer deg som barn her."
}
};
export default alerts;
import React, { Fragment } from "react";
import Link from "next/link";
import { withRouter } from "next/router";
import { connect } from "react-redux";
import PropTypes from "prop-types";
import autoBind from "auto-bind";
import { getEvents } from "../store/events";
import LANDING_PAGE from "../constants/landingPage";
import ALERTS from "../constants/alerts";
import Head from "../components/Head";
import EventGrid from "../components/EventGrid";
......@@ -19,7 +21,8 @@ import {
Icon,
Flex,
Grid,
GridItem
GridItem,
Alert
} from "@digibib/deichman-ui";
import HighlightedServicesContainer from "../components/HighlightedServices/HighlightedServicesContainer";
import { getCampaigns } from "../store/campaigns";
......@@ -38,7 +41,11 @@ class IndexPage extends React.Component {
};
render() {
const { allEvents = [], highlightedEvents = [] } = this.props.events;
const {
events: { allEvents = [], highlightedEvents = [] },
router
} = this.props;
const { query = {} } = router;
const inlineFilterOptions = [
{
......@@ -87,9 +94,37 @@ class IndexPage extends React.Component {
}
];
// keycloak seems to lowercase query params in redirect URLs,
// so in case it's after an SSO logout, uppercase the alert key
const alertToDisplay = ALERTS[query.alert?.toUpperCase()];
return (
<Fragment>
<Head title="Deichman.no" />
{alertToDisplay && (
<Container>
<Alert
type={alertToDisplay.type}
closeLabel="Lukk"
onClose={() => {
router.replace("/", undefined, { shallow: true });
}}
>
<Block top={4} bottom={4}>
<p>{alertToDisplay.message}</p>
{alertToDisplay.link && (
<Block top={4}>
<p>
<Link href={alertToDisplay.link}>
<a>{alertToDisplay.linkText}</a>
</Link>
</p>
</Block>
)}
</Block>
</Alert>
</Container>
)}
<CampaignZone type="top" page="Forside" />
<Container>
{highlightedEvents.length > 0 && (
......@@ -168,7 +203,8 @@ class IndexPage extends React.Component {
IndexPage.propTypes = {
events: PropTypes.object.isRequired,
getEvents: PropTypes.func.isRequired
getEvents: PropTypes.func.isRequired,
router: PropTypes.object.isRequired
};
function mapStateToProps(state) {
......@@ -188,4 +224,4 @@ function mapDispatchToProps(dispatch) {
export default connect(
mapStateToProps,
mapDispatchToProps
)(IndexPage);
)(withRouter(IndexPage));
import React, { useEffect } from "react";
import PropTypes from "prop-types";
import { useDispatch } from "react-redux";
import Router from "next/router";
import { logout, getStatus } from "../store/auth";
import Head from "../components/Head";
import FullScreen from "../components/FullScreen";
import { Block, Text } from "@digibib/deichman-ui";
const LogoutPage = props => {
const { query } = props;
const dispatch = useDispatch();
useEffect(() => {
(async () => {
const isLoggedIn = await dispatch(getStatus());
if (isLoggedIn) {
dispatch(logout(query));
} else {
Router.push("/");
}
})();
}, []);
return (
<>
<Head title="Logg ut - Deichman.no" />
<FullScreen>
<h1 className="h2">Vennligst vent</h1>
<Block top={4}>
<Text gray>Du blir straks logget ut.</Text>
</Block>
</FullScreen>
</>
);
};
LogoutPage.getInitialProps = ({ query }) => {
return {
query
};
};
LogoutPage.propTypes = {
query: PropTypes.object.isRequired
};
export default LogoutPage;
import React, { Fragment } from "react";
import PropTypes from "prop-types";
import Head from "../../components/Head";
import { completeRegistrationPages } from "../../constants/navItems";
import { withAuthSync } from "../../utilities/auth";
import { connect } from "react-redux";
import FullScreen from "../../components/FullScreen";
import autoBind from "auto-bind";
import SubNav from "../../components/SubNav";
import { fetchIdPortenInfo } from "../../store/idporten";
import { logout } from "../../store/auth";
import { Container, Block, Grid, GridItem, Loader } from "@digibib/deichman-ui";
class WelcomePageUnder15 extends React.Component {
constructor(props) {
super(props);
autoBind(this);
}
componentDidMount() {
setTimeout(() => {
this.props.logout();
}, 5000);
this.props.fetchIdPortenInfo();
}
render() {
const { idporten } = this.props;
return (
<Fragment>
<Head
title="Min side - Deichman.no"
description="Velkommen som låner på Deichman.no"
/>
<Head title="Min side - Deichman.no" />
<SubNav items={completeRegistrationPages} />
{idporten.isRequestingIdPortenInfo ? (
<FullScreen>
<Loader />
</FullScreen>
) : (
<Container>
<Block top={8}>
<Grid>
<GridItem large="two-fifths" />
<GridItem large="three-fifths">
<h2 className="h3">
Hei {idporten.name}, {idporten.isRequestingIdPortenInfo}
</h2>
<Block top={4}>
<p>
Du er under 15 år og kan desverre ikke registrere deg selv
som voksen Deichman.no. Du vil bli logget ut
automatisk.
</p>
</Block>
</GridItem>
</Grid>
</Block>
</Container>
)}
</Fragment>
);
}
}
WelcomePageUnder15.propTypes = {
idporten: PropTypes.object.isRequired,
fetchIdPortenInfo: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired
};
function mapDispatchToProps(dispatch) {
return {
logout: () => dispatch(logout()),
fetchIdPortenInfo: () => dispatch(fetchIdPortenInfo())
};
}
const mapStateToProps = state => ({
idporten: state.idporten
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(withAuthSync(WelcomePageUnder15));
......@@ -123,7 +123,7 @@ routes.get("/idporten", async (request, response) => {
} else if (authorities.includes("ROLE_IDPORTEN_UNDER_15")) {
request.session.jwt_token = resolvedResponse.access_token;
request.session.refresh_token = resolvedResponse.refresh_token;
response.redirect("/min-side/under-15");
response.redirect("/logg-ut?alert=IDPORTEN_UNDER_15");
} else if (authorities.includes("ROLE_IDPORTEN_MINIMAL_TOKEN")) {
request.session.jwt_token = resolvedResponse.access_token;
request.session.refresh_token = resolvedResponse.refresh_token;
......
......@@ -169,7 +169,7 @@ export function login(data, preventRedirect, target) {
};
}
export function logout() {
export function logout(redirectQueryParams) {
return dispatch => {
dispatch(logoutRequest());
fetch("/api/auth/logout", {
......@@ -181,9 +181,11 @@ export function logout() {
dispatch(reset());
authLogout();
if (res && res.authServerUrl) {
window.location = `${res.authServerUrl}/exit?logoutUrl=${
window.location.origin
}`;
const queryParams = redirectQueryParams
? `?${new URLSearchParams(redirectQueryParams).toString()}`
: "";
const logoutUrl = `${window.location.origin}${queryParams}`;
window.location = `${res.authServerUrl}/exit?logoutUrl=${logoutUrl}`;
} else {
window.location.href = window.location.href;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment