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');
};
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');
};
switch (apiCode) {
case 'not_authorized':
cookies.removeItem('jwt');
+ cookies.removeItem('isAdmin');
page('/signin');
return false;
case 'otp_not_setup':
'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()})
],
);
}
}
+class Admin extends React.Component {
+ render = () => {
+ return <a href="/admin"><u>Admin</u></a>;
+ }
+}
+
class Logo extends React.Component {
render() {
return <div id="logo" className="w-100 h-100 align-self-center">
elements = [];
}
+ if (this.props.isAdmin === true) {
+ elements = elements.concat(<Admin />);
+ }
+
if (this.props.isLoggedIn === true) {
elements = elements.concat(<MyAccount />);
elements = elements.concat(<Signout />);
elements = [];
}
+ if (this.props.isAdmin === true) {
+ elements = elements.concat(<Admin />);
+ }
+
if (this.props.isLoggedIn === true) {
elements = elements.concat(<MyAccount />);
elements = elements.concat(<Signout />);