Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mySkill-x
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
angular
mySkill-x
Commits
534af721
Commit
534af721
authored
Apr 17, 2025
by
Ooh-Ao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
แก้ user
parent
b3ebfbc9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
42 deletions
+82
-42
login-page.component.ts
src/app/authentication/login-page/login-page.component.ts
+18
-3
sidebar.component.ts
src/app/shared/components/sidebar/sidebar.component.ts
+13
-11
employee.service.ts
src/app/shared/services/employee.service.ts
+12
-13
http-request.interceptor.ts
src/app/shared/services/http-request.interceptor.ts
+2
-1
token.service.ts
src/app/shared/services/token.service.ts
+36
-13
environment.ts
src/environments/environment.ts
+1
-1
No files found.
src/app/authentication/login-page/login-page.component.ts
View file @
534af721
...
@@ -4,6 +4,7 @@ import { Router } from '@angular/router';
...
@@ -4,6 +4,7 @@ import { Router } from '@angular/router';
import
{
AuthService
}
from
'src/app/shared/services/auth.service'
;
import
{
AuthService
}
from
'src/app/shared/services/auth.service'
;
import
{
DOCUMENT
}
from
'@angular/common'
;
import
{
DOCUMENT
}
from
'@angular/common'
;
import
{
TokenService
}
from
'src/app/shared/services/token.service'
;
import
{
TokenService
}
from
'src/app/shared/services/token.service'
;
import
{
EmployeeService
}
from
'src/app/shared/services/employee.service'
;
@
Component
({
@
Component
({
selector
:
'app-login-page'
,
selector
:
'app-login-page'
,
...
@@ -21,7 +22,8 @@ export class LoginPageComponent {
...
@@ -21,7 +22,8 @@ export class LoginPageComponent {
private
renderer
:
Renderer2
,
private
renderer
:
Renderer2
,
private
formBuilder
:
FormBuilder
,
private
formBuilder
:
FormBuilder
,
private
router
:
Router
,
private
router
:
Router
,
private
authservice
:
AuthService
,
private
tokenService
:
TokenService
)
{
private
authservice
:
AuthService
,
private
tokenService
:
TokenService
,
private
employeeService
:
EmployeeService
)
{
const
bodyElement
=
this
.
renderer
.
selectRootElement
(
'body'
,
true
);
const
bodyElement
=
this
.
renderer
.
selectRootElement
(
'body'
,
true
);
this
.
renderer
.
setAttribute
(
bodyElement
,
'class'
,
'cover1 justify-center'
);
this
.
renderer
.
setAttribute
(
bodyElement
,
'class'
,
'cover1 justify-center'
);
...
@@ -109,8 +111,12 @@ export class LoginPageComponent {
...
@@ -109,8 +111,12 @@ export class LoginPageComponent {
this
.
errorUser
=
false
this
.
errorUser
=
false
this
.
tokenService
.
saveToken
(
response
.
accessToken
);
this
.
tokenService
.
saveToken
(
response
.
accessToken
);
this
.
tokenService
.
saveRefreshToken
(
response
.
refreshToken
);
this
.
tokenService
.
saveRefreshToken
(
response
.
refreshToken
);
this
.
tokenService
.
saveUser
(
response
);
this
.
tokenService
.
saveUser
(
this
.
decodeJWT
(
response
.
accessToken
))
this
.
router
.
navigate
([
'/self-evaluation'
]);
this
.
employeeService
.
getProfile
().
subscribe
(
result
=>
{
this
.
tokenService
.
saveUserData
(
result
)
this
.
router
.
navigate
([
'/self-evaluation'
]);
})
}
else
{
}
else
{
this
.
errorUser
=
true
this
.
errorUser
=
true
}
}
...
@@ -125,6 +131,15 @@ export class LoginPageComponent {
...
@@ -125,6 +131,15 @@ export class LoginPageComponent {
}
}
}
}
decodeJWT
(
token
:
string
)
{
let
base64Url
=
token
.
split
(
'.'
)[
1
];
// ดึงส่วนที่เป็น Payload
let
base64
=
base64Url
.
replace
(
'-'
,
'+'
).
replace
(
'_'
,
'/'
);
// แก้ไข base64 ให้ถูกต้อง
let
jsonPayload
=
decodeURIComponent
(
atob
(
base64
).
split
(
''
).
map
(
function
(
c
)
{
return
'%'
+
(
'00'
+
c
.
charCodeAt
(
0
).
toString
(
16
)).
slice
(
-
2
);
}).
join
(
''
));
return
JSON
.
parse
(
jsonPayload
);
}
public
togglePassword
()
{
public
togglePassword
()
{
this
.
showPassword
=
!
this
.
showPassword
;
this
.
showPassword
=
!
this
.
showPassword
;
}
}
...
...
src/app/shared/components/sidebar/sidebar.component.ts
View file @
534af721
...
@@ -6,6 +6,7 @@ import { NavigationEnd, Router } from '@angular/router';
...
@@ -6,6 +6,7 @@ import { NavigationEnd, Router } from '@angular/router';
import
{
checkHoriMenu
,
switcherArrowFn
}
from
'./sidebar'
;
import
{
checkHoriMenu
,
switcherArrowFn
}
from
'./sidebar'
;
import
{
ConfigPermissionService
}
from
'../../services/config-permission.service'
;
import
{
ConfigPermissionService
}
from
'../../services/config-permission.service'
;
import
{
ConfigPermissionModel
,
MenuBodyModel
,
MyConfigPermissionModel
}
from
'../../model/config-permission.model'
;
import
{
ConfigPermissionModel
,
MenuBodyModel
,
MyConfigPermissionModel
}
from
'../../model/config-permission.model'
;
import
{
TokenService
}
from
'../../services/token.service'
;
@
Component
({
@
Component
({
selector
:
'app-sidebar'
,
selector
:
'app-sidebar'
,
...
@@ -62,7 +63,7 @@ export class SidebarComponent {
...
@@ -62,7 +63,7 @@ export class SidebarComponent {
public
menuItems
:
Menu
[]
=
[];
public
menuItems
:
Menu
[]
=
[];
public
menuitemsSubscribe$
!
:
Subscription
;
public
menuitemsSubscribe$
!
:
Subscription
;
user_level
=
""
user_level
?
=
""
configPermission
:
{
loading
:
boolean
,
data
:
ConfigPermissionModel
}
=
{
loading
:
false
,
data
:
new
MyConfigPermissionModel
()
}
configPermission
:
{
loading
:
boolean
,
data
:
ConfigPermissionModel
}
=
{
loading
:
false
,
data
:
new
MyConfigPermissionModel
()
}
constructor
(
constructor
(
...
@@ -73,9 +74,10 @@ export class SidebarComponent {
...
@@ -73,9 +74,10 @@ export class SidebarComponent {
private
elementRef
:
ElementRef
,
private
elementRef
:
ElementRef
,
private
configPermissionService
:
ConfigPermissionService
,
private
configPermissionService
:
ConfigPermissionService
,
private
cdr
:
ChangeDetectorRef
,
private
cdr
:
ChangeDetectorRef
,
private
tokenService
:
TokenService
)
{
)
{
this
.
screenWidth
=
window
.
innerWidth
;
this
.
screenWidth
=
window
.
innerWidth
;
this
.
user_level
=
this
.
decodeJWT
(
sessionStorage
.
getItem
(
"accessToken"
)
||
''
)
.
user_level
this
.
user_level
=
this
.
tokenService
.
getUser
()?
.
user_level
}
}
ngOnInit
()
{
ngOnInit
()
{
...
@@ -111,7 +113,7 @@ export class SidebarComponent {
...
@@ -111,7 +113,7 @@ export class SidebarComponent {
}
}
getConfigPermissionByUserLevel
()
{
getConfigPermissionByUserLevel
()
{
this
.
configPermission
.
loading
=
true
this
.
configPermission
.
loading
=
true
this
.
configPermissionService
.
getByUserLevel
(
this
.
user_level
).
subscribe
({
this
.
configPermissionService
.
getByUserLevel
(
this
.
user_level
!
).
subscribe
({
next
:
response
=>
{
next
:
response
=>
{
this
.
configPermission
.
data
=
new
MyConfigPermissionModel
(
response
)
this
.
configPermission
.
data
=
new
MyConfigPermissionModel
(
response
)
this
.
menuItems
.
forEach
(
x
=>
{
this
.
menuItems
.
forEach
(
x
=>
{
...
@@ -161,14 +163,14 @@ export class SidebarComponent {
...
@@ -161,14 +163,14 @@ export class SidebarComponent {
})
})
}
}
decodeJWT
(
token
:
string
)
{
//
decodeJWT(token: string) {
let
base64Url
=
token
.
split
(
'.'
)[
1
];
// ดึงส่วนที่เป็น Payload
//
let base64Url = token.split('.')[1]; // ดึงส่วนที่เป็น Payload
let
base64
=
base64Url
.
replace
(
'-'
,
'+'
).
replace
(
'_'
,
'/'
);
// แก้ไข base64 ให้ถูกต้อง
//
let base64 = base64Url.replace('-', '+').replace('_', '/'); // แก้ไข base64 ให้ถูกต้อง
let
jsonPayload
=
decodeURIComponent
(
atob
(
base64
).
split
(
''
).
map
(
function
(
c
)
{
//
let jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
return
'%'
+
(
'00'
+
c
.
charCodeAt
(
0
).
toString
(
16
)).
slice
(
-
2
);
//
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).
join
(
''
));
//
}).join(''));
return
JSON
.
parse
(
jsonPayload
);
//
return JSON.parse(jsonPayload);
}
//
}
...
...
src/app/shared/services/employee.service.ts
View file @
534af721
...
@@ -9,18 +9,17 @@ import { PageModel } from '../model/page.model';
...
@@ -9,18 +9,17 @@ import { PageModel } from '../model/page.model';
providedIn
:
'root'
providedIn
:
'root'
})
})
export
class
EmployeeService
{
export
class
EmployeeService
{
api
=
"/employee"
baseUrlapi
=
"/employee"
urlApi
=
environment
.
baseUrl
+
this
.
api
constructor
(
private
http
:
HttpClient
)
{
constructor
(
private
http
:
HttpClient
)
{
}
}
getPageList
(
page
:
string
,
size
:
string
):
Observable
<
PageModel
>
{
getPageList
(
page
:
string
,
size
:
string
):
Observable
<
PageModel
>
{
return
this
.
http
.
get
<
PageModel
>
(
this
.
urlA
pi
+
"/profile/create-short?page="
+
page
+
"&size="
+
size
)
return
this
.
http
.
get
<
PageModel
>
(
this
.
baseUrla
pi
+
"/profile/create-short?page="
+
page
+
"&size="
+
size
)
}
}
getPageListAll
():
Observable
<
EmployeeModel
[]
>
{
getPageListAll
():
Observable
<
EmployeeModel
[]
>
{
return
this
.
http
.
get
<
PageModel
>
(
`
${
this
.
urlA
pi
}
/profile/create-short?page=0&size=100`
).
pipe
(
return
this
.
http
.
get
<
PageModel
>
(
`
${
this
.
baseUrla
pi
}
/profile/create-short?page=0&size=100`
).
pipe
(
expand
(
response
=>
expand
(
response
=>
!
response
.
last
!
response
.
last
?
this
.
http
.
get
<
PageModel
>
(
`
${
this
.
urlA
pi
}
/profile/create-short?page=
${
response
.
pageable
.
pageNumber
+
1
}
&size=100`
)
?
this
.
http
.
get
<
PageModel
>
(
`
${
this
.
baseUrla
pi
}
/profile/create-short?page=
${
response
.
pageable
.
pageNumber
+
1
}
&size=100`
)
:
[]
:
[]
),
),
map
(
response
=>
response
.
content
),
map
(
response
=>
response
.
content
),
...
@@ -29,25 +28,25 @@ export class EmployeeService {
...
@@ -29,25 +28,25 @@ export class EmployeeService {
}
}
getList
():
Observable
<
EmployeeModel
[]
>
{
getList
():
Observable
<
EmployeeModel
[]
>
{
return
this
.
http
.
get
<
EmployeeModel
[]
>
(
this
.
urlA
pi
+
"/profile/create-short/lists"
)
return
this
.
http
.
get
<
EmployeeModel
[]
>
(
this
.
baseUrla
pi
+
"/profile/create-short/lists"
)
}
}
getById
(
employeeId
:
string
):
Observable
<
EmployeeModel
>
{
getById
(
employeeId
:
string
):
Observable
<
EmployeeModel
>
{
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
urlA
pi
+
"/profile?employeeId="
+
employeeId
)
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
baseUrla
pi
+
"/profile?employeeId="
+
employeeId
)
}
}
getWorking
():
Observable
<
EmployeeModel
>
{
getWorking
():
Observable
<
EmployeeModel
>
{
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
urlA
pi
+
"/working/mini"
)
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
baseUrla
pi
+
"/working/mini"
)
}
}
getWorkingById
(
employeeId
?:
string
):
Observable
<
EmployeeModel
>
{
getWorkingById
(
employeeId
?:
string
):
Observable
<
EmployeeModel
>
{
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
urlA
pi
+
"/working/mini"
+
(
employeeId
?
"?employeeid="
+
employeeId
:
''
))
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
baseUrla
pi
+
"/working/mini"
+
(
employeeId
?
"?employeeid="
+
employeeId
:
''
))
}
}
getProfile
():
Observable
<
EmployeeModel
>
{
getProfile
():
Observable
<
EmployeeModel
>
{
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
urlA
pi
+
"/profile"
)
return
this
.
http
.
get
<
EmployeeModel
>
(
this
.
baseUrla
pi
+
"/profile"
)
}
}
add
(
body
:
EmployeeModel
):
Observable
<
AlertModel
>
{
add
(
body
:
EmployeeModel
):
Observable
<
AlertModel
>
{
return
this
.
http
.
post
<
AlertModel
>
(
this
.
urlA
pi
+
'/profile-create'
,
body
)
return
this
.
http
.
post
<
AlertModel
>
(
this
.
baseUrla
pi
+
'/profile-create'
,
body
)
}
}
update
(
body
:
EmployeeModel
):
Observable
<
AlertModel
>
{
update
(
body
:
EmployeeModel
):
Observable
<
AlertModel
>
{
return
this
.
http
.
post
<
AlertModel
>
(
this
.
urlA
pi
+
'/profile-update'
,
body
)
return
this
.
http
.
post
<
AlertModel
>
(
this
.
baseUrla
pi
+
'/profile-update'
,
body
)
}
}
delete
(
body
:
EmployeeModel
[]):
Observable
<
AlertModel
>
{
delete
(
body
:
EmployeeModel
[]):
Observable
<
AlertModel
>
{
const
options
=
{
const
options
=
{
...
@@ -56,6 +55,6 @@ export class EmployeeService {
...
@@ -56,6 +55,6 @@ export class EmployeeService {
}),
}),
body
:
body
body
:
body
};
};
return
this
.
http
.
delete
<
AlertModel
>
(
this
.
urlA
pi
+
"/profile-delete"
,
options
)
return
this
.
http
.
delete
<
AlertModel
>
(
this
.
baseUrla
pi
+
"/profile-delete"
,
options
)
}
}
}
}
src/app/shared/services/http-request.interceptor.ts
View file @
534af721
...
@@ -23,10 +23,11 @@ export class HttpRequestInterceptor {
...
@@ -23,10 +23,11 @@ export class HttpRequestInterceptor {
return
next
.
handle
(
req
);
return
next
.
handle
(
req
);
}
else
{
}
else
{
let
authReq
=
req
;
let
authReq
=
req
;
console
.
log
(
req
.
url
)
const
fullUrl
=
req
.
url
.
startsWith
(
"http"
)
?
req
.
url
:
environment
.
baseUrl
+
req
.
url
;
const
fullUrl
=
req
.
url
.
startsWith
(
"http"
)
?
req
.
url
:
environment
.
baseUrl
+
req
.
url
;
const
token
=
this
.
tokenService
.
getToken
()
const
token
=
this
.
tokenService
.
getToken
()
if
(
token
!=
null
&&
!
req
.
url
.
includes
(
"/refresh-token"
))
{
if
(
token
!=
null
&&
!
req
.
url
.
includes
(
"/refresh-token"
))
{
authReq
=
this
.
addTokenHeader
(
req
,
token
,
fullUrl
);
authReq
=
this
.
addTokenHeader
(
req
,
"Bearer "
+
token
,
fullUrl
);
}
else
{
}
else
{
const
overideReq
=
{
const
overideReq
=
{
url
:
fullUrl
,
url
:
fullUrl
,
...
...
src/app/shared/services/token.service.ts
View file @
534af721
...
@@ -7,10 +7,38 @@ const TOKEN_KEY = 'auth-token';
...
@@ -7,10 +7,38 @@ const TOKEN_KEY = 'auth-token';
const
REFRESHTOKEN_KEY
=
'auth-refreshtoken'
;
const
REFRESHTOKEN_KEY
=
'auth-refreshtoken'
;
const
USER_KEY
=
'auth-user'
;
const
USER_KEY
=
'auth-user'
;
const
USER_DATA_KEY
=
'auth-user-data'
;
const
USER_DATA_KEY
=
'auth-user-data'
;
export
class
UserLoginModel
{
export
interface
UserLoginModel
{
public
username
:
string
=
""
;
sub
:
string
;
public
accessToken
:
string
=
""
;
iss
:
string
;
public
refreshToken
:
string
=
""
;
companyid
:
string
;
companyName
:
string
;
employeeid
:
string
;
dbName
:
string
;
job
:
string
;
emp_position
:
string
;
user_level
:
string
;
lang
:
string
;
firstlogin
:
string
;
user_role
:
string
;
role_level
:
string
;
encode
:
string
;
user
:
string
;
roles
:
string
[];
username
:
string
;
app_name
:
string
;
zmlogin
:
string
;
zm_user
:
string
;
memberid
:
string
;
token_zeeme
:
string
;
comid
:
string
;
url_myhr
:
string
;
regionallty
:
string
;
ad
:
string
;
workarea
:
string
;
branch
:
string
;
actorid
:
string
;
accountactive
:
string
;
exp
:
number
;
}
}
@
Injectable
({
@
Injectable
({
...
@@ -28,11 +56,6 @@ export class TokenService {
...
@@ -28,11 +56,6 @@ export class TokenService {
public
saveToken
(
token
:
string
):
void
{
public
saveToken
(
token
:
string
):
void
{
window
.
localStorage
.
removeItem
(
TOKEN_KEY
);
window
.
localStorage
.
removeItem
(
TOKEN_KEY
);
window
.
localStorage
.
setItem
(
TOKEN_KEY
,
token
);
window
.
localStorage
.
setItem
(
TOKEN_KEY
,
token
);
const
user
=
this
.
getUser
();
if
(
user
.
accessToken
)
{
this
.
saveUser
({
...
user
,
accessToken
:
token
});
}
}
}
public
saveUser
(
user
:
any
):
void
{
public
saveUser
(
user
:
any
):
void
{
...
@@ -40,13 +63,13 @@ export class TokenService {
...
@@ -40,13 +63,13 @@ export class TokenService {
window
.
localStorage
.
setItem
(
USER_KEY
,
JSON
.
stringify
(
user
));
window
.
localStorage
.
setItem
(
USER_KEY
,
JSON
.
stringify
(
user
));
}
}
public
getUser
():
UserLoginModel
{
public
getUser
():
UserLoginModel
|
undefined
{
const
user
=
window
.
localStorage
.
getItem
(
USER_KEY
);
const
user
=
window
.
localStorage
.
getItem
(
USER_KEY
);
if
(
user
)
{
if
(
user
)
{
return
JSON
.
parse
(
user
);
return
JSON
.
parse
(
user
);
}
}
return
new
UserLoginModel
()
;
return
undefined
;
}
}
public
getToken
():
string
|
null
{
public
getToken
():
string
|
null
{
...
@@ -61,9 +84,9 @@ export class TokenService {
...
@@ -61,9 +84,9 @@ export class TokenService {
public
getRefreshToken
():
string
|
null
{
public
getRefreshToken
():
string
|
null
{
return
window
.
localStorage
.
getItem
(
REFRESHTOKEN_KEY
);
return
window
.
localStorage
.
getItem
(
REFRESHTOKEN_KEY
);
}
}
public
saveUserData
(
user
:
string
):
void
{
public
saveUserData
(
user
:
EmployeeModel
):
void
{
window
.
localStorage
.
removeItem
(
USER_DATA_KEY
);
window
.
localStorage
.
removeItem
(
USER_DATA_KEY
);
window
.
localStorage
.
setItem
(
USER_DATA_KEY
,
user
);
window
.
localStorage
.
setItem
(
USER_DATA_KEY
,
JSON
.
stringify
(
user
)
);
}
}
public
getUserData
():
EmployeeModel
{
public
getUserData
():
EmployeeModel
{
...
...
src/environments/environment.ts
View file @
534af721
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`.
// The list of file replacements can be found in `angular.json`.
export
const
environment
=
{
export
const
environment
=
{
production
:
false
,
production
:
false
,
baseUrl
:
'
https://myskill-x-uat.myhr.co.th/api'
,
baseUrl
:
'https://myskill-x-uat.myhr.co.th/api'
,
};
};
/*
/*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment