member_webapp/@overflow/member/component/member-modify-password.component.ts

73 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-05-28 05:41:56 +00:00
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
2018-05-30 07:44:21 +00:00
import {FormGroup, FormBuilder, Validators, FormControl, ValidationErrors, AbstractControl} from '@angular/forms';
import {Member} from '@overflow/commons-typescript/model/member';
2018-05-28 05:41:56 +00:00
@Component({
selector: 'of-member-modify-password',
templateUrl: './member-modify-password.component.html',
})
export class MemberModifyPasswordComponent implements OnInit {
@Input() token: string;
2018-05-30 07:44:21 +00:00
@Input() member: Member;
2018-05-28 11:16:00 +00:00
@Output() modifyPassword = new EventEmitter<{token: string, password: string, confirmPassword: string}>();
2018-05-28 05:41:56 +00:00
@Output() signin = new EventEmitter();
modifyPasswordForm: FormGroup;
2018-05-30 07:44:21 +00:00
password: AbstractControl;
pwConfirm: AbstractControl;
2018-05-28 05:41:56 +00:00
constructor(
private formBuilder: FormBuilder,
) { }
ngOnInit() {
this.initForm();
}
initForm() {
this.modifyPasswordForm = this.formBuilder.group({
2018-05-30 07:44:21 +00:00
'password': [
2018-05-28 05:41:56 +00:00
'',
[
2018-05-30 07:44:21 +00:00
Validators.required,
Validators.pattern('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$'),
Validators.minLength(6),
Validators.maxLength(25),
2018-05-28 05:41:56 +00:00
]
],
2018-05-30 07:44:21 +00:00
'pwConfirm': [
2018-05-28 05:41:56 +00:00
'',
[
2018-05-30 07:44:21 +00:00
Validators.compose([
Validators.required, this.pwMatchValidator
])
2018-05-28 05:41:56 +00:00
]
2018-05-30 07:44:21 +00:00
]
2018-05-28 05:41:56 +00:00
});
2018-05-30 07:44:21 +00:00
this.password = this.modifyPasswordForm.controls['password'];
this.pwConfirm = this.modifyPasswordForm.controls['pwConfirm'];
}
pwMatchValidator(control: FormControl): ValidationErrors {
let pw;
if (control.parent) {
pw = control.parent.controls['password'].value;
}
if (control.value !== pw) {
return { notMatched: true };
}
return null;
2018-05-28 05:41:56 +00:00
}
modifyPasswordFormSubmit() {
const formValue = Object.assign({}, this.modifyPasswordForm.value);
2018-05-28 11:16:00 +00:00
this.modifyPassword.emit({token: this.token, password: formValue.pw, confirmPassword: formValue.confirmPw});
2018-05-28 05:41:56 +00:00
}
2018-05-30 07:44:21 +00:00
onSignin() {
this.signin.emit();
}
2018-05-28 05:41:56 +00:00
}