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
aba3496f
Commit
aba3496f
authored
Oct 31, 2024
by
vtduong0912
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
a0c87f85
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
41 deletions
+51
-41
login.model.ts
src/app/+login/data-access/model/login.model.ts
+3
-5
login.component.html
src/app/+login/feature/login.component.html
+15
-11
login.component.ts
src/app/+login/feature/login.component.ts
+33
-25
No files found.
src/app/+login/data-access/model/login.model.ts
View file @
aba3496f
export
namespace
Login
{
export
namespace
Login
{
export
type
Response
=
{
export
type
Response
=
{
user
:
{
token
:
string
,
username
:
string
,
expirationTime
:
number
,
role
:
string
,
role
:
string
},
accessToken
:
string
,
};
};
export
type
Request
=
{
export
type
Request
=
{
...
...
src/app/+login/feature/login.component.html
View file @
aba3496f
...
@@ -5,30 +5,36 @@
...
@@ -5,30 +5,36 @@
>
>
<form
nz-form
[
formGroup
]="
signInFormGroup
"
>
<form
nz-form
[
formGroup
]="
signInFormGroup
"
>
<nz-form-item>
<nz-form-item>
<nz-form-control>
<nz-form-control
nzErrorTip=
"Please input your username!"
>
<nz-input-group>
<nz-input-group
class=
"tw-h-12"
>
<input
<input
type=
"text"
type=
"text"
nz-input
nz-input
id=
"username_input"
placeholder=
"Username"
placeholder=
"Username"
class=
"tw-
h-10 tw-
text-sm tw-rounded-md"
class=
"tw-text-sm tw-rounded-md"
formControlName=
"username"
formControlName=
"username"
/>
/>
</nz-input-group>
</nz-input-group>
</nz-form-control>
</nz-form-control>
</nz-form-item>
</nz-form-item>
<nz-form-item>
<nz-form-item>
<nz-form-control>
<nz-form-control
nzErrorTip=
"Please input your password!"
>
<nz-input-group>
<nz-input-group
[
nzSuffix
]="
suffixTemplate
"
class=
"tw-h-12"
>
<input
<input
type=
"password"
type=
"password"
nz-input
nz-input
id=
"password_input
"
[
type
]="
passwordVisible
?
'
text
'
:
'
password
'
"
placeholder=
"Password"
placeholder=
"Password"
class=
"tw-
h-10 tw-
text-sm tw-rounded-md"
class=
"tw-text-sm tw-rounded-md"
formControlName=
"password"
formControlName=
"password"
/>
/>
<ng-template
#
suffixTemplate
>
<span
nz-icon
[
nzType
]="
passwordVisible
?
'
eye-invisible
'
:
'
eye
'"
(
click
)="
passwordVisible =
!passwordVisible"
></span>
</ng-template>
</nz-input-group>
</nz-input-group>
</nz-form-control>
</nz-form-control>
</nz-form-item>
</nz-form-item>
...
@@ -37,9 +43,7 @@
...
@@ -37,9 +43,7 @@
</div>
</div>
<nz-form-item>
<nz-form-item>
<nz-form-control>
<nz-form-control>
<label
nz-checkbox
<label
nz-checkbox
>
Remember me
</label>
>
Remember me
</label
>
</nz-form-control>
</nz-form-control>
</nz-form-item>
</nz-form-item>
<div></div>
<div></div>
...
...
src/app/+login/feature/login.component.ts
View file @
aba3496f
...
@@ -36,51 +36,59 @@ import { Router } from '@angular/router';
...
@@ -36,51 +36,59 @@ import { Router } from '@angular/router';
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
})
export
class
LoginComponent
implements
OnInit
{
export
class
LoginComponent
implements
OnInit
{
errorMsg
?:
string
;
passwordVisible
:
boolean
=
false
;
errorMsg
:
string
=
""
;
signInFormGroup
!
:
FormGroup
;
signInFormGroup
!
:
FormGroup
;
// isEdit: boolean = false;
constructor
(
constructor
(
private
_f
ormBuilder
:
FormBuilder
,
private
_f
b
:
FormBuilder
,
private
_authService
:
AuthService
,
private
_authService
:
AuthService
,
private
_changeDetectorRef
:
ChangeDetectorRef
,
private
_changeDetectorRef
:
ChangeDetectorRef
,
private
_router
:
Router
private
_router
:
Router
)
{}
)
{
this
.
signInFormGroup
=
this
.
_fb
.
group
({
username
:
[
''
,
[
Validators
.
required
,
validateUsername
]],
password
:
[
''
,
Validators
.
required
],
});
}
ngOnInit
():
void
{
ngOnInit
():
void
{
this
.
signInFormGroup
=
this
.
_formBuilder
.
group
({
username
:
[
null
,
[
Validators
.
required
,
validateUsername
]],
password
:
[
null
,
Validators
.
required
],
});
}
}
onLogin
()
{
onLogin
()
{
const
data
=
this
.
signInFormGroup
.
value
;
const
data
=
this
.
signInFormGroup
.
value
;
if
(
!
this
.
signInFormGroup
.
valid
)
{
Object
.
values
(
this
.
signInFormGroup
.
controls
).
forEach
(
control
=>
{
if
(
control
.
invalid
)
{
control
.
markAsDirty
();
control
.
updateValueAndValidity
({
onlySelf
:
true
});
}
});
return
;
}
this
.
signInFormGroup
.
markAllAsTouched
();
this
.
signInFormGroup
.
markAllAsTouched
();
this
.
_authService
.
loginPost
(
data
)
this
.
_authService
.
loginPost
(
data
)
.
pipe
(
.
pipe
(
tap
((
response
:
ResponseResult
<
Login
.
Response
>
)
=>
{
tap
((
response
:
ResponseResult
<
Login
.
Response
>
)
=>
{
this
.
onSuccess
(
response
);
this
.
onSuccess
(
response
);
}),
}),
catchError
((
error
:
ResponseResult
<
any
>
)
=>
{
catchError
((
error
:
ResponseResult
<
any
>
)
=>
{
this
.
onError
(
error
);
this
.
onError
(
error
);
return
of
(
null
);
return
of
(
null
);
})
})
)
)
.
subscribe
();
.
subscribe
();
}
}
onSuccess
(
response
:
ResponseResult
<
Login
.
Response
>
)
{
onSuccess
(
response
:
ResponseResult
<
Login
.
Response
>
)
{
localStorage
.
setItem
(
"token"
,
JSON
.
stringify
(
response
.
responseData
?.
accessT
oken
)
??
""
);
localStorage
.
setItem
(
"token"
,
JSON
.
stringify
(
response
.
responseData
?.
t
oken
)
??
""
);
localStorage
.
setItem
(
"role"
,
JSON
.
stringify
(
response
.
responseData
?.
user
.
role
)
??
""
);
localStorage
.
setItem
(
"role"
,
JSON
.
stringify
(
response
.
responseData
?.
role
)
??
""
);
this
.
_router
.
navigate
([
'/home'
]);
this
.
_router
.
navigate
([
'/home'
]);
}
}
onError
(
error
:
ResponseResult
<
any
>
)
{
onError
(
error
:
ResponseResult
<
any
>
)
{
if
(
error
.
status
===
401
)
{
this
.
errorMsg
=
"Invalid username or password!"
;
this
.
errorMsg
=
"Invalid username or password!"
;
}
else
{
this
.
errorMsg
=
"An error has occurred! Please try later."
;
}
this
.
_changeDetectorRef
.
markForCheck
();
this
.
_changeDetectorRef
.
markForCheck
();
}
}
}
}
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