Skip to content

Commit 86a4a06

Browse files
committed
Proper handling of logout and session expired home page.
1 parent fddb772 commit 86a4a06

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

src/containers/App/App.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ import { loggedInUserIdSelector, accessTokenSelector } from '../../redux/selecto
1111
import { fetchUserIfNeeded } from '../../redux/modules/users.js';
1212
import { fetchUserStatus } from '../../redux/selectors/users.js';
1313
import { isTokenValid, isTokenInNeedOfRefreshment } from '../../redux/helpers/token';
14-
import { addNotification } from '../../redux/modules/notifications.js';
1514
import { logout, refresh } from '../../redux/modules/auth.js';
1615
import { resourceStatus } from '../../redux/helpers/resourceManager';
1716
import { suspendAbortPendingRequestsOptimization } from '../../pages/routes.js';
18-
import { SESSION_EXPIRED_MESSAGE } from '../../redux/helpers/api/tools.js';
1917
import withRouter, { withRouterProps } from '../../helpers/withRouter.js';
2018

2119
import './siscodex.css';
@@ -69,20 +67,18 @@ class App extends Component {
6967
* must be checked more often.
7068
*/
7169
checkAuthentication = () => {
72-
const { isLoggedIn, accessToken, refreshToken, logout, addNotification } = this.props;
70+
const { isLoggedIn, accessToken, refreshToken, logout } = this.props;
7371

7472
const token = accessToken ? accessToken.toJS() : null;
7573
if (isLoggedIn) {
7674
if (!isTokenValid(token)) {
7775
logout();
78-
addNotification(SESSION_EXPIRED_MESSAGE, false);
7976
} else if (isTokenInNeedOfRefreshment(token) && !this.isRefreshingToken) {
8077
suspendAbortPendingRequestsOptimization();
8178
this.isRefreshingToken = true;
8279
refreshToken()
8380
.catch(() => {
8481
logout();
85-
addNotification(SESSION_EXPIRED_MESSAGE, false);
8682
})
8783
.then(() => {
8884
this.isRefreshingToken = false;
@@ -104,7 +100,6 @@ App.propTypes = {
104100
loadAsync: PropTypes.func.isRequired,
105101
refreshToken: PropTypes.func.isRequired,
106102
logout: PropTypes.func.isRequired,
107-
addNotification: PropTypes.func.isRequired,
108103
location: withRouterProps.location,
109104
};
110105

@@ -123,7 +118,6 @@ export default withRouter(
123118
loadAsync: userId => App.loadAsync({}, dispatch, { userId }),
124119
refreshToken: () => dispatch(refresh()),
125120
logout: () => dispatch(logout()),
126-
addNotification: (msg, successful) => dispatch(addNotification(msg, successful)),
127121
})
128122
)(App)
129123
);

src/locales/cs.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
"app.homepage.termsPage": "Správa semestrů a jejich souvisejících dat (kdy jsou aktivní pro studenty a učitele).",
149149
"app.homepage.title": "Rozšíření SIS-CodEx",
150150
"app.homepage.userPage": "Stránka s osobními údaji umožnujě synchronizovat uživatelský profil (jméno, tituly, email) s daty ze SISu.",
151+
"app.homepage.userSessionExpired": "Vaše uživatelská relace vypršela",
152+
"app.homepage.userSessionExpiredInfo": "Musíte inicializovat novou relaci opětovným vstupem do této aplikace z ReCodExu.",
151153
"app.localizedTexts.validation.noLocalizedText": "Prosíme povolte alespoň jednu záložku s lokalizovanými texty.",
152154
"app.notifications.hideAll": "Pouze nové notifikace",
153155
"app.notifications.showAll": "Zobrazit {count, plural, one {jednu starou notifikaci} two {dvě staré notifikace} other {# starých notifikací}}",

src/locales/en.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@
148148
"app.homepage.termsPage": "Management of terms and their related dates (when they are active for students and teachers).",
149149
"app.homepage.title": "SiS-CodEx Extension",
150150
"app.homepage.userPage": "The personal data integration page allows updating ReCodEx user profile (name, titles, email) using data from SIS.",
151+
"app.homepage.userSessionExpired": "Your user session has expired",
152+
"app.homepage.userSessionExpiredInfo": "You need to initialize a new session by re-entering this application from ReCodEx.",
151153
"app.localizedTexts.validation.noLocalizedText": "Please enable at least one tab of localized texts.",
152154
"app.notifications.hideAll": "Only new notifications",
153155
"app.notifications.showAll": "Show {count, plural, one {old notification} two {two old notifications} other {all # notifications}}",
@@ -265,4 +267,4 @@
265267
"generic.operationFailed": "The operation has failed",
266268
"generic.reset": "Reset",
267269
"generic.save": "Save"
268-
}
270+
}

src/pages/Home/Home.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Row, Col } from 'react-bootstrap';
77
import { Link } from 'react-router-dom';
88

99
import Page from '../../components/layout/Page';
10+
import PageContent from '../../components/layout/PageContent';
1011
import Icon, {
1112
GroupFocusIcon,
1213
HomeIcon,
@@ -88,6 +89,33 @@ class Home extends Component {
8889
links: { USER_URI, TERMS_URI, GROUPS_STUDENT_URI, GROUPS_TEACHER_URI, GROUPS_SUPERADMIN_URI },
8990
} = this.props;
9091

92+
if (!loggedInUser && !token) {
93+
return (
94+
<PageContent
95+
icon={<HomeIcon />}
96+
title={<FormattedMessage id="app.homepage.title" defaultMessage="SiS-CodEx Extension" />}
97+
windowTitle={<FormattedMessage id="app.homepage.title" defaultMessage="SiS-CodEx Extension" />}>
98+
<Callout variant="warning" className="my-3">
99+
<h4>
100+
<FormattedMessage id="app.homepage.userSessionExpired" defaultMessage="Your user session has expired" />
101+
</h4>
102+
<p>
103+
<FormattedMessage
104+
id="app.homepage.userSessionExpiredInfo"
105+
defaultMessage="You need to initialize a new session by re-entering this application from ReCodEx."
106+
/>
107+
</p>
108+
<p>
109+
<a href={getReturnUrl()}>
110+
<ReturnIcon gapRight />
111+
<FormattedMessage id="app.homepage.returnToReCodEx" defaultMessage="Return to ReCodEx..." />
112+
</a>
113+
</p>
114+
</Callout>
115+
</PageContent>
116+
);
117+
}
118+
91119
return (
92120
<Page
93121
resource={loggedInUser}

src/pages/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Home from './Home';
1010
import Terms from './Terms';
1111
import User from './User';
1212

13-
import { createLoginLinkWithRedirect, abortAllPendingRequests } from '../redux/helpers/api/tools.js';
13+
import { abortAllPendingRequests } from '../redux/helpers/api/tools.js';
1414
import { API_BASE, URL_PATH_PREFIX } from '../helpers/config.js';
1515
import withRouter from '../helpers/withRouter.js';
1616

@@ -83,7 +83,7 @@ const routesDescriptors = [
8383

8484
const getRedirect = (routeObj, urlPath, isLoggedIn) => {
8585
if (routeObj.auth !== undefined && routeObj.auth !== isLoggedIn) {
86-
return routeObj.auth ? createLoginLinkWithRedirect(urlPath) : getLinks().DASHBOARD_URI;
86+
return getLinks().HOME_URI;
8787
} else {
8888
return null;
8989
}

src/redux/helpers/api/tools.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import statusCode from 'statuscode';
22
import { flatten } from 'flat';
3-
import { Buffer } from 'buffer';
43

54
import { addNotification } from '../../modules/notifications.js';
65
import { newPendingFetchOperation, completedFetchOperation } from '../../modules/app.js';
76
import { isTokenValid, decode } from '../../helpers/token';
8-
import { API_BASE, URL_PATH_PREFIX } from '../../../helpers/config.js';
7+
import { API_BASE } from '../../../helpers/config.js';
98
import { actionTypes as authActionTypes } from '../../modules/authTypes.js';
109
import { canUseDOM } from '../../../helpers/common.js';
1110

@@ -134,15 +133,6 @@ export const logout = () => ({
134133
type: authActionTypes.LOGOUT,
135134
});
136135

137-
export const SESSION_EXPIRED_MESSAGE =
138-
'Your session expired and you were automatically logged out of the ReCodEx system.';
139-
export const LOGIN_URI_PREFIX = 'login';
140-
141-
export const createLoginLinkWithRedirect = redirLocation => {
142-
const redirBase64 = Buffer.from(redirLocation).toString('base64');
143-
return `${URL_PATH_PREFIX}/${LOGIN_URI_PREFIX}/${encodeURIComponent(redirBase64)}`;
144-
};
145-
146136
/**
147137
* Create a request and setup the processing of the response.
148138
* @param {Object} request The request settings and data
@@ -170,7 +160,6 @@ export const createApiCallPromise = (
170160
if (res.status === 401 && !isTokenValid(decode(accessToken)) && dispatch) {
171161
abortAllPendingRequests();
172162
dispatch(logout());
173-
dispatch(addNotification(SESSION_EXPIRED_MESSAGE, false));
174163
return Promise.reject(res);
175164
}
176165

@@ -184,7 +173,7 @@ export const createApiCallPromise = (
184173
};
185174

186175
/**
187-
* A specific error means that there is a problem with the Internet connectin or the server is down.
176+
* A specific error means that there is a problem with the Internet connecting or the server is down.
188177
* @param {Object} err The error description
189178
* @param {Function} dispatch
190179
*/

0 commit comments

Comments
 (0)