diff options
Diffstat (limited to 'cmd/web/js/app.js')
-rw-r--r-- | cmd/web/js/app.js | 15 |
1 files changed, 11 insertions, 4 deletions
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() { | |||
32 | return cookies.hasItem('jwt'); | 32 | return cookies.hasItem('jwt'); |
33 | }; | 33 | }; |
34 | 34 | ||
35 | App.isUserAdmin = function() { | ||
36 | return cookies.hasItem('isAdmin') && cookies.getItem('isAdmin') === 'true'; | ||
37 | }; | ||
38 | |||
35 | App.getUserToken = function() { | 39 | App.getUserToken = function() { |
36 | return cookies.getItem('jwt'); | 40 | return cookies.getItem('jwt'); |
37 | }; | 41 | }; |
38 | 42 | ||
39 | App.onUserSignIn = function(token) { | 43 | App.onUserSignIn = function(token, isAdmin) { |
40 | if (!token || token === '') { | 44 | if (!token || token === '') { |
41 | page('/signin'); | 45 | page('/signin'); |
42 | return; | 46 | return; |
43 | } | 47 | } |
44 | 48 | ||
45 | cookies.setItem('jwt', token, cookieExpire); | 49 | cookies.setItem('jwt', token, cookieExpire); |
50 | cookies.setItem('isAdmin', isAdmin, cookieExpire); | ||
46 | page('/me'); | 51 | page('/me'); |
47 | }; | 52 | }; |
48 | 53 | ||
@@ -56,13 +61,14 @@ App.onUserValidateOtp = function(token) { | |||
56 | page('/me'); | 61 | page('/me'); |
57 | }; | 62 | }; |
58 | 63 | ||
59 | App.onUserSignUp = function(token) { | 64 | App.onUserSignUp = function(token, isAdmin) { |
60 | if (!token || token === '') { | 65 | if (!token || token === '') { |
61 | page('/signin'); | 66 | page('/signin'); |
62 | return; | 67 | return; |
63 | } | 68 | } |
64 | 69 | ||
65 | cookies.setItem('jwt', token, cookieExpire); | 70 | cookies.setItem('jwt', token, cookieExpire); |
71 | cookies.setItem('isAdmin', isAdmin, cookieExpire); | ||
66 | page('/not_confirmed'); | 72 | page('/not_confirmed'); |
67 | }; | 73 | }; |
68 | 74 | ||
@@ -98,6 +104,7 @@ App.onUserNotAuthorized = function(httpCode, apiCode) { | |||
98 | switch (apiCode) { | 104 | switch (apiCode) { |
99 | case 'not_authorized': | 105 | case 'not_authorized': |
100 | cookies.removeItem('jwt'); | 106 | cookies.removeItem('jwt'); |
107 | cookies.removeItem('isAdmin'); | ||
101 | page('/signin'); | 108 | page('/signin'); |
102 | return false; | 109 | return false; |
103 | case 'otp_not_setup': | 110 | case 'otp_not_setup': |
@@ -119,9 +126,9 @@ App.mount = function(app) { | |||
119 | 'div', | 126 | 'div', |
120 | {className: 'container'}, | 127 | {className: 'container'}, |
121 | [ | 128 | [ |
122 | React.createElement(Header, {key: 'header', isLoggedIn: App.isUserSignedIn()}), | 129 | React.createElement(Header, {key: 'header', isLoggedIn: App.isUserSignedIn(), isAdmin: App.isUserAdmin()}), |
123 | React.createElement(React.Fragment, {key: 'app'}, app), | 130 | React.createElement(React.Fragment, {key: 'app'}, app), |
124 | React.createElement(Footer, {key: 'footer', isLoggedIn: App.isUserSignedIn()}) | 131 | React.createElement(Footer, {key: 'footer', isLoggedIn: App.isUserSignedIn(), isAdmin: App.isUserAdmin()}) |
125 | ], | 132 | ], |
126 | ); | 133 | ); |
127 | 134 | ||