member_webapp/src/packages/member/component/signup/signup.component.ts

109 lines
2.7 KiB
TypeScript
Raw Normal View History

2018-04-06 06:59:49 +00:00
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
2018-04-10 10:19:41 +00:00
import { FormGroup, FormBuilder, Validators, AbstractControl, FormControl } from '@angular/forms';
2018-05-02 08:09:39 +00:00
import { Member } from '@overflow/commons-typescript/model/member';
2018-04-12 08:06:15 +00:00
import * as AuthStore from '../../store/signup';
import {Store} from '@ngrx/store';
2018-04-06 06:59:49 +00:00
@Component({
selector: 'of-member-signup',
templateUrl: './signup.component.html',
})
export class SignupComponent implements OnInit {
signupForm: FormGroup;
2018-04-10 10:19:41 +00:00
email: AbstractControl;
password: AbstractControl;
pwConfirm: AbstractControl;
name: AbstractControl;
phone: AbstractControl;
company: AbstractControl;
2018-04-06 06:59:49 +00:00
constructor(
private router: Router,
2018-04-12 08:06:15 +00:00
private formBuilder: FormBuilder,
private store: Store<AuthStore.State>,
2018-04-06 06:59:49 +00:00
) { }
ngOnInit() {
this.initForm();
}
initForm() {
this.signupForm = this.formBuilder.group({
2018-04-12 08:06:15 +00:00
'email': [
'geekhot@hotmail.co.kr',
[
Validators.required,
Validators.email
]
2018-04-06 06:59:49 +00:00
],
2018-04-12 08:06:15 +00:00
'password': [
'!@#$Qwer1234',
[
Validators.required,
Validators.pattern('^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$'),
Validators.minLength(6),
Validators.maxLength(25),
]
2018-04-06 06:59:49 +00:00
],
2018-04-12 08:06:15 +00:00
'pwConfirm': [
'!@#$Qwer1234',
[
Validators.compose([
2018-04-10 10:19:41 +00:00
Validators.required, this.pwMatchValidator
])
2018-04-12 08:06:15 +00:00
]
2018-04-06 06:59:49 +00:00
],
2018-04-12 08:06:15 +00:00
'name': [
'Park',
[
Validators.required
]
2018-04-06 06:59:49 +00:00
],
2018-04-12 08:06:15 +00:00
'phone': [
'010-3040-0303',
[
Validators.required
]
2018-04-06 06:59:49 +00:00
],
2018-04-12 08:06:15 +00:00
'company': [
'atgame',
[
Validators.required
]
2018-04-06 06:59:49 +00:00
],
2018-04-10 10:19:41 +00:00
});
this.email = this.signupForm.controls['email'];
this.password = this.signupForm.controls['password'];
this.pwConfirm = this.signupForm.controls['pwConfirm'];
this.name = this.signupForm.controls['name'];
this.phone = this.signupForm.controls['phone'];
this.company = this.signupForm.controls['company'];
2018-04-10 07:30:05 +00:00
}
2018-04-10 10:19:41 +00:00
pwMatchValidator(control: FormControl): { [s: string]: boolean } {
let pw;
if (control.parent) {
pw = control.parent.controls['password'].value;
}
if (control.value !== pw) {
return { notMatched: true };
}
}
2018-04-06 06:59:49 +00:00
2018-04-10 07:30:05 +00:00
signup() {
2018-04-12 08:06:15 +00:00
const signupValue = Object.assign({}, this.signupForm.value);
const password = signupValue.password;
2018-04-10 10:19:41 +00:00
const member: Member = {
2018-04-12 08:06:15 +00:00
email: signupValue.email,
name: signupValue.name,
phone: signupValue.phone,
companyName: signupValue.company,
2018-04-10 10:19:41 +00:00
};
2018-04-12 08:06:15 +00:00
this.store.dispatch(new AuthStore.Signup({member, password}));
2018-04-10 10:19:41 +00:00
console.log(member);
2018-04-06 06:59:49 +00:00
}
}