Skip to content
Snippets Groups Projects
Commit 25c4d437 authored by Sandro Lutz's avatar Sandro Lutz Committed by Hermann
Browse files

Implement proper logout

parent 988ecae3
No related branches found
No related tags found
No related merge requests found
...@@ -11,9 +11,14 @@ const APISession = { ...@@ -11,9 +11,14 @@ const APISession = {
token: '', token: '',
// user admins are a very special case as the permissions on the resource can only // user admins are a very special case as the permissions on the resource can only
// be seen by requesting users and check whether you see their membership // be seen by requesting users and check whether you see their membership
isUserAdmin: false isUserAdmin: false,
}; };
const amivapi = axios.create({
baseURL: apiUrl,
headers: { 'Content-Type': 'application/json' },
});
// OAuth Handler // OAuth Handler
const oauth = new ClientOAuth2({ const oauth = new ClientOAuth2({
clientId: oAuthID, clientId: oAuthID,
...@@ -21,18 +26,13 @@ const oauth = new ClientOAuth2({ ...@@ -21,18 +26,13 @@ const oauth = new ClientOAuth2({
redirectUri: `${ownUrl}/oauthcallback`, redirectUri: `${ownUrl}/oauthcallback`,
}); });
export function resetSession() { function resetSession() {
APISession.authenticated = false; APISession.authenticated = false;
APISession.token = ''; APISession.token = '';
localStorage.remove('token'); localStorage.remove('token');
window.location.replace(oauth.token.getUri()); window.location.replace(oauth.token.getUri());
} }
const amivapi = axios.create({
baseURL: apiUrl,
headers: { 'Content-Type': 'application/json' },
});
function checkToken(token) { function checkToken(token) {
// check if a token is still valid // check if a token is still valid
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
...@@ -88,6 +88,26 @@ export function getSession() { ...@@ -88,6 +88,26 @@ export function getSession() {
}); });
} }
export function deleteSession() {
return new Promise((resolve, reject) => {
getSession().then((api) => {
api.get(`sessions/${APISession.token}`).then((response) => {
if (response.status === 200) {
api.delete(
`sessions/${response.data._id}`,
{ headers: { 'If-Match': response.data._etag } },
).then((deleteResponse) => {
if (deleteResponse.status === 204) {
resetSession();
resolve(deleteResponse.data);
} else reject();
}).catch(reject);
} else reject();
}).catch(reject);
});
});
}
export class ResourceHandler { export class ResourceHandler {
/* Handler to get and manipulate resource items /* Handler to get and manipulate resource items
* *
......
...@@ -42,5 +42,3 @@ m.route(root, '/events', { ...@@ -42,5 +42,3 @@ m.route(root, '/events', {
'/newjoboffer': layoutWith(JobItem), '/newjoboffer': layoutWith(JobItem),
'/joboffers/:id': layoutWith(JobItem), '/joboffers/:id': layoutWith(JobItem),
}); });
m.route.prefix('');
...@@ -9,11 +9,12 @@ import { ...@@ -9,11 +9,12 @@ import {
ToolbarTitle, ToolbarTitle,
Dialog, Dialog,
SVG, SVG,
Button,
IconButton, IconButton,
} from 'polythene-mithril'; } from 'polythene-mithril';
import { styler } from 'polythene-core-css'; import { styler } from 'polythene-core-css';
import { icons } from './views/elements'; import { icons } from './views/elements';
import { resetSession } from './auth'; import { deleteSession } from './auth';
import { colors } from './style'; import { colors } from './style';
const layoutStyle = [ const layoutStyle = [
...@@ -109,7 +110,11 @@ export class Layout { ...@@ -109,7 +110,11 @@ export class Layout {
style: { color: '#ffffff' }, style: { color: '#ffffff' },
})), })),
m(ToolbarTitle, { text: 'AMIV Admintools' }), m(ToolbarTitle, { text: 'AMIV Admintools' }),
m('a', { onclick: resetSession }, 'Logout'), m(Button, {
className: 'red-row-button',
label: 'logout',
events: { onclick: deleteSession },
}),
]), ]),
m( m(
'div.mdc-typography.wrapper-sidebar', 'div.mdc-typography.wrapper-sidebar',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment