diff options
Diffstat (limited to 'src/stores/UserStore.js')
-rw-r--r-- | src/stores/UserStore.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 7addb5760..31555dd5c 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -129,10 +129,6 @@ export default class UserStore extends Store { | |||
129 | return Boolean(localStorage.getItem('authToken')); | 129 | return Boolean(localStorage.getItem('authToken')); |
130 | } | 130 | } |
131 | 131 | ||
132 | // @computed get isTokenValid() { | ||
133 | // return this.authToken !== null && moment(this.tokenExpiry).isAfter(moment()); | ||
134 | // } | ||
135 | |||
136 | @computed get isTokenExpired() { | 132 | @computed get isTokenExpired() { |
137 | if (!this.authToken) return false; | 133 | if (!this.authToken) return false; |
138 | 134 | ||
@@ -146,6 +142,10 @@ export default class UserStore extends Store { | |||
146 | return this.getUserInfoRequest.execute().result || {}; | 142 | return this.getUserInfoRequest.execute().result || {}; |
147 | } | 143 | } |
148 | 144 | ||
145 | @computed get isPremium() { | ||
146 | return !!this.data.isPremium; | ||
147 | } | ||
148 | |||
149 | @computed get legacyServices() { | 149 | @computed get legacyServices() { |
150 | return this.getLegacyServicesRequest.execute() || {}; | 150 | return this.getLegacyServicesRequest.execute() || {}; |
151 | } | 151 | } |
@@ -160,6 +160,14 @@ export default class UserStore extends Store { | |||
160 | gaEvent('User', 'login'); | 160 | gaEvent('User', 'login'); |
161 | } | 161 | } |
162 | 162 | ||
163 | @action _tokenLogin(authToken) { | ||
164 | this._setUserData(authToken); | ||
165 | |||
166 | this.stores.router.push('/'); | ||
167 | |||
168 | gaEvent('User', 'tokenLogin'); | ||
169 | } | ||
170 | |||
163 | @action async _signup({ | 171 | @action async _signup({ |
164 | firstname, lastname, email, password, accountType, company, | 172 | firstname, lastname, email, password, accountType, company, |
165 | }) { | 173 | }) { |
@@ -170,6 +178,7 @@ export default class UserStore extends Store { | |||
170 | password, | 178 | password, |
171 | accountType, | 179 | accountType, |
172 | company, | 180 | company, |
181 | locale: this.stores.app.locale, | ||
173 | }); | 182 | }); |
174 | 183 | ||
175 | this.hasCompletedSignup = false; | 184 | this.hasCompletedSignup = false; |
@@ -206,6 +215,8 @@ export default class UserStore extends Store { | |||
206 | } | 215 | } |
207 | 216 | ||
208 | @action async _update({ userData }) { | 217 | @action async _update({ userData }) { |
218 | if (!this.isLoggedIn) return; | ||
219 | |||
209 | const response = await this.updateUserInfoRequest.execute(userData)._promise; | 220 | const response = await this.updateUserInfoRequest.execute(userData)._promise; |
210 | 221 | ||
211 | this.getUserInfoRequest.patch(() => response.data); | 222 | this.getUserInfoRequest.patch(() => response.data); |
@@ -222,6 +233,7 @@ export default class UserStore extends Store { | |||
222 | // workaround mobx issue | 233 | // workaround mobx issue |
223 | localStorage.removeItem('authToken'); | 234 | localStorage.removeItem('authToken'); |
224 | window.localStorage.removeItem('authToken'); | 235 | window.localStorage.removeItem('authToken'); |
236 | |||
225 | this.getUserInfoRequest.invalidate().reset(); | 237 | this.getUserInfoRequest.invalidate().reset(); |
226 | this.authToken = null; | 238 | this.authToken = null; |
227 | } | 239 | } |
@@ -262,6 +274,18 @@ export default class UserStore extends Store { | |||
262 | const { router } = this.stores; | 274 | const { router } = this.stores; |
263 | const currentRoute = router.location.pathname; | 275 | const currentRoute = router.location.pathname; |
264 | if (!this.isLoggedIn | 276 | if (!this.isLoggedIn |
277 | && currentRoute.includes('token=')) { | ||
278 | router.push(this.WELCOME_ROUTE); | ||
279 | const token = currentRoute.split('=')[1]; | ||
280 | |||
281 | const data = this._parseToken(token); | ||
282 | if (data) { | ||
283 | // Give this some time to sink | ||
284 | setTimeout(() => { | ||
285 | this._tokenLogin(token); | ||
286 | }, 1000); | ||
287 | } | ||
288 | } else if (!this.isLoggedIn | ||
265 | && !currentRoute.includes(this.BASE_ROUTE)) { | 289 | && !currentRoute.includes(this.BASE_ROUTE)) { |
266 | router.push(this.WELCOME_ROUTE); | 290 | router.push(this.WELCOME_ROUTE); |
267 | } else if (this.isLoggedIn | 291 | } else if (this.isLoggedIn |