2018-05-30 07:44:21 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
EventEmitter, Input
|
|
|
|
} from '@angular/core';
|
|
|
|
import {
|
|
|
|
FormGroup,
|
|
|
|
FormBuilder,
|
|
|
|
Validators,
|
|
|
|
AbstractControl
|
|
|
|
} from '@angular/forms';
|
2018-05-31 10:20:14 +00:00
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { Observable, of } from 'rxjs';
|
|
|
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
|
|
|
|
2018-05-31 12:11:31 +00:00
|
|
|
import { Member } from '@overflow/commons-typescript/model/member';
|
|
|
|
import { MemberService } from '../service/member.service';
|
2018-05-28 05:41:56 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-member-reset-password',
|
|
|
|
templateUrl: './member-reset-password.component.html',
|
|
|
|
})
|
|
|
|
export class MemberResetPasswordComponent implements OnInit {
|
2018-05-31 10:20:14 +00:00
|
|
|
// @Output() resetPassword = new EventEmitter<string>();
|
2018-05-30 07:44:21 +00:00
|
|
|
@Output() signin = new EventEmitter();
|
|
|
|
@Output() signup = new EventEmitter();
|
|
|
|
|
2018-05-31 10:20:14 +00:00
|
|
|
// @Input() member: Member;
|
|
|
|
member$: Observable<Member>;
|
|
|
|
pending$: Observable<boolean>;
|
|
|
|
error$: Observable<any>;
|
2018-05-28 05:41:56 +00:00
|
|
|
|
|
|
|
resetPasswordForm: FormGroup;
|
2018-05-30 05:52:39 +00:00
|
|
|
email: AbstractControl;
|
2018-05-28 05:41:56 +00:00
|
|
|
|
|
|
|
constructor(
|
2018-05-31 10:20:14 +00:00
|
|
|
private store: Store<any>,
|
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
private memberService: MemberService,
|
2018-05-28 05:41:56 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.resetPasswordForm = this.formBuilder.group({
|
|
|
|
'email': ['', [
|
|
|
|
Validators.required,
|
|
|
|
Validators.email
|
|
|
|
]
|
|
|
|
]
|
|
|
|
});
|
2018-05-30 05:52:39 +00:00
|
|
|
|
|
|
|
this.email = this.resetPasswordForm.controls['email'];
|
2018-05-28 05:41:56 +00:00
|
|
|
}
|
|
|
|
|
2018-05-30 07:44:21 +00:00
|
|
|
resetPasswordSubmit() {
|
2018-05-28 05:41:56 +00:00
|
|
|
const formValue = Object.assign({}, this.resetPasswordForm.value);
|
2018-05-31 10:20:14 +00:00
|
|
|
// this.resetPassword.emit(formValue.email);
|
|
|
|
this.memberService.sendEmailResetPassword(formValue.email)
|
|
|
|
.pipe(
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(true);
|
|
|
|
}),
|
|
|
|
map((rmember: Member) => {
|
|
|
|
this.member$ = of(rmember);
|
|
|
|
}),
|
2018-05-31 12:11:31 +00:00
|
|
|
catchError(err => {
|
2018-05-31 10:20:14 +00:00
|
|
|
this.error$ = of(err);
|
|
|
|
return of();
|
|
|
|
}),
|
|
|
|
tap(() => {
|
|
|
|
this.pending$ = of(false);
|
|
|
|
}),
|
2018-05-31 12:11:31 +00:00
|
|
|
).take(1).subscribe();
|
2018-05-28 05:41:56 +00:00
|
|
|
}
|
2018-05-30 07:44:21 +00:00
|
|
|
|
|
|
|
onSignin() {
|
|
|
|
this.signin.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
onSignup() {
|
|
|
|
this.signup.emit();
|
|
|
|
}
|
2018-05-31 10:20:14 +00:00
|
|
|
|
2018-05-28 05:41:56 +00:00
|
|
|
}
|