From: jloup Date: Sun, 13 May 2018 21:07:26 +0000 (+0200) Subject: Admin user token in frontend. X-Git-Tag: v0.0.14~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=6bf174a95ba0f71abf25397316fc101405381cdf;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git Admin user token in frontend. --- diff --git a/cmd/web/js/app.js b/cmd/web/js/app.js index 878878d..4756057 100644 --- a/cmd/web/js/app.js +++ b/cmd/web/js/app.js @@ -32,17 +32,22 @@ App.isUserSignedIn = function() { return cookies.hasItem('jwt'); }; +App.isUserAdmin = function() { + return cookies.hasItem('isAdmin') && cookies.getItem('isAdmin') === 'true'; +}; + App.getUserToken = function() { return cookies.getItem('jwt'); }; -App.onUserSignIn = function(token) { +App.onUserSignIn = function(token, isAdmin) { if (!token || token === '') { page('/signin'); return; } cookies.setItem('jwt', token, cookieExpire); + cookies.setItem('isAdmin', isAdmin, cookieExpire); page('/me'); }; @@ -56,13 +61,14 @@ App.onUserValidateOtp = function(token) { page('/me'); }; -App.onUserSignUp = function(token) { +App.onUserSignUp = function(token, isAdmin) { if (!token || token === '') { page('/signin'); return; } cookies.setItem('jwt', token, cookieExpire); + cookies.setItem('isAdmin', isAdmin, cookieExpire); page('/not_confirmed'); }; @@ -98,6 +104,7 @@ App.onUserNotAuthorized = function(httpCode, apiCode) { switch (apiCode) { case 'not_authorized': cookies.removeItem('jwt'); + cookies.removeItem('isAdmin'); page('/signin'); return false; case 'otp_not_setup': @@ -119,9 +126,9 @@ App.mount = function(app) { 'div', {className: 'container'}, [ - React.createElement(Header, {key: 'header', isLoggedIn: App.isUserSignedIn()}), + React.createElement(Header, {key: 'header', isLoggedIn: App.isUserSignedIn(), isAdmin: App.isUserAdmin()}), React.createElement(React.Fragment, {key: 'app'}, app), - React.createElement(Footer, {key: 'footer', isLoggedIn: App.isUserSignedIn()}) + React.createElement(Footer, {key: 'footer', isLoggedIn: App.isUserSignedIn(), isAdmin: App.isUserAdmin()}) ], ); diff --git a/cmd/web/js/header_footer.jsx b/cmd/web/js/header_footer.jsx index f11ed06..3e87c1e 100644 --- a/cmd/web/js/header_footer.jsx +++ b/cmd/web/js/header_footer.jsx @@ -12,6 +12,12 @@ class MyAccount extends React.Component { } } +class Admin extends React.Component { + render = () => { + return Admin; + } +} + class Logo extends React.Component { render() { return