Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
frag.jetzt SWTP 2022
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Marc Tröll
frag.jetzt SWTP 2022
Commits
d3b1ed75
Verified
Commit
d3b1ed75
authored
7 years ago
by
Lukas Maximilian Kimpel
Browse files
Options
Downloads
Patches
Plain Diff
Add error handling for username and password input
parent
9513d1db
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/login/login.component.html
+11
-9
11 additions, 9 deletions
src/app/login/login.component.html
src/app/login/login.component.ts
+14
-9
14 additions, 9 deletions
src/app/login/login.component.ts
with
25 additions
and
18 deletions
src/app/login/login.component.html
+
11
−
9
View file @
d3b1ed75
<mat-form-field
class=
"input-block"
>
<input
matInput
#userName
placeholder=
"Username"
/>
<mat-error
*ngIf=
"usernameErrorMessage !== ''"
>
{{ usernameErrorMessage }}
</mat-error>
</mat-form-field>
<form>
<mat-form-field
class=
"input-block"
>
<input
matInput
#userName
placeholder=
"Username"
[formControl]=
"usernameFormControl"
[errorStateMatcher]=
"matcher"
name=
"username"
/>
<mat-error
*ngIf=
"usernameFormControl.hasError('required')"
>
Username is
<strong>
required
</strong>
.
</mat-error>
</mat-form-field>
<mat-form-field
class=
"input-block"
>
<input
matInput
#userPassword
type=
"password"
placeholder=
"Password"
/>
<mat-error
*ngIf=
"password
ErrorMessage !== ''"
>
{{ passwordErrorMessage }}
</mat-error>
</mat-form-field>
<mat-form-field
class=
"input-block"
>
<input
matInput
#userPassword
type=
"password"
placeholder=
"Password"
[formControl]=
"passwordFormControl"
[errorStateMatcher]=
"matcher"
name=
"password"
/>
<mat-error
*ngIf=
"password
FormControl.hasError('required')"
>
Password is
<strong>
required
</strong>
.
</mat-error>
</mat-form-field>
<button
mat-raised-button
color=
"primary"
(click)=
"login(userName.value, userPassword.value)"
>
Login
</button>
<button
mat-raised-button
color=
"primary"
(click)=
"login(userName.value, userPassword.value)"
>
Login
</button>
</form>
This diff is collapsed.
Click to expand it.
src/app/login/login.component.ts
+
14
−
9
View file @
d3b1ed75
...
...
@@ -2,6 +2,15 @@ import { Component, OnInit } from '@angular/core';
import
{
AuthenticationService
}
from
'
../authentication.service
'
;
import
{
Router
}
from
'
@angular/router
'
;
import
{
NotificationService
}
from
'
../notification.service
'
;
import
{
ErrorStateMatcher
}
from
'
@angular/material
'
;
import
{
FormControl
,
FormGroupDirective
,
NgForm
,
ReactiveFormsModule
,
Validators
}
from
'
@angular/forms
'
;
export
class
LoginErrorStateMatcher
implements
ErrorStateMatcher
{
isErrorState
(
control
:
FormControl
|
null
,
form
:
FormGroupDirective
|
NgForm
|
null
):
boolean
{
const
isSubmitted
=
form
&&
form
.
submitted
;
return
!!
(
control
&&
control
.
invalid
&&
(
control
.
dirty
||
control
.
touched
||
isSubmitted
));
}
}
@
Component
({
selector
:
'
app-login
'
,
...
...
@@ -10,8 +19,10 @@ import { NotificationService } from '../notification.service';
})
export
class
LoginComponent
implements
OnInit
{
protected
usernameErrorMessage
=
''
;
protected
passwordErrorMessage
=
''
;
usernameFormControl
=
new
FormControl
(
''
,
[
Validators
.
required
]);
passwordFormControl
=
new
FormControl
(
''
,
[
Validators
.
required
]);
matcher
=
new
LoginErrorStateMatcher
();
constructor
(
public
authenticationService
:
AuthenticationService
,
public
router
:
Router
,
...
...
@@ -25,14 +36,8 @@ export class LoginComponent implements OnInit {
username
=
username
.
trim
();
password
=
password
.
trim
();
if
(
username
===
''
)
{
// ToDo: Handle username and password not correct event
this
.
usernameErrorMessage
=
'
Username is required
'
;
}
else
if
(
password
===
''
)
{
this
.
passwordErrorMessage
=
'
Password is required
'
;
}
else
{
if
(
username
!==
''
&&
password
!==
''
)
{
this
.
authenticationService
.
login
(
username
,
password
).
subscribe
(
loginSuccessful
=>
{
console
.
log
(
loginSuccessful
);
if
(
loginSuccessful
)
{
this
.
notificationService
.
show
(
'
Login successful!
'
);
this
.
router
.
navigate
([
'
rooms
'
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment