Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Meu-Template-Angular-CSR
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
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
Trần Anh Phú
Meu-Template-Angular-CSR
Commits
bc83c79b
Commit
bc83c79b
authored
Oct 30, 2024
by
tinhbe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complate login
parent
1bfb63bb
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
147 additions
and
44 deletions
+147
-44
layout.component.ts
src/app/+admin/layout/feature/ui/layout.component.ts
+1
-0
home.component.html
src/app/+home/feature/home.component.html
+44
-3
home.component.scss
src/app/+home/feature/home.component.scss
+28
-0
home.component.ts
src/app/+home/feature/home.component.ts
+15
-3
ApiService.service.ts
src/app/+login/data-access/Services/ApiService.service.ts
+2
-1
admin.guard.ts
src/app/+login/data-access/guard/admin.guard.ts
+9
-3
auth.guard.ts
src/app/+login/data-access/guard/auth.guard.ts
+11
-3
login.component.html
src/app/+login/feature/login.component.html
+7
-11
login.component.scss
src/app/+login/feature/login.component.scss
+2
-2
login.component.ts
src/app/+login/feature/login.component.ts
+24
-17
_utilities.scss
src/custom/tailwind/_utilities.scss
+3
-0
environment.development.ts
src/environments/environment.development.ts
+1
-1
No files found.
src/app/+admin/layout/feature/ui/layout.component.ts
View file @
bc83c79b
...
@@ -16,6 +16,7 @@ import { CommonModule } from '@angular/common';
...
@@ -16,6 +16,7 @@ import { CommonModule } from '@angular/common';
],
],
template
:
` <nz-content>
template
:
` <nz-content>
<div>
<div>
admin
<router-outlet></router-outlet>
<router-outlet></router-outlet>
</div>
</div>
</nz-content>`
,
</nz-content>`
,
...
...
src/app/+home/feature/home.component.html
View file @
bc83c79b
<div>
<nz-layout>
<p
class=
"tw-text-white tw-bg-black tw-p-5"
>
Welcome to the home page!
</p>
<nz-sider
nzCollapsible
nzWidth=
"200px"
>
</div>
<div
class=
"logo"
></div>
\ No newline at end of file
<ul
nz-menu
nzTheme=
"dark"
nzMode=
"inline"
>
<li
nz-menu-item
>
<span
nz-icon
nzType=
"pie-chart"
></span>
<span>
Option 1
</span>
</li>
<li
nz-menu-item
>
<span
nz-icon
nzType=
"desktop"
></span>
<span>
Option 2
</span>
</li>
<li
nz-submenu
nzTitle=
"User"
nzIcon=
"user"
>
<ul>
<li
nz-menu-item
>
Tom
</li>
<li
nz-menu-item
>
Bill
</li>
<li
nz-menu-item
>
Alex
</li>
</ul>
</li>
<li
nz-submenu
nzTitle=
"Team"
nzIcon=
"team"
>
<ul>
<li
nz-menu-item
>
Team 1
</li>
<li
nz-menu-item
>
Team 2
</li>
</ul>
</li>
<li
nz-menu-item
>
<span
nz-icon
nzType=
"file"
></span>
<span>
File
</span>
</li>
</ul>
</nz-sider>
<nz-layout>
<nz-header></nz-header>
<nz-content>
<nz-breadcrumb>
<nz-breadcrumb-item>
User
</nz-breadcrumb-item>
<nz-breadcrumb-item>
Bill
</nz-breadcrumb-item>
</nz-breadcrumb>
<div
class=
"inner-content"
>
Bill is a cat.
</div>
</nz-content>
<nz-footer>
Ant Design ©2020 Implement By Angular
</nz-footer>
</nz-layout>
</nz-layout>
src/app/+home/feature/home.component.scss
View file @
bc83c79b
.logo
{
height
:
32px
;
margin
:
16px
;
background
:
rgba
(
255
,
255
,
255
,
0
.3
);
}
nz-header
{
background
:
#fff
;
padding
:
0
;
}
nz-content
{
margin
:
0
16px
;
}
nz-breadcrumb
{
margin
:
16px
0
;
}
.inner-content
{
padding
:
24px
;
background
:
#fff
;
min-height
:
360px
;
}
nz-footer
{
text-align
:
center
;
}
src/app/+home/feature/home.component.ts
View file @
bc83c79b
import
{
CommonModule
}
from
'@angular/common'
;
import
{
ChangeDetectionStrategy
,
Component
}
from
'@angular/core'
;
import
{
ChangeDetectionStrategy
,
Component
}
from
'@angular/core'
;
import
{
NzCarouselModule
}
from
'ng-zorro-antd/carousel'
;
import
{
NzCarouselModule
}
from
'ng-zorro-antd/carousel'
;
import
{
NzLayoutModule
}
from
'ng-zorro-antd/layout'
;
import
{
NzBreadCrumbModule
}
from
'ng-zorro-antd/breadcrumb'
;
import
{
NzMenuModule
}
from
'ng-zorro-antd/menu'
;
import
{
NzIconModule
}
from
'ng-zorro-antd/icon'
;
@
Component
({
@
Component
({
selector
:
'meu-home'
,
selector
:
'meu-home'
,
standalone
:
true
,
standalone
:
true
,
imports
:
[
NzCarouselModule
],
imports
:
[
NzCarouselModule
,
CommonModule
,
NzLayoutModule
,
NzBreadCrumbModule
,
NzMenuModule
,
NzIconModule
],
templateUrl
:
'./home.component.html'
,
templateUrl
:
'./home.component.html'
,
styleUrl
:
'./home.component.scss'
,
styleUrls
:
[
'./home.component.scss'
],
//styleUrl: './home.component.scss',
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
})
export
class
HomeComponent
{}
export
class
HomeComponent
{}
src/app/+login/data-access/Services/ApiService.service.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
Observable
}
from
'rxjs'
;
import
{
Observable
}
from
'rxjs'
;
import
{
environment
}
from
'../../../../environments/environment.development'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'root'
,
providedIn
:
'root'
,
})
})
export
class
AuthService
{
export
class
AuthService
{
private
apiUrl
=
'http://localhost:3000
/login'
;
private
apiUrl
=
environment
.
API_DOMAIN
+
'
/login'
;
constructor
(
private
http
:
HttpClient
)
{}
constructor
(
private
http
:
HttpClient
)
{}
...
...
src/app/+login/data-access/guard/admin.guard.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
CanActivate
}
from
'@angular/router'
;
import
{
CanActivate
,
Router
}
from
'@angular/router'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'root'
,
providedIn
:
'root'
,
})
})
export
class
AdminGuard
implements
CanActivate
{
export
class
AdminGuard
implements
CanActivate
{
constructor
()
{}
constructor
(
private
router
:
Router
)
{}
canActivate
():
boolean
{
canActivate
():
boolean
{
return
true
;
const
role
=
localStorage
.
getItem
(
'role'
);
if
(
role
===
'admin'
)
{
return
true
;
}
else
{
this
.
router
.
navigate
([
'/login'
]);
// chuyển đến trang lỗi không có quyền. cho bắt đăng nhập với quyên admin
return
false
;
}
}
}
}
}
src/app/+login/data-access/guard/auth.guard.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
Injectable
}
from
'@angular/core'
;
import
{
CanActivate
}
from
'@angular/router'
;
import
{
CanActivate
,
Router
}
from
'@angular/router'
;
@
Injectable
({
@
Injectable
({
providedIn
:
'root'
,
providedIn
:
'root'
,
})
})
export
class
AuthGuard
implements
CanActivate
{
export
class
AuthGuard
implements
CanActivate
{
constructor
()
{}
constructor
(
private
router
:
Router
)
{}
canActivate
():
boolean
{
canActivate
():
boolean
{
return
true
;
const
token
=
localStorage
.
getItem
(
'token'
);
if
(
token
)
{
this
.
router
.
navigate
([
'/home'
]);
return
false
;
}
else
{
return
true
;
}
}
}
}
}
src/app/+login/feature/login.component.html
View file @
bc83c79b
<div
class=
"tw-h-screen tw-bg-gradient-to-br tw-from-indigo-600 tw-to-purple-600 tw-flex tw-items-center tw-justify-center tw-p-6"
>
<div
class=
"tw-h-screen tw-bg-gradient-to-br tw-from-indigo-600 tw-to-purple-600 tw-flex tw-items-center tw-justify-center tw-p-6"
>
<form
nz-form
[
formGroup
]="
loginForm
"
class=
"tw-w-full tw-max-w-md tw-bg-white tw-rounded-lg tw-shadow-xl tw-p-8 tw-space-y-6 tw-backdrop-blur-sm"
(
ngSubmit
)="
onSubmit
()"
>
<form
nz-form
[
formGroup
]="
loginForm
"
class=
"tw-w-full tw-max-w-md tw-bg-white tw-rounded-lg tw-shadow-xl tw-p-8 tw-space-y-6 tw-backdrop-blur-sm"
(
ngSubmit
)="
onSubmit
()"
>
<!-- Form Header -->
<h2
class=
"tw-text-3xl tw-font-bold tw-text-center tw-text-gray-800"
>
Welcome Back!
</h2>
<h2
class=
"tw-text-2xl tw-font-bold tw-text-center tw-text-gray-800"
>
Welcome Back!
</h2>
<p
class=
"tw-text-center tw-text-1xl tw-text-gray-600"
>
Please log in to your account
</p>
<p
class=
"tw-text-center tw-text-gray-600"
>
Please log in to your account
</p>
<!-- Username Field -->
<nz-form-item
class=
"tw-mb-4"
>
<nz-form-item
class=
"tw-mb-4"
>
<nz-form-label
[
nzFor
]="'
userName
'"
class=
"tw-text-gray-700 tw-font-
medium"
>
Username
</nz-form-label>
<nz-form-label
[
nzFor
]="'
userName
'"
class=
"tw-text-gray-700 tw-font-
bold"
>
Username :
</nz-form-label>
<nz-form-control
nzErrorTip=
"Please input your username!"
>
<nz-form-control
nzErrorTip=
"Please input your username!"
>
<nz-input-group
class=
"tw-w-full"
>
<nz-input-group
class=
"tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
...
@@ -25,9 +23,9 @@
...
@@ -25,9 +23,9 @@
</nz-form-control>
</nz-form-control>
</nz-form-item>
</nz-form-item>
<!-- Password Field -->
<nz-form-item
class=
"tw-mb-4"
>
<nz-form-item
class=
"tw-mb-4"
>
<nz-form-label
[
nzFor
]="'
password
'"
class=
"tw-text-gray-700 tw-font-
medium"
>
Password
</nz-form-label>
<nz-form-label
[
nzFor
]="'
password
'"
class=
"tw-text-gray-700 tw-font-
bold "
>
Password :
</nz-form-label>
<nz-form-control
nzErrorTip=
"Please input your password!"
>
<nz-form-control
nzErrorTip=
"Please input your password!"
>
<nz-input-group
class=
"tw-w-full"
>
<nz-input-group
class=
"tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
...
@@ -45,17 +43,15 @@
...
@@ -45,17 +43,15 @@
</nz-input-group>
</nz-input-group>
</nz-form-control>
</nz-form-control>
</nz-form-item>
</nz-form-item>
<p
*
ngIf=
"MgsError"
class=
"text-error tw-mb-4"
>
{{ MgsError }}
</p>
<!-- Submit Button -->
<button
<button
nz-button
nz-button
class=
"
button tw-w-full tw-bg-indigo-600 tw-text-white tw-font-semibold tw-py-2 tw-rounded-md tw-hover:bg-indigo-700 tw-transition-colors
"
class=
"
tw-w-full tw-bg-indigo-600 tw-text-white tw-font-semibold tw-py-2 tw-rounded-md hover:bg-submit tw-transition-colors button-login
"
[
nzType
]="'
primary
'"
[
nzType
]="'
primary
'"
>
>
Log in
Log in
</button>
</button>
<!-- Register Link -->
<p
class=
"tw-text-center tw-text-gray-600 tw-mt-4"
>
<p
class=
"tw-text-center tw-text-gray-600 tw-mt-4"
>
Or
Or
<a
class=
"tw-text-indigo-600 tw-font-semibold hover:tw-underline cursor-pointer"
>
register now!
</a>
<a
class=
"tw-text-indigo-600 tw-font-semibold hover:tw-underline cursor-pointer"
>
register now!
</a>
...
...
src/app/+login/feature/login.component.scss
View file @
bc83c79b
...
@@ -12,6 +12,6 @@
...
@@ -12,6 +12,6 @@
.error-message
{
.error-message
{
color
:
red
;
color
:
red
;
}
}
.button
{
.button
-login
{
background-color
:
#
3700ff
;
background-color
:
#
714afd
;
}
}
src/app/+login/feature/login.component.ts
View file @
bc83c79b
...
@@ -10,7 +10,7 @@ import { NzAlertModule } from 'ng-zorro-antd/alert';
...
@@ -10,7 +10,7 @@ import { NzAlertModule } from 'ng-zorro-antd/alert';
import
{
CommonModule
}
from
'@angular/common'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
FormBuilder
,
FormGroup
,
FormsModule
,
ReactiveFormsModule
,
Validators
}
from
'@angular/forms'
;
import
{
FormBuilder
,
FormGroup
,
FormsModule
,
ReactiveFormsModule
,
Validators
}
from
'@angular/forms'
;
import
{
catchError
,
finalize
,
Observable
,
tap
}
from
'rxjs'
;
import
{
catchError
,
finalize
,
Observable
,
of
,
tap
}
from
'rxjs'
;
import
{
AuthService
}
from
'../data-access/Services/ApiService.service'
;
import
{
AuthService
}
from
'../data-access/Services/ApiService.service'
;
import
{
response
}
from
'express'
;
import
{
response
}
from
'express'
;
@
Component
({
@
Component
({
...
@@ -34,35 +34,42 @@ import { response } from 'express';
...
@@ -34,35 +34,42 @@ import { response } from 'express';
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
})
export
class
LoginComponent
implements
OnInit
{
export
class
LoginComponent
implements
OnInit
{
MgsError
:
string
=
''
;
loginForm
:
FormGroup
;
loginForm
:
FormGroup
;
constructor
(
private
fb
:
FormBuilder
,
private
authService
:
AuthService
)
{
constructor
(
private
fb
:
FormBuilder
,
private
authService
:
AuthService
)
{
this
.
loginForm
=
this
.
fb
.
group
({
this
.
loginForm
=
this
.
fb
.
group
({
user
n
ame
:
[
''
,
[
Validators
.
required
]],
user
N
ame
:
[
''
,
[
Validators
.
required
]],
password
:
[
''
,
[
Validators
.
required
]],
password
:
[
''
,
[
Validators
.
required
]],
});
});
}
}
ngOnInit
()
{}
ngOnInit
()
{}
saveInfo
(
res
:
any
)
{
localStorage
.
setItem
(
'token'
,
res
.
responseData
.
token
);
localStorage
.
setItem
(
'expirationTime'
,
res
.
responseData
.
expirationTime
);
localStorage
.
setItem
(
'role'
,
res
.
responseData
.
role
);
}
onSubmit
()
{
onSubmit
()
{
const
headers
=
new
HttpHeaders
()
if
(
!
this
.
loginForm
.
valid
)
{
if
(
!
this
.
loginForm
.
valid
)
{
alert
(
'vui lòng nhập đầy đủ thông tin'
)
;
this
.
MgsError
=
"Vui lòng nhập thống tin đăng nhập"
;
return
;
return
;
}
}
console
.
log
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
);
console
.
log
(
this
.
loginForm
.
value
.
userName
,
this
.
loginForm
.
value
.
password
);
this
.
authService
.
login
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
).
pipe
(
tap
(()
=>
{
this
.
authService
.
login
(
this
.
loginForm
.
value
.
userName
,
this
.
loginForm
.
value
.
password
).
pipe
(
tap
((
res
)
=>
{
// không ảnh hưởng đến data trên observable
this
.
saveInfo
(
res
);
window
.
location
.
href
=
'/admin'
;
}),
}),
catchError
((
error
)
=>
{
catchError
((
err
)
=>
{
console
.
log
(
error
);
this
.
MgsError
=
err
.
message
;
throw
error
;
console
.
log
(
this
.
MgsError
);
console
.
log
(
err
);
return
of
(
null
);
}),
}),
finalize
(()
=>
{})
finalize
(()
=>
{
// gọi ra khi observable hoàn tất
).
subscribe
(
console
.
log
(
'Login request completed'
);
response
=>
{
})
alert
(
response
.
message
);
).
subscribe
();
}
);
}
}
}
}
src/custom/tailwind/_utilities.scss
View file @
bc83c79b
...
@@ -13,4 +13,7 @@
...
@@ -13,4 +13,7 @@
color
:
white
;
color
:
white
;
border
:
rgb
(
218
,
141
,
0
);
border
:
rgb
(
218
,
141
,
0
);
}
}
.bg-submit
{
background-color
:
#3700ff
;
}
}
}
src/environments/environment.development.ts
View file @
bc83c79b
export
const
environment
=
{
export
const
environment
=
{
API_DOMAIN
:
'http
/
'
,
//custom
API_DOMAIN
:
'http
://localhost:3000
'
,
//custom
};
};
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