Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 19.27: Create the recover component
- Loading branch information
1 parent
9f93ba9
commit 51aa040
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {Component, OnInit, NgZone} from '@angular/core'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { Router } from '@angular/router'; | ||
import { Accounts } from 'meteor/accounts-base'; | ||
|
||
import template from './recover.component.html'; | ||
|
||
@Component({ | ||
selector: 'recover', | ||
template | ||
}) | ||
export class RecoverComponent implements OnInit { | ||
recoverForm: FormGroup; | ||
error: string; | ||
|
||
constructor(private router: Router, private zone: NgZone, private formBuilder: FormBuilder) {} | ||
|
||
ngOnInit() { | ||
this.recoverForm = this.formBuilder.group({ | ||
email: ['', Validators.required] | ||
}); | ||
|
||
this.error = ''; | ||
} | ||
|
||
recover() { | ||
if (this.recoverForm.valid) { | ||
Accounts.forgotPassword({ | ||
email: this.recoverForm.value.email | ||
}, (err) => { | ||
if (err) { | ||
this.zone.run(() => { | ||
this.error = err; | ||
}); | ||
} else { | ||
this.router.navigate(['/']); | ||
} | ||
}); | ||
} | ||
} | ||
} |