From 6bf174a95ba0f71abf25397316fc101405381cdf Mon Sep 17 00:00:00 2001 From: jloup Date: Sun, 13 May 2018 23:07:26 +0200 Subject: Admin user token in frontend. --- cmd/web/js/app.js | 15 +++++++++++---- cmd/web/js/header_footer.jsx | 14 ++++++++++++++ cmd/web/js/signin.jsx | 2 +- cmd/web/js/signup.jsx | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) (limited to 'cmd/web') 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