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
6 months ago
by
tinhbe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
complate login
parent
1bfb63bb
Changes
12
Show 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';
],
template
:
` <nz-content>
<div>
admin
<router-outlet></router-outlet>
</div>
</nz-content>`
,
...
...
This diff is collapsed.
Click to expand it.
src/app/+home/feature/home.component.html
View file @
bc83c79b
<div>
<p
class=
"tw-text-white tw-bg-black tw-p-5"
>
Welcome to the home page!
</p>
</div>
\ No newline at end of file
<nz-layout>
<nz-sider
nzCollapsible
nzWidth=
"200px"
>
<div
class=
"logo"
></div>
<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>
This diff is collapsed.
Click to expand it.
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
;
}
This diff is collapsed.
Click to expand it.
src/app/+home/feature/home.component.ts
View file @
bc83c79b
import
{
CommonModule
}
from
'@angular/common'
;
import
{
ChangeDetectionStrategy
,
Component
}
from
'@angular/core'
;
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
({
selector
:
'meu-home'
,
standalone
:
true
,
imports
:
[
NzCarouselModule
],
imports
:
[
NzCarouselModule
,
CommonModule
,
NzLayoutModule
,
NzBreadCrumbModule
,
NzMenuModule
,
NzIconModule
],
templateUrl
:
'./home.component.html'
,
styleUrl
:
'./home.component.scss'
,
styleUrls
:
[
'./home.component.scss'
],
//styleUrl: './home.component.scss',
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
export
class
HomeComponent
{}
This diff is collapsed.
Click to expand it.
src/app/+login/data-access/Services/ApiService.service.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
Observable
}
from
'rxjs'
;
import
{
environment
}
from
'../../../../environments/environment.development'
;
@
Injectable
({
providedIn
:
'root'
,
})
export
class
AuthService
{
private
apiUrl
=
'http://localhost:3000
/login'
;
private
apiUrl
=
environment
.
API_DOMAIN
+
'
/login'
;
constructor
(
private
http
:
HttpClient
)
{}
...
...
This diff is collapsed.
Click to expand it.
src/app/+login/data-access/guard/admin.guard.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
CanActivate
}
from
'@angular/router'
;
import
{
CanActivate
,
Router
}
from
'@angular/router'
;
@
Injectable
({
providedIn
:
'root'
,
})
export
class
AdminGuard
implements
CanActivate
{
constructor
()
{}
constructor
(
private
router
:
Router
)
{}
canActivate
():
boolean
{
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
;
}
}
}
This diff is collapsed.
Click to expand it.
src/app/+login/data-access/guard/auth.guard.ts
View file @
bc83c79b
import
{
Injectable
}
from
'@angular/core'
;
import
{
CanActivate
}
from
'@angular/router'
;
import
{
CanActivate
,
Router
}
from
'@angular/router'
;
@
Injectable
({
providedIn
:
'root'
,
})
export
class
AuthGuard
implements
CanActivate
{
constructor
()
{}
constructor
(
private
router
:
Router
)
{}
canActivate
():
boolean
{
const
token
=
localStorage
.
getItem
(
'token'
);
if
(
token
)
{
this
.
router
.
navigate
([
'/home'
]);
return
false
;
}
else
{
return
true
;
}
}
}
This diff is collapsed.
Click to expand it.
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"
>
<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-2xl tw-font-bold tw-text-center tw-text-gray-800"
>
Welcome Back!
</h2>
<p
class=
"tw-text-center tw-text-gray-600"
>
Please log in to your account
</p>
<h2
class=
"tw-text-3xl 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>
<!-- Username Field -->
<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-input-group
class=
"tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
...
...
@@ -25,9 +23,9 @@
</nz-form-control>
</nz-form-item>
<!-- Password Field -->
<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-input-group
class=
"tw-w-full"
>
<div
class=
"tw-relative tw-w-full"
>
...
...
@@ -45,17 +43,15 @@
</nz-input-group>
</nz-form-control>
</nz-form-item>
<!-- Submit Button -->
<p
*
ngIf=
"MgsError"
class=
"text-error tw-mb-4"
>
{{ MgsError }}
</p>
<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
'"
>
Log in
</button>
<!-- Register Link -->
<p
class=
"tw-text-center tw-text-gray-600 tw-mt-4"
>
Or
<a
class=
"tw-text-indigo-600 tw-font-semibold hover:tw-underline cursor-pointer"
>
register now!
</a>
...
...
This diff is collapsed.
Click to expand it.
src/app/+login/feature/login.component.scss
View file @
bc83c79b
...
...
@@ -12,6 +12,6 @@
.error-message
{
color
:
red
;
}
.button
{
background-color
:
#
3700ff
;
.button
-login
{
background-color
:
#
714afd
;
}
This diff is collapsed.
Click to expand it.
src/app/+login/feature/login.component.ts
View file @
bc83c79b
...
...
@@ -10,7 +10,7 @@ import { NzAlertModule } from 'ng-zorro-antd/alert';
import
{
CommonModule
}
from
'@angular/common'
;
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
{
response
}
from
'express'
;
@
Component
({
...
...
@@ -34,35 +34,42 @@ import { response } from 'express';
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
export
class
LoginComponent
implements
OnInit
{
MgsError
:
string
=
''
;
loginForm
:
FormGroup
;
constructor
(
private
fb
:
FormBuilder
,
private
authService
:
AuthService
)
{
this
.
loginForm
=
this
.
fb
.
group
({
user
n
ame
:
[
''
,
[
Validators
.
required
]],
user
N
ame
:
[
''
,
[
Validators
.
required
]],
password
:
[
''
,
[
Validators
.
required
]],
});
}
ngOnInit
()
{}
saveInfo
(
res
:
any
)
{
localStorage
.
setItem
(
'token'
,
res
.
responseData
.
token
);
localStorage
.
setItem
(
'expirationTime'
,
res
.
responseData
.
expirationTime
);
localStorage
.
setItem
(
'role'
,
res
.
responseData
.
role
);
}
onSubmit
()
{
const
headers
=
new
HttpHeaders
()
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
;
}
console
.
log
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
);
this
.
authService
.
login
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
).
pipe
(
tap
(()
=>
{
console
.
log
(
this
.
loginForm
.
value
.
userName
,
this
.
loginForm
.
value
.
password
);
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
)
=>
{
console
.
log
(
error
);
throw
error
;
catchError
((
err
)
=>
{
this
.
MgsError
=
err
.
message
;
console
.
log
(
this
.
MgsError
);
console
.
log
(
err
);
return
of
(
null
);
}),
finalize
(()
=>
{})
).
subscribe
(
response
=>
{
alert
(
response
.
message
);
}
);
finalize
(()
=>
{
// gọi ra khi observable hoàn tất
console
.
log
(
'Login request completed'
);
})
).
subscribe
();
}
}
This diff is collapsed.
Click to expand it.
src/custom/tailwind/_utilities.scss
View file @
bc83c79b
...
...
@@ -13,4 +13,7 @@
color
:
white
;
border
:
rgb
(
218
,
141
,
0
);
}
.bg-submit
{
background-color
:
#3700ff
;
}
}
This diff is collapsed.
Click to expand it.
src/environments/environment.development.ts
View file @
bc83c79b
export
const
environment
=
{
API_DOMAIN
:
'http
/
'
,
//custom
API_DOMAIN
:
'http
://localhost:3000
'
,
//custom
};
This diff is collapsed.
Click to expand it.
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