Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
web-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
web-et-numerique
web-et-numerique-internet
data.grandlyon.com
web-portal
components
custom-apps
web-app
Commits
1bcc40ac
Commit
1bcc40ac
authored
5 years ago
by
FORESTIER Fabien
Browse files
Options
Downloads
Patches
Plain Diff
Do not use localStorage to store userInfo but call auth service on app init
parent
673d2df5
No related branches found
No related tags found
1 merge request
!49
Version 2.3.1
Pipeline
#1769
passed
5 years ago
Stage: build
Stage: deploy
Stage: post-deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/app.module.ts
+7
-2
7 additions, 2 deletions
src/app/app.module.ts
src/app/user/services/user.service.ts
+6
-16
6 additions, 16 deletions
src/app/user/services/user.service.ts
with
13 additions
and
18 deletions
src/app/app.module.ts
+
7
−
2
View file @
1bcc40ac
...
@@ -16,8 +16,13 @@ import { AppConfigService } from './core/services';
...
@@ -16,8 +16,13 @@ import { AppConfigService } from './core/services';
export
function
initUserService
(
authService
:
UserService
)
{
export
function
initUserService
(
authService
:
UserService
)
{
return
():
Promise
<
any
>
=>
{
return
():
Promise
<
any
>
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
authService
.
initializeService
();
authService
.
initializeService
().
subscribe
(
resolve
();
()
=>
{
resolve
();
},
()
=>
{
resolve
();
});
});
});
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
src/app/user/services/user.service.ts
+
6
−
16
View file @
1bcc40ac
...
@@ -3,7 +3,6 @@ import { HttpClient } from '@angular/common/http';
...
@@ -3,7 +3,6 @@ import { HttpClient } from '@angular/common/http';
import
{
Observable
,
Subject
}
from
'
rxjs
'
;
import
{
Observable
,
Subject
}
from
'
rxjs
'
;
import
{
IUserInfo
,
PasswordUpdateForm
,
User
,
ILoginResponse
,
LegacyAccount
,
IPasswordForgottenForm
}
from
'
../models
'
;
import
{
IUserInfo
,
PasswordUpdateForm
,
User
,
ILoginResponse
,
LegacyAccount
,
IPasswordForgottenForm
}
from
'
../models
'
;
import
{
map
,
mergeMap
,
tap
}
from
'
rxjs/operators
'
;
import
{
map
,
mergeMap
,
tap
}
from
'
rxjs/operators
'
;
import
*
as
JwtDecode
from
'
jwt-decode
'
;
import
*
as
NodeRSA
from
'
node-rsa
'
;
import
*
as
NodeRSA
from
'
node-rsa
'
;
import
{
APP_CONFIG
}
from
'
../../core/services/app-config.service
'
;
import
{
APP_CONFIG
}
from
'
../../core/services/app-config.service
'
;
...
@@ -20,16 +19,19 @@ export class UserService {
...
@@ -20,16 +19,19 @@ export class UserService {
}
}
initializeService
()
{
initializeService
()
{
this
.
setUserInfo
();
return
this
.
getUserInfo
().
pipe
(
map
((
userInfo
)
=>
{
this
.
_user
=
new
User
(
userInfo
);
}),
);
}
}
// Function and helpers allowing the management of the user session (jwt), info...
// Function and helpers allowing the management of the user session (jwt), info...
setSession
(
authResult
):
boolean
{
setSession
(
authResult
):
boolean
{
let
success
=
false
;
let
success
=
false
;
if
(
authResult
&&
authResult
.
userInfo
&&
authResult
.
xsrfToken
)
{
if
(
authResult
&&
authResult
.
userInfo
&&
authResult
.
xsrfToken
)
{
localStorage
.
setItem
(
'
userInfo
'
,
JSON
.
stringify
(
authResult
.
userInfo
));
localStorage
.
setItem
(
'
xsrfToken
'
,
authResult
.
xsrfToken
);
localStorage
.
setItem
(
'
xsrfToken
'
,
authResult
.
xsrfToken
);
this
.
setU
serInfo
(
);
this
.
_user
=
new
User
(
authResult
.
u
serInfo
);
success
=
true
;
success
=
true
;
this
.
_userStatusChangedSubject
.
next
(
true
);
this
.
_userStatusChangedSubject
.
next
(
true
);
}
else
{
}
else
{
...
@@ -39,19 +41,7 @@ export class UserService {
...
@@ -39,19 +41,7 @@ export class UserService {
return
success
;
return
success
;
}
}
setUserInfo
()
{
const
userInfo
=
JSON
.
parse
(
localStorage
.
getItem
(
'
userInfo
'
));
if
(
userInfo
)
{
if
(
userInfo
.
exp
>
Date
.
now
())
{
this
.
_user
=
new
User
(
userInfo
);
}
else
{
this
.
resetAuth
();
}
}
}
resetAuth
()
{
resetAuth
()
{
localStorage
.
removeItem
(
'
userInfo
'
);
localStorage
.
removeItem
(
'
xsrfToken
'
);
localStorage
.
removeItem
(
'
xsrfToken
'
);
this
.
logout
().
subscribe
();
this
.
logout
().
subscribe
();
this
.
_user
=
null
;
this
.
_user
=
null
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment