From 6a45d012b3d9ad1adbcc681b4e42637666159c26 Mon Sep 17 00:00:00 2001 From: geek Date: Sun, 6 May 2018 18:40:18 +0900 Subject: [PATCH] modify ing --- .../pages/auth/auth-page-routing.module.ts | 2 + src/app/pages/auth/auth-page.module.ts | 2 + .../modify-password-page.component.html | 1 + .../modify-password-page.component.spec.ts | 25 ++++++++ .../modify-password-page.component.ts | 21 +++++++ .../auth/signin/signin-page.component.ts | 5 -- src/packages/member/component/index.ts | 8 ++- .../modify-password.component.html | 46 ++++++++++++++ .../modify-password.component.spec.ts | 25 ++++++++ .../modify-password.component.ts | 63 +++++++++++++++++++ .../component/signin/signin.component.html | 1 - .../component/signin/signin.component.ts | 1 + src/packages/member/service/member.service.ts | 17 ++++- .../reset-password/reset-password.action.ts | 28 +++++++++ .../reset-password/reset-password.effect.ts | 14 +++++ .../reset-password/reset-password.reducer.ts | 27 ++++++++ 16 files changed, 276 insertions(+), 10 deletions(-) create mode 100644 src/app/pages/auth/reset-password/modify-password-page.component.html create mode 100644 src/app/pages/auth/reset-password/modify-password-page.component.spec.ts create mode 100644 src/app/pages/auth/reset-password/modify-password-page.component.ts create mode 100644 src/packages/member/component/reset-password/modify-password.component.html create mode 100644 src/packages/member/component/reset-password/modify-password.component.spec.ts create mode 100644 src/packages/member/component/reset-password/modify-password.component.ts diff --git a/src/app/pages/auth/auth-page-routing.module.ts b/src/app/pages/auth/auth-page-routing.module.ts index b2783e9..3cd13d6 100644 --- a/src/app/pages/auth/auth-page-routing.module.ts +++ b/src/app/pages/auth/auth-page-routing.module.ts @@ -5,6 +5,7 @@ import { AuthPageComponent } from './auth-page.component'; import { SigninPageComponent } from './signin/signin-page.component'; import { SignupPageComponent } from './signup/signup-page.component'; import { ResetPasswordPageComponent } from './reset-password/reset-password-page.component'; +import { ModifyPasswordPageComponent } from './reset-password/modify-password-page.component'; const routes: Routes = [ { @@ -15,6 +16,7 @@ const routes: Routes = [ { path: 'signin', component: SigninPageComponent }, { path: 'signup', component: SignupPageComponent }, { path: 'reset-password', component: ResetPasswordPageComponent }, + { path: 'modify-password', component: ModifyPasswordPageComponent } ] } ]; diff --git a/src/app/pages/auth/auth-page.module.ts b/src/app/pages/auth/auth-page.module.ts index 4cd8f32..e0957ee 100644 --- a/src/app/pages/auth/auth-page.module.ts +++ b/src/app/pages/auth/auth-page.module.ts @@ -9,12 +9,14 @@ import { AuthPageRoutingModule } from './auth-page-routing.module'; import { SigninPageComponent } from './signin/signin-page.component'; import { SignupPageComponent } from './signup/signup-page.component'; import { ResetPasswordPageComponent } from './reset-password/reset-password-page.component'; +import {ModifyPasswordPageComponent} from './reset-password/modify-password-page.component'; export const COMPONENTS = [ AuthPageComponent, SigninPageComponent, SignupPageComponent, ResetPasswordPageComponent, + ModifyPasswordPageComponent, ]; @NgModule({ diff --git a/src/app/pages/auth/reset-password/modify-password-page.component.html b/src/app/pages/auth/reset-password/modify-password-page.component.html new file mode 100644 index 0000000..8838c53 --- /dev/null +++ b/src/app/pages/auth/reset-password/modify-password-page.component.html @@ -0,0 +1 @@ + diff --git a/src/app/pages/auth/reset-password/modify-password-page.component.spec.ts b/src/app/pages/auth/reset-password/modify-password-page.component.spec.ts new file mode 100644 index 0000000..69d2e46 --- /dev/null +++ b/src/app/pages/auth/reset-password/modify-password-page.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ModifyPasswordPageComponent } from './modify-password-page.component'; + +describe('ModifyPasswordPageComponent', () => { + let component: ModifyPasswordPageComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ModifyPasswordPageComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ModifyPasswordPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/pages/auth/reset-password/modify-password-page.component.ts b/src/app/pages/auth/reset-password/modify-password-page.component.ts new file mode 100644 index 0000000..d099e26 --- /dev/null +++ b/src/app/pages/auth/reset-password/modify-password-page.component.ts @@ -0,0 +1,21 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { Form, FormBuilder, FormGroup, FormGroupDirective, FormControl, NgForm, Validators } from '@angular/forms'; + +@Component({ + selector: 'of-pages-modify-password', + templateUrl: './modify-password-page.component.html', +}) +export class ModifyPasswordPageComponent implements OnInit { + toenURL: string; + + constructor( + private router: Router, + private activatedRoute: ActivatedRoute, + ) { } + + ngOnInit() { + this.toenURL = this.activatedRoute.snapshot.queryParams['token']; + } + +} diff --git a/src/app/pages/auth/signin/signin-page.component.ts b/src/app/pages/auth/signin/signin-page.component.ts index b15d9f4..21b3d16 100644 --- a/src/app/pages/auth/signin/signin-page.component.ts +++ b/src/app/pages/auth/signin/signin-page.component.ts @@ -9,7 +9,6 @@ import { Form, FormBuilder, FormGroup, FormGroupDirective, FormControl, NgForm, }) export class SigninPageComponent implements OnInit { - signInForm: FormGroup; returnURL: string; constructor( @@ -20,8 +19,4 @@ export class SigninPageComponent implements OnInit { ngOnInit() { this.returnURL = this.activatedRoute.snapshot.queryParams['returnURL'] || '/'; } - - initForm() { - } - } diff --git a/src/packages/member/component/index.ts b/src/packages/member/component/index.ts index 87ad642..3258093 100644 --- a/src/packages/member/component/index.ts +++ b/src/packages/member/component/index.ts @@ -2,15 +2,17 @@ import { ProfileComponent } from './profile/profile.component'; import { SigninComponent } from './signin/signin.component'; import { SignupComponent } from './signup/signup.component'; import { ResetPasswordComponent } from './reset-password/reset-password.component'; -import {SETTINGS_COMPONENTS} from './settings'; -import {PolicyComponent} from './policy/policy.component'; -import {TermsComponent} from './terms/terms.component'; +import { SETTINGS_COMPONENTS } from './settings'; +import { PolicyComponent } from './policy/policy.component'; +import { TermsComponent } from './terms/terms.component'; +import { ModifyPasswordComponent } from './reset-password/modify-password.component'; export const COMPONENTS = [ ProfileComponent, SigninComponent, SignupComponent, ResetPasswordComponent, + ModifyPasswordComponent, PolicyComponent, TermsComponent, SETTINGS_COMPONENTS, diff --git a/src/packages/member/component/reset-password/modify-password.component.html b/src/packages/member/component/reset-password/modify-password.component.html new file mode 100644 index 0000000..63bf9f8 --- /dev/null +++ b/src/packages/member/component/reset-password/modify-password.component.html @@ -0,0 +1,46 @@ +
+ + + + + +
diff --git a/src/packages/member/component/reset-password/modify-password.component.spec.ts b/src/packages/member/component/reset-password/modify-password.component.spec.ts new file mode 100644 index 0000000..2a7b14d --- /dev/null +++ b/src/packages/member/component/reset-password/modify-password.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ModifyPasswordComponent } from './modify-password-page.component'; + +describe('ModifyPasswordPageComponent', () => { + let component: ModifyPasswordComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ModifyPasswordComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ModifyPasswordComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/packages/member/component/reset-password/modify-password.component.ts b/src/packages/member/component/reset-password/modify-password.component.ts new file mode 100644 index 0000000..bfb40b0 --- /dev/null +++ b/src/packages/member/component/reset-password/modify-password.component.ts @@ -0,0 +1,63 @@ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import * as ModifyPasswordStore from '../../store/reset-password'; +import {select, Store} from '@ngrx/store'; +import { ResetPasswordSelector } from '../../store'; + +@Component({ + selector: 'of-member-modify-password', + templateUrl: './modify-password.component.html', +}) +export class ModifyPasswordComponent implements OnInit { + + modifyPwForm: FormGroup; + tokenURL: string; + formErrors = { + 'pw': '', + 'confirmPw': '' + }; + + constructor( + private router: Router, + private activatedRoute: ActivatedRoute, + private formBuilder: FormBuilder, + private modifyPasswordStore: Store, + ) { } + + ngOnInit() { + this.tokenURL = this.activatedRoute.snapshot.queryParams['token']; + console.log(this.tokenURL); + this.initForm(); + } + + initForm() { + this.modifyPwForm = this.formBuilder.group({ + 'pw': [ + '', + [ + // Validators.required, + ] + ], + 'confirmPw': [ + '', + [ + // Validators.pattern('^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$'), + // Validators.minLength(6), + // Validators.maxLength(25) + ] + ], + }); + + } + + modifyPw() { + const modifyPwValue = Object.assign({}, this.modifyPwForm.value); + const m = {token: this.tokenURL, pw: modifyPwValue.pw, confirmPw: modifyPwValue.confirmPw}; + this.modifyPasswordStore.dispatch(new ModifyPasswordStore.ModifyPassword(m)); + } + + signinBtn() { + this.router.navigateByUrl('/auth/signin'); + } +} diff --git a/src/packages/member/component/signin/signin.component.html b/src/packages/member/component/signin/signin.component.html index 2c5b9fa..a3655ca 100644 --- a/src/packages/member/component/signin/signin.component.html +++ b/src/packages/member/component/signin/signin.component.html @@ -1,4 +1,3 @@ -
diff --git a/src/packages/member/component/signin/signin.component.ts b/src/packages/member/component/signin/signin.component.ts index 14d6603..fbc8894 100644 --- a/src/packages/member/component/signin/signin.component.ts +++ b/src/packages/member/component/signin/signin.component.ts @@ -88,4 +88,5 @@ export class SigninComponent implements OnInit { this.store.dispatch(new AuthStore.Signin(signinValue)); console.log('signin component signin fnc'); } + } diff --git a/src/packages/member/service/member.service.ts b/src/packages/member/service/member.service.ts index d9f1685..6862462 100644 --- a/src/packages/member/service/member.service.ts +++ b/src/packages/member/service/member.service.ts @@ -50,6 +50,21 @@ export class MemberService { } public sendEmailResetPassword(email: string): Observable { - return this.rpcService.call('MemberService.sendEmailForPassword', email); + // return this.rpcService.call('MemberService.sendEmailForPassword', email); + return this.restService.request('post', '/account/send_email_pw', { + body: { + signinID: email, + }, + }); + } + public resetPassword(token: string, pw: string, confirmPw: string): Observable { + // return this.rpcService.call('MemberService.sendEmailForPassword', email); + return this.restService.request('post', '/account/reset_password', { + body: { + token: token, + pw: pw, + confirmPw: confirmPw, + }, + }); } } diff --git a/src/packages/member/store/reset-password/reset-password.action.ts b/src/packages/member/store/reset-password/reset-password.action.ts index 67dd341..a870fac 100644 --- a/src/packages/member/store/reset-password/reset-password.action.ts +++ b/src/packages/member/store/reset-password/reset-password.action.ts @@ -32,4 +32,32 @@ export type Actions = | ResetPassword | ResetPasswordSuccess | ResetPasswordFailure + | ModifyPassword + | ModifyPasswordSuccess + | ModifyPasswordFailure ; + + +export enum ActionType { + ModifyPassword = '[member.modifyPassword] ModifyPassword', + ModifyPasswordSuccess = '[member.modifyPassword] ModifyPasswordSuccess', + ModifyPasswordFailure = '[member.modifyPassword] ModifyPasswordFailure', +} + +export class ModifyPassword implements Action { + readonly type = ActionType.ModifyPassword; + + constructor(public payload: { token: string, pw: string, confirmPw: string } ) {} +} + +export class ModifyPasswordSuccess implements Action { + readonly type = ActionType.ModifyPasswordSuccess; + + constructor(public payload: Member) {} +} + +export class ModifyPasswordFailure implements Action { + readonly type = ActionType.ModifyPasswordFailure; + + constructor(public payload: RESTClientError) {} +} diff --git a/src/packages/member/store/reset-password/reset-password.effect.ts b/src/packages/member/store/reset-password/reset-password.effect.ts index 555b754..376b933 100644 --- a/src/packages/member/store/reset-password/reset-password.effect.ts +++ b/src/packages/member/store/reset-password/reset-password.effect.ts @@ -19,6 +19,9 @@ import { ResetPassword, ResetPasswordSuccess, ResetPasswordFailure, + ModifyPassword, + ModifyPasswordSuccess, + ModifyPasswordFailure, ActionType } from './reset-password.action'; @@ -42,6 +45,17 @@ export class Effects { .catch(error => of(new ResetPasswordFailure(error))) ); + @Effect() + ModifyPassword$: Observable = this.actions$ + .ofType(ActionType.ModifyPassword) + .map((action: ModifyPassword) => action.payload) + .exhaustMap(payload => + this.memberService + .resetPassword(payload.token, payload.pw, payload.confirmPw) + .map(_member => new ModifyPasswordSuccess(_member)) + .catch(error => of(new ModifyPasswordFailure(error))) + ); + // // @Effect({ dispatch: false }) // ResetPasswordSuccess$ = this.actions$ // .ofType(ActionType.ResetPasswordSuccess) diff --git a/src/packages/member/store/reset-password/reset-password.reducer.ts b/src/packages/member/store/reset-password/reset-password.reducer.ts index d027272..7a13c7b 100644 --- a/src/packages/member/store/reset-password/reset-password.reducer.ts +++ b/src/packages/member/store/reset-password/reset-password.reducer.ts @@ -36,8 +36,35 @@ export function reducer(state = initialState, action: Actions): State { }; } + case ActionType.ModifyPassword: { + return { + ...state, + error: null, + pending: true, + }; + } + + case ActionType.ModifyPasswordSuccess: { + return { + ...state, + error: null, + pending: false, + member: action.payload, + }; + } + + case ActionType.ModifyPasswordFailure: { + return { + ...state, + error: action.payload, + pending: false, + member: null, + }; + } + default: { return state; } } } +