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
548eb41b
Commit
548eb41b
authored
Oct 24, 2024
by
tinhbe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
task Login
parent
f87a738f
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
2059 additions
and
2039 deletions
+2059
-2039
package-lock.json
package-lock.json
+659
-313
ApiService.service.ts
src/app/+login/data-access/Services/ApiService.service.ts
+20
-0
login.component.html
src/app/+login/feature/login.component.html
+33
-0
login.component.scss
src/app/+login/feature/login.component.scss
+22
-0
login.component.ts
src/app/+login/feature/login.component.ts
+32
-5
yarn.lock
yarn.lock
+1293
-1721
No files found.
package-lock.json
View file @
548eb41b
This diff is collapsed.
Click to expand it.
src/app/+login/data-access/Services/ApiService.service.ts
0 → 100644
View file @
548eb41b
import
{
Injectable
}
from
'@angular/core'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
Observable
}
from
'rxjs'
;
@
Injectable
({
providedIn
:
'root'
,
})
export
class
AuthService
{
private
apiUrl
=
'http://localhost:3000/login'
;
constructor
(
private
http
:
HttpClient
)
{}
login
(
username
:
string
,
password
:
string
):
Observable
<
any
>
{
const
headers
=
new
HttpHeaders
({
'Content-Type'
:
'application/json'
});
const
body
=
{
username
,
password
};
return
this
.
http
.
post
<
any
>
(
this
.
apiUrl
,
body
,
{
headers
});
}
}
src/app/+login/feature/login.component.html
View file @
548eb41b
<form
[
formGroup
]="
loginForm
"
(
ngSubmit
)="
onSubmit
()"
class=
"tw-max-w-md tw-mx-auto tw-bg-white tw-p-8 tw-shadow-md tw-rounded-lg"
>
<div
class=
"tw-text-50px tw-font-bold tw-pb-10 tw-mx-auto tw-text-center"
>
Login
</div>
<div
class=
"tw-mb-4"
>
<label
for=
"username"
class=
"tw-block tw-text-gray-700 tw-font-bold tw-mb-2"
>
Username
</label>
<input
id=
"username"
type=
"text"
formControlName=
"username"
class=
"tw-shadow tw-appearance-none tw-border tw-rounded tw-w-full tw-py-2 tw-px-3 tw-text-gray-700 leading-tight focus:tw-outline-none"
>
<div
*
ngIf=
"loginForm.get('username')?.invalid && loginForm.get('username')?.touched"
class=
" tw-text-xs tw-mt-2 text-error"
>
Username is required.
</div>
</div>
<div
class=
"tw-mb-6"
>
<label
for=
"password"
class=
"tw-block tw-text-gray-700 tw-font-bold tw-mb-2"
>
Password
</label>
<input
id=
"password"
type=
"password"
formControlName=
"password"
class=
"tw-shadow tw-appearance-none tw-border tw-rounded tw-w-full tw-py-2 tw-px-3 tw-text-gray-700 leading-tight focus:tw-outline-none"
>
<div
*
ngIf=
"loginForm.get('password')?.invalid && loginForm.get('password')?.touched"
class=
"tw-text-xs tw-mt-2 text-error"
>
Password must be at least 6 characters long.
</div>
</div>
<div
class=
"tw-flex tw-items-center tw-justify-between tw-mb-4"
>
<a
routerLink=
"/#"
class=
"tw-inline-block tw-align-baseline tw-font-bold tw-text-sm tw-text-blue-500 hover:tw-text-blue-800"
>
Forgot password?
</a>
</div>
<div>
<button
class=
"tw-bg-blue-500 tw-text-white tw-font-bold tw-py-2 tw-px-4 tw-rounded focus:tw-outline-none focus:tw-shadow-outline tw-w-full"
type=
"submit"
[
disabled
]="
loginForm
.
invalid
"
>
Login
</button>
</div>
<div
class=
"tw-text-center tw-mt-4"
>
<a
routerLink=
"/#"
class=
"tw-text-sm tw-text-blue-500 hover:tw-text-blue-800"
>
Register now!
</a>
</div>
</form>
src/app/+login/feature/login.component.scss
View file @
548eb41b
.form-container
{
max-width
:
400px
;
margin
:
auto
;
padding
:
20px
;
background-color
:
white
;
border-radius
:
8px
;
box-shadow
:
0
2px
10px
rgba
(
0
,
0
,
0
,
0
.1
);
}
button
{
background-color
:
#1D4ED8
;
/* Tailwind's blue-500 */
color
:
white
;
padding
:
10px
15px
;
border
:
none
;
border-radius
:
4px
;
width
:
100%
;
cursor
:
pointer
;
font-size
:
16px
;
}
.error-message
{
color
:
red
;
}
src/app/+login/feature/login.component.ts
View file @
548eb41b
import
{
ChangeDetectionStrategy
,
Component
,
OnInit
}
from
'@angular/core'
;
import
{
HttpClient
,
HttpHeaders
}
from
'@angular/common/http'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
FormBuilder
,
FormGroup
,
FormsModule
,
ReactiveFormsModule
,
Validators
}
from
'@angular/forms'
;
import
{
catchError
,
Observable
}
from
'rxjs'
;
import
{
AuthService
}
from
'../data-access/Services/ApiService.service'
;
import
{
response
}
from
'express'
;
@
Component
({
selector
:
'meu-login'
,
standalone
:
true
,
templateUrl
:
'./login.component.html'
,
styleUrls
:
[
'./login.component.scss'
],
imports
:
[
CommonModule
],
imports
:
[
CommonModule
,
FormsModule
,
ReactiveFormsModule
],
changeDetection
:
ChangeDetectionStrategy
.
OnPush
,
})
export
class
LoginComponent
implements
OnInit
{
constructor
()
{}
loginForm
:
FormGroup
;
constructor
(
private
fb
:
FormBuilder
,
private
authService
:
AuthService
)
{
this
.
loginForm
=
this
.
fb
.
group
({
username
:
[
''
,
[
Validators
.
required
]],
password
:
[
''
,
[
Validators
.
required
]],
});
}
ngOnInit
()
{}
onSubmit
()
{
const
headers
=
new
HttpHeaders
()
if
(
!
this
.
loginForm
.
valid
)
{
alert
(
'vui lòng nhập đầy đủ thông tin'
);
return
;
}
console
.
log
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
);
this
.
authService
.
login
(
this
.
loginForm
.
value
.
username
,
this
.
loginForm
.
value
.
password
).
pipe
(
catchError
((
error
)
=>
{
console
.
log
(
error
);
throw
error
;
})
).
subscribe
(
response
=>
{
alert
(
response
.
message
);
}
);
}
}
yarn.lock
View file @
548eb41b
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