@@ -46,6 +46,51 @@ import {
4646 LATEST_CS_VERSION
4747} from '@/store/mutation-types'
4848
49+ function setLoginCookies ( result ) {
50+ Cookies . set ( 'account' , result . account )
51+ Cookies . set ( 'domainid' , result . domainid )
52+ Cookies . set ( 'role' , result . type )
53+ Cookies . set ( 'timezone' , result . timezone )
54+ Cookies . set ( 'timezoneoffset' , result . timezoneoffset )
55+ Cookies . set ( 'userfullname' , result . firstname + ' ' + result . lastname )
56+ Cookies . set ( 'userid' , result . userid )
57+ Cookies . set ( 'username' , result . username )
58+ }
59+
60+ function processLoginResponse ( commit , response ) {
61+ const result = response . loginresponse || { }
62+ setLoginCookies ( result )
63+ vueProps . $localStorage . set ( ACCESS_TOKEN , result . sessionkey , 24 * 60 * 60 * 1000 )
64+ commit ( 'SET_TOKEN' , result . sessionkey )
65+ commit ( 'SET_TIMEZONE_OFFSET' , result . timezoneoffset )
66+
67+ const cachedUseBrowserTimezone = vueProps . $localStorage . get ( USE_BROWSER_TIMEZONE , false )
68+ commit ( 'SET_USE_BROWSER_TIMEZONE' , cachedUseBrowserTimezone )
69+ const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
70+ commit ( 'SET_DARK_MODE' , darkMode )
71+ const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
72+ commit ( 'SET_CUSTOM_COLUMNS' , cachedCustomColumns )
73+
74+ commit ( 'SET_APIS' , { } )
75+ commit ( 'SET_NAME' , '' )
76+ commit ( 'SET_AVATAR' , '' )
77+ commit ( 'SET_INFO' , { } )
78+ commit ( 'SET_PROJECT' , { } )
79+ commit ( 'SET_HEADER_NOTICES' , [ ] )
80+ commit ( 'SET_FEATURES' , { } )
81+ commit ( 'SET_LDAP' , { } )
82+ commit ( 'SET_CLOUDIAN' , { } )
83+ commit ( 'SET_DOMAIN_STORE' , { } )
84+ commit ( 'SET_LOGOUT_FLAG' , false )
85+ commit ( 'SET_2FA_ENABLED' , ( result . is2faenabled === 'true' ) )
86+ commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
87+ commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
88+ commit ( 'SET_LOGIN_FLAG' , false )
89+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
90+ commit ( 'SET_LATEST_VERSION' , latestVersion )
91+ notification . destroy ( )
92+ }
93+
4994const user = {
5095 state : {
5196 token : '' ,
@@ -192,45 +237,7 @@ const user = {
192237 Login ( { commit } , userInfo ) {
193238 return new Promise ( ( resolve , reject ) => {
194239 login ( userInfo ) . then ( response => {
195- const result = response . loginresponse || { }
196- Cookies . set ( 'account' , result . account , { expires : 1 } )
197- Cookies . set ( 'domainid' , result . domainid , { expires : 1 } )
198- Cookies . set ( 'role' , result . type , { expires : 1 } )
199- Cookies . set ( 'timezone' , result . timezone , { expires : 1 } )
200- Cookies . set ( 'timezoneoffset' , result . timezoneoffset , { expires : 1 } )
201- Cookies . set ( 'userfullname' , result . firstname + ' ' + result . lastname , { expires : 1 } )
202- Cookies . set ( 'userid' , result . userid , { expires : 1 } )
203- Cookies . set ( 'username' , result . username , { expires : 1 } )
204- vueProps . $localStorage . set ( ACCESS_TOKEN , result . sessionkey , 24 * 60 * 60 * 1000 )
205- commit ( 'SET_TOKEN' , result . sessionkey )
206- commit ( 'SET_TIMEZONE_OFFSET' , result . timezoneoffset )
207-
208- const cachedUseBrowserTimezone = vueProps . $localStorage . get ( USE_BROWSER_TIMEZONE , false )
209- commit ( 'SET_USE_BROWSER_TIMEZONE' , cachedUseBrowserTimezone )
210- const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
211- commit ( 'SET_DARK_MODE' , darkMode )
212- const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
213- commit ( 'SET_CUSTOM_COLUMNS' , cachedCustomColumns )
214-
215- commit ( 'SET_APIS' , { } )
216- commit ( 'SET_NAME' , '' )
217- commit ( 'SET_AVATAR' , '' )
218- commit ( 'SET_INFO' , { } )
219- commit ( 'SET_PROJECT' , { } )
220- commit ( 'SET_HEADER_NOTICES' , [ ] )
221- commit ( 'SET_FEATURES' , { } )
222- commit ( 'SET_LDAP' , { } )
223- commit ( 'SET_CLOUDIAN' , { } )
224- commit ( 'SET_DOMAIN_STORE' , { } )
225- commit ( 'SET_LOGOUT_FLAG' , false )
226- commit ( 'SET_2FA_ENABLED' , ( result . is2faenabled === 'true' ) )
227- commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
228- commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
229- commit ( 'SET_LOGIN_FLAG' , false )
230- const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
231- commit ( 'SET_LATEST_VERSION' , latestVersion )
232- notification . destroy ( )
233-
240+ processLoginResponse ( commit , response )
234241 resolve ( )
235242 } ) . catch ( error => {
236243 reject ( error )
@@ -241,45 +248,7 @@ const user = {
241248 OauthLogin ( { commit } , userInfo ) {
242249 return new Promise ( ( resolve , reject ) => {
243250 oauthlogin ( userInfo ) . then ( response => {
244- const result = response . loginresponse || { }
245- Cookies . set ( 'account' , result . account , { expires : 1 } )
246- Cookies . set ( 'domainid' , result . domainid , { expires : 1 } )
247- Cookies . set ( 'role' , result . type , { expires : 1 } )
248- Cookies . set ( 'timezone' , result . timezone , { expires : 1 } )
249- Cookies . set ( 'timezoneoffset' , result . timezoneoffset , { expires : 1 } )
250- Cookies . set ( 'userfullname' , result . firstname + ' ' + result . lastname , { expires : 1 } )
251- Cookies . set ( 'userid' , result . userid , { expires : 1 } )
252- Cookies . set ( 'username' , result . username , { expires : 1 } )
253- vueProps . $localStorage . set ( ACCESS_TOKEN , result . sessionkey , 24 * 60 * 60 * 1000 )
254- commit ( 'SET_TOKEN' , result . sessionkey )
255- commit ( 'SET_TIMEZONE_OFFSET' , result . timezoneoffset )
256-
257- const cachedUseBrowserTimezone = vueProps . $localStorage . get ( USE_BROWSER_TIMEZONE , false )
258- commit ( 'SET_USE_BROWSER_TIMEZONE' , cachedUseBrowserTimezone )
259- const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
260- commit ( 'SET_DARK_MODE' , darkMode )
261- const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
262- commit ( 'SET_CUSTOM_COLUMNS' , cachedCustomColumns )
263-
264- commit ( 'SET_APIS' , { } )
265- commit ( 'SET_NAME' , '' )
266- commit ( 'SET_AVATAR' , '' )
267- commit ( 'SET_INFO' , { } )
268- commit ( 'SET_PROJECT' , { } )
269- commit ( 'SET_HEADER_NOTICES' , [ ] )
270- commit ( 'SET_FEATURES' , { } )
271- commit ( 'SET_LDAP' , { } )
272- commit ( 'SET_CLOUDIAN' , { } )
273- commit ( 'SET_DOMAIN_STORE' , { } )
274- commit ( 'SET_LOGOUT_FLAG' , false )
275- commit ( 'SET_2FA_ENABLED' , ( result . is2faenabled === 'true' ) )
276- commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
277- commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
278- commit ( 'SET_LOGIN_FLAG' , false )
279- const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
280- commit ( 'SET_LATEST_VERSION' , latestVersion )
281- notification . destroy ( )
282-
251+ processLoginResponse ( commit , response )
283252 resolve ( )
284253 } ) . catch ( error => {
285254 reject ( error )
@@ -304,6 +273,11 @@ const user = {
304273 commit ( 'SET_DARK_MODE' , darkMode )
305274 commit ( 'SET_LATEST_VERSION' , latestVersion )
306275 if ( hasAuth ) {
276+ if ( ! Cookies . get ( 'userid' ) ) {
277+ reject ( new Error ( 'Identity session expired' ) )
278+ return
279+ }
280+
307281 console . log ( 'Login detected, using cached APIs' )
308282 commit ( 'SET_ZONES' , cachedZones )
309283 commit ( 'SET_SHOW_SECURITY_GROUPS' , cachedShowSecurityGroups )
@@ -433,6 +407,7 @@ const user = {
433407 } )
434408 } ) . catch ( error => {
435409 console . error ( error )
410+ throw error
436411 } )
437412 } ,
438413
0 commit comments