Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BookingMyHrManagement
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
Chanachai
BookingMyHrManagement
Commits
f40cbcd3
Commit
f40cbcd3
authored
Mar 11, 2025
by
Ooh-Ao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login
parent
a77f8b77
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
64 additions
and
101 deletions
+64
-101
User.js
API/src/models/User.js
+22
-22
login-page.component.ts
...src/app/authentication/login-page/login-page.component.ts
+8
-11
user.model.ts
Synto-Angular/src/app/models/user.model.ts
+7
-50
header.component.html
...ar/src/app/shared/components/header/header.component.html
+2
-2
header.component.ts
...ular/src/app/shared/components/header/header.component.ts
+10
-4
sidebar.component.ts
...ar/src/app/shared/components/sidebar/sidebar.component.ts
+6
-4
auth.service.ts
Synto-Angular/src/app/shared/services/auth.service.ts
+3
-2
token.service.ts
Synto-Angular/src/app/shared/services/token.service.ts
+2
-2
user-auth.model.ts
Synto-Angular/src/app/shared/user-auth.model.ts
+3
-3
environment.ts
Synto-Angular/src/environments/environment.ts
+1
-1
No files found.
API/src/models/User.js
View file @
f40cbcd3
...
...
@@ -59,30 +59,30 @@ User.beforeUpdate(async (user, options) => {
}
});
(
async
()
=>
{
try
{
// sync() จะสร้างตารางตาม Model ทั้งหมดที่มีในโปรเจกต์ (ถ้ายังไม่มี)
// หากมีอยู่แล้วและต้องการ drop table เดิมให้ใช้ force: true (ไม่แนะนำบน production)
await
sequelize
.
sync
({
force
:
false
});
//
(async () => {
//
try {
//
// sync() จะสร้างตารางตาม Model ทั้งหมดที่มีในโปรเจกต์ (ถ้ายังไม่มี)
//
// หากมีอยู่แล้วและต้องการ drop table เดิมให้ใช้ force: true (ไม่แนะนำบน production)
//
await sequelize.sync({ force: false });
console
.
log
(
"Table(s) created successfully!"
);
//
console.log("Table(s) created successfully!");
// ตัวอย่างการทดสอบสร้าง User ทันที (ถ้าต้องการ)
const
newUser
=
await
User
.
create
({
first_name
:
"Jane"
,
last_name
:
"Doe"
,
email
:
"jane@example.com"
,
password
:
"123456"
,
// จะถูก hash จาก hook ใน model
role
:
"employee"
,
});
console
.
log
(
"New user created:"
,
newUser
.
user_id
);
//
// ตัวอย่างการทดสอบสร้าง User ทันที (ถ้าต้องการ)
//
const newUser = await User.create({
//
first_name: "Jane",
//
last_name: "Doe",
//
email: "jane@example.com",
//
password: "123456", // จะถูก hash จาก hook ใน model
//
role: "employee",
//
});
//
console.log("New user created:", newUser.user_id);
}
catch
(
error
)
{
console
.
error
(
"Error creating table(s):"
,
error
);
}
finally
{
// ปิด connection เมื่อเสร็จสิ้นงาน (ขึ้นอยู่กับว่าเราต้องการปิดหรือไม่)
await
sequelize
.
close
();
}
})();
//
} catch (error) {
//
console.error("Error creating table(s):", error);
//
} finally {
//
// ปิด connection เมื่อเสร็จสิ้นงาน (ขึ้นอยู่กับว่าเราต้องการปิดหรือไม่)
//
await sequelize.close();
//
}
//
})();
module
.
exports
=
User
;
Synto-Angular/src/app/authentication/login-page/login-page.component.ts
View file @
f40cbcd3
...
...
@@ -22,8 +22,8 @@ export class LoginPageComponent {
private
renderer
:
Renderer2
,
public
tokenService
:
TokenService
,
)
{
const
bodyElement
=
this
.
renderer
.
selectRootElement
(
'body'
,
true
);
this
.
renderer
.
setAttribute
(
bodyElement
,
'class'
,
'cover1 justify-center'
);
const
bodyElement
=
this
.
renderer
.
selectRootElement
(
'body'
,
true
);
this
.
renderer
.
setAttribute
(
bodyElement
,
'class'
,
'cover1 justify-center'
);
}
ngOnInit
():
void
{
this
.
loginForm
=
this
.
formBuilder
.
group
({
...
...
@@ -66,23 +66,20 @@ export class LoginPageComponent {
body
.
username
=
this
.
email
;
body
.
password
=
this
.
password
;
this
.
authService
.
login
(
this
.
loginForm
.
controls
[
'username'
].
value
,
this
.
loginForm
.
controls
[
'password'
].
value
).
subscribe
(
result
=>
{
this
.
tokenService
.
saveToken
(
result
.
access
_t
oken
);
this
.
tokenService
.
saveToken
(
result
.
access
T
oken
);
// this.tokenService.saveRefreshToken(result.refreshToken);
this
.
tokenService
.
saveUser
(
result
);
if
(
result
.
member
.
status
==
1
)
{
if
(
result
.
member
.
role
==
99
)
{
this
.
router
.
navigate
([
'/admin/member-manage'
])
}
else
{
this
.
router
.
navigate
([
'/admin/member-manage'
])
}
if
(
result
.
user
.
role
==
'admin'
)
{
this
.
router
.
navigate
([
'/admin/home'
])
}
else
{
this
.
error
=
'ไม่สามารถใช้งานได้กรุณาติดต่อผู้ให้บริการ'
this
.
router
.
navigate
([
'/employee/home'
])
}
// this.routes.navigate(['/admin/member-manage'])
},
(
error
)
=>
{
this
.
disabled
=
''
;
this
.
error
=
'Username หรือ Password ไม่ถูกต้อง'
;
this
.
router
.
navigate
([
'/employee/home'
])
//
this.router.navigate(['/employee/home'])
})
}
...
...
Synto-Angular/src/app/models/user.model.ts
View file @
f40cbcd3
import
{
TranslateService
}
from
"@ngx-translate/core"
;
import
{
BaseModel
}
from
"./base.model"
;
import
{
environment
}
from
"src/environments/environment"
;
export
class
UserProfileModel
extends
BaseModel
{
memberI
d
:
string
;
user
name
:
string
;
password
:
string
;
user_i
d
:
string
;
first_
name
:
string
;
last_name
:
string
;
email
:
string
;
firstName
:
string
;
lastName
:
string
;
phoneNumber
:
string
;
role
:
number
;
status
:
number
;
picture
:
any
;
createdAt
:
string
;
updatedAt
:
string
;
role
:
string
;
constructor
(
data
?:
Partial
<
UserProfileModel
>
,
translateService
?:
TranslateService
)
{
super
(
data
,
translateService
);
this
.
memberId
=
data
?.
memberId
!
;
this
.
username
=
data
?.
username
!
this
.
password
=
data
?.
password
!
this
.
phoneNumber
=
data
?.
phoneNumber
||
""
this
.
firstName
=
data
?.
firstName
||
""
this
.
lastName
=
data
?.
lastName
||
""
this
.
status
=
data
?.
status
!
this
.
user_id
=
data
?.
user_id
!
;
this
.
first_name
=
data
?.
first_name
!
this
.
last_name
=
data
?.
last_name
!
this
.
email
=
data
?.
email
!
this
.
role
=
data
?.
role
!
this
.
createdAt
=
data
?.
createdAt
!
this
.
updatedAt
=
data
?.
updatedAt
!
}
getRole
():
string
{
if
(
this
.
role
==
99
)
{
return
this
.
translateService
.
instant
(
'Admin-System'
)
}
else
if
(
this
.
role
==
1
)
{
return
this
.
translateService
.
instant
(
'Admin-Company'
)
}
else
{
return
this
.
translateService
.
instant
(
'User'
)
}
}
getStatus
():
string
{
if
(
this
.
status
==
1
)
{
return
this
.
translateService
.
instant
(
'Active'
)
}
else
{
return
this
.
translateService
.
instant
(
'Unactive'
)
}
}
getPicture
():
string
{
return
this
.
picture
?
environment
.
baseUrl
+
'/images/'
+
this
.
picture
:
'./assets/images/faces/1.jpg'
}
getFullname
():
string
{
return
this
.
firstName
+
" "
+
this
.
lastName
}
}
Synto-Angular/src/app/shared/components/header/header.component.html
View file @
f40cbcd3
...
...
@@ -791,7 +791,7 @@
<i
class=
"ti ti-wallet text-lg"
></i>
Bal: $7,12,950
</a>
<a
routerLink=
"/signin/basic
"
class=
"ti-dropdown-item"
>
<a
(
click
)="
logOut
()
"
class=
"ti-dropdown-item"
>
<i
class=
"ti ti-logout text-lg"
></i>
Log Out
</a>
...
...
@@ -1025,7 +1025,7 @@
id=
"not3"
class=
"p-2 border dark:border-white/10 rounded-sm flex items-center text-gray-500 relative header-box"
>
<a
<a
routerLink=
"/tables/basictables"
(
click
)="
removetheModal
()"
class=
"w-full my-auto items-center flex"
>
...
...
Synto-Angular/src/app/shared/components/header/header.component.ts
View file @
f40cbcd3
/* eslint-disable no-constant-condition */
import
{
Component
,
ElementRef
}
from
'@angular/core'
;
import
{
NavService
}
from
'../../services/navservice'
;
import
{
AuthService
}
from
'../../services/auth.service'
;
import
{
TokenService
}
from
'../../services/token.service'
;
@
Component
({
selector
:
'app-header'
,
...
...
@@ -9,7 +11,7 @@ import { NavService } from '../../services/navservice';
})
export
class
HeaderComponent
{
constructor
(
public
navServices
:
NavService
,
constructor
(
public
navServices
:
NavService
,
private
tokenService
:
TokenService
,
private
elementRef
:
ElementRef
)
{
}
...
...
@@ -37,11 +39,11 @@ export class HeaderComponent {
toggleSidebar
()
{
let
html
=
this
.
elementRef
.
nativeElement
.
ownerDocument
.
documentElement
;
if
(
window
.
innerWidth
<=
992
)
{
if
(
window
.
innerWidth
<=
992
)
{
html
?.
setAttribute
(
'toggled'
,
html
?.
getAttribute
(
'toggled'
)
==
'open'
?
'close'
:
'open'
);
if
(
html
?.
getAttribute
(
'toggled'
)
==
'open'
)
{
if
(
html
?.
getAttribute
(
'toggled'
)
==
'open'
)
{
document
.
querySelector
(
'#responsive-overlay'
)?.
classList
.
add
(
'active'
);
}
else
{
}
else
{
document
.
querySelector
(
'#responsive-overlay'
)?.
classList
.
remove
(
'active'
);
}
}
...
...
@@ -106,4 +108,8 @@ export class HeaderComponent {
const
element
:
any
=
document
.
querySelector
(
'.serachmodal'
);
element
.
click
();
}
logOut
()
{
this
.
tokenService
.
signOut
();
}
}
Synto-Angular/src/app/shared/components/sidebar/sidebar.component.ts
View file @
f40cbcd3
...
...
@@ -4,6 +4,7 @@ import { Subscription, fromEvent } from 'rxjs';
import
{
DomSanitizer
,
SafeHtml
}
from
'@angular/platform-browser'
;
import
{
NavigationEnd
,
Router
}
from
'@angular/router'
;
import
{
checkHoriMenu
,
switcherArrowFn
}
from
'./sidebar'
;
import
{
TokenService
}
from
'../../services/token.service'
;
@
Component
({
selector
:
'app-sidebar'
,
...
...
@@ -66,17 +67,18 @@ export class SidebarComponent {
private
sanitizer
:
DomSanitizer
,
public
router
:
Router
,
public
renderer
:
Renderer2
,
private
elementRef
:
ElementRef
private
elementRef
:
ElementRef
,
private
tokenService
:
TokenService
,
)
{
this
.
screenWidth
=
window
.
innerWidth
;
}
ngOnInit
()
{
if
(
true
)
{
if
(
this
.
tokenService
.
getUser
().
user
.
role
==
'admin'
)
{
this
.
menuitemsSubscribe$
=
this
.
navServices
.
itemsAdmin
.
subscribe
((
items
)
=>
{
this
.
menuItems
=
items
;
});
}
else
{
}
else
{
this
.
menuitemsSubscribe$
=
this
.
navServices
.
itemsEmp
.
subscribe
((
items
)
=>
{
this
.
menuItems
=
items
;
});
...
...
@@ -89,7 +91,7 @@ export class SidebarComponent {
this
.
ParentActive
();
}
});
if
(
window
.
innerWidth
<=
992
)
{
if
(
window
.
innerWidth
<=
992
)
{
document
.
documentElement
?.
setAttribute
(
'toggled'
,
'close'
);
}
const
WindowResize
=
fromEvent
(
window
,
'resize'
);
...
...
Synto-Angular/src/app/shared/services/auth.service.ts
View file @
f40cbcd3
...
...
@@ -2,11 +2,12 @@ import { Injectable, NgZone } from '@angular/core';
import
{
HttpClient
}
from
'@angular/common/http'
;
import
{
ProfileModel
,
UserModel
}
from
'../user-auth.model'
;
import
{
UserProfileModel
}
from
'src/app/models/user.model'
;
import
{
environment
}
from
'src/environments/environment'
;
@
Injectable
({
providedIn
:
'root'
,
})
export
class
AuthService
{
apiBaseUrl
=
"/auth"
;
apiBaseUrl
=
environment
.
baseUrl
+
"/auth"
;
constructor
(
private
http
:
HttpClient
,
)
{
...
...
@@ -14,7 +15,7 @@ export class AuthService {
login
(
username
:
string
,
password
:
string
)
{
const
body
=
{
username
:
username
,
email
:
username
,
password
:
password
,
};
return
this
.
http
.
post
<
UserModel
>
(
this
.
apiBaseUrl
+
'/login'
,
body
)
...
...
Synto-Angular/src/app/shared/services/token.service.ts
View file @
f40cbcd3
...
...
@@ -31,8 +31,8 @@ export class TokenService {
window
.
localStorage
.
setItem
(
TOKEN_KEY
,
token
);
const
user
=
this
.
getUser
();
if
(
user
.
access
_t
oken
)
{
this
.
saveUser
({
...
user
,
access
_t
oken
:
token
});
if
(
user
.
access
T
oken
)
{
this
.
saveUser
({
...
user
,
access
T
oken
:
token
});
}
}
...
...
Synto-Angular/src/app/shared/user-auth.model.ts
View file @
f40cbcd3
...
...
@@ -8,9 +8,9 @@ export class LoginModel {
export
class
UserModel
{
public
access
_t
oken
:
string
=
""
;
public
token_typ
e
:
string
=
""
;
public
memb
er
:
UserProfileModel
=
new
UserProfileModel
()
public
access
T
oken
:
string
=
""
;
public
messag
e
:
string
=
""
;
public
us
er
:
UserProfileModel
=
new
UserProfileModel
()
}
export
interface
ProfileModel
{
...
...
Synto-Angular/src/environments/environment.ts
View file @
f40cbcd3
...
...
@@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`.
export
const
environment
=
{
production
:
true
,
baseUrl
:
'http://localhost:3000'
,
baseUrl
:
'http://localhost:3000
/api
'
,
firebase
:
{
apiKey
:
'********************************'
,
authDomain
:
'********************************'
,
...
...
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