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
3ab62ff9
Verified
Commit
3ab62ff9
authored
7 years ago
by
Lukas Maximilian Kimpel
Browse files
Options
Downloads
Patches
Plain Diff
Implement password reset logic
Use angular-flex for form Implement FormControl and Matcher
parent
0cd8aba9
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/app/password-reset/password-reset.component.html
+6
-3
6 additions, 3 deletions
src/app/password-reset/password-reset.component.html
src/app/password-reset/password-reset.component.ts
+40
-2
40 additions, 2 deletions
src/app/password-reset/password-reset.component.ts
with
46 additions
and
5 deletions
src/app/password-reset/password-reset.component.html
+
6
−
3
View file @
3ab62ff9
<form>
<form
(ngSubmit)=
"resetPassword(email.value)"
fxLayout=
"column"
fxLayoutAlign=
"space-around"
fxLayoutGap=
"10px"
>
<mat-form-field
class=
"input-block"
>
<input
matInput
placeholder=
"E-Mail"
/>
<input
matInput
#email
placeholder=
"E-Mail"
[formControl]=
"usernameFormControl"
[errorStateMatcher]=
"matcher"
name=
"email"
/>
<mat-error
*ngIf=
"usernameFormControl.hasError('required')"
>
Email address is
<strong>
required
</strong>
.
</mat-error>
</mat-form-field>
<button
mat-raised-button
color=
"primary"
>
Submit
</button>
<button
mat-raised-button
color=
"primary"
(click)=
"resetPassword(email.value)"
>
Reset password
</button>
</form>
This diff is collapsed.
Click to expand it.
src/app/password-reset/password-reset.component.ts
+
40
−
2
View file @
3ab62ff9
import
{
Component
,
OnInit
}
from
'
@angular/core
'
;
import
{
Component
,
Inject
,
OnInit
}
from
'
@angular/core
'
;
import
{
FormControl
,
FormGroupDirective
,
NgForm
,
Validators
}
from
'
@angular/forms
'
;
import
{
ErrorStateMatcher
,
MAT_DIALOG_DATA
,
MatDialogRef
}
from
'
@angular/material
'
;
import
{
AuthenticationService
}
from
'
../authentication.service
'
;
import
{
NotificationService
}
from
'
../notification.service
'
;
import
{
RegisterComponent
}
from
'
../register/register.component
'
;
export
class
PasswordResetErrorStateMatcher
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-password-reset
'
,
...
...
@@ -7,9 +19,35 @@ import { Component, OnInit } from '@angular/core';
})
export
class
PasswordResetComponent
implements
OnInit
{
constructor
()
{
}
usernameFormControl
=
new
FormControl
(
''
,
[
Validators
.
required
,
Validators
.
email
]);
matcher
=
new
PasswordResetErrorStateMatcher
();
constructor
(
public
authenticationService
:
AuthenticationService
,
public
notificationService
:
NotificationService
,
public
dialogRef
:
MatDialogRef
<
RegisterComponent
>
,
@
Inject
(
MAT_DIALOG_DATA
)
public
data
:
any
)
{
}
ngOnInit
()
{
}
resetPassword
(
username
:
string
):
void
{
username
=
username
.
trim
();
if
(
username
)
{
this
.
authenticationService
.
resetPassword
(
username
).
subscribe
(
result
=>
{
if
(
result
)
{
this
.
notificationService
.
show
(
'
Password was reset. Please check your mail!
'
);
this
.
dialogRef
.
close
();
}
else
{
this
.
notificationService
.
show
(
'
Could not reset your password. Is your email address correct?
'
);
}
});
}
else
{
this
.
notificationService
.
show
(
'
Email address can not be empty.
'
);
}
}
}
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