diff --git a/src/packages/settings/member/component/totp/totp.component.ts b/src/packages/settings/member/component/totp/totp.component.ts index b9ed48f..98adae1 100644 --- a/src/packages/settings/member/component/totp/totp.component.ts +++ b/src/packages/settings/member/component/totp/totp.component.ts @@ -3,9 +3,12 @@ import { ActivatedRoute, Router } from '@angular/router'; import * as TotpStore from '../../store/totp'; import { Store, select } from '@ngrx/store'; import { FormGroup, FormBuilder, Validators } from '@angular/forms'; + +import { AuthSelector } from 'packages/member/store'; + + import { TotpSelector } from '../../store'; -import {AuthSelector} from "../../../../member/store/index"; -import {Member} from "../../../../member/model/Member"; +import { Member } from 'packages/member/model/Member'; @Component({ selector: 'of-totp', @@ -51,6 +54,29 @@ export class TotpComponent implements OnInit { }); } + // ngAfterContentInit() { + // + // this.listStore.select(AuthSelector.select('member')).subscribe( + // (member: Member) => { + // this.store.dispatch(new TotpRegistStore.createTotp(member)); + // }, + // (error) => { + // console.log(error); + // } + // ); + // + // this.probes$.subscribe( + // (probes: boo) => { + // console.log(probes); + // this.dataSource = new MatTableDataSource(probes); + // this.dataSource.sort = this.sort; + // }, + // (error: RPCError) => { + // console.log(error.response.message); + // } + // ); + // + // } registClick() { const code = this.totpForm.value['code']; const secretCode = 'X6AWAK573M5372NM'; diff --git a/src/packages/settings/member/service/member-totp.service.ts b/src/packages/settings/member/service/member-totp.service.ts index 36aff5b..d3629fc 100644 --- a/src/packages/settings/member/service/member-totp.service.ts +++ b/src/packages/settings/member/service/member-totp.service.ts @@ -16,7 +16,7 @@ export class MemberTotpService { public createTotp(member: Member): Observable { // Todo Store get member object - return this.rpcClient.call('MemberTotpService.createTotp', {Member: {id:1}}); + return this.rpcClient.call('MemberTotpService.createTotp', {Member: member}); } public regist(member: Member, secretCode: string, code: string): Observable { @@ -27,4 +27,8 @@ export class MemberTotpService { // }; return this.rpcClient.call('MemberTotpService.regist', member, secretCode, code); } + + public checkCodeForMember(member: Member, code: string): Observable { + return this.rpcClient.call('MemberTotpService.checkCodeForMember', member, code); + } } diff --git a/src/packages/settings/member/store/totp/totp.action.ts b/src/packages/settings/member/store/totp/totp.action.ts index 6797de9..4315eb6 100644 --- a/src/packages/settings/member/store/totp/totp.action.ts +++ b/src/packages/settings/member/store/totp/totp.action.ts @@ -5,13 +5,17 @@ import { RESTError } from 'packages/core/rest/error'; import { Member } from '../../../../member/model'; export enum ActionType { - CreateTotp = '[member.totp] CreateTotp', - CreateTotpSuccess = '[member.totp] CreateTotpSuccess', - CreateTotpFailure = '[member.totp] CreateTotpFailure', + CreateTotp = '[member.totp] CreateTotp', + CreateTotpSuccess = '[member.totp] CreateTotpSuccess', + CreateTotpFailure = '[member.totp] CreateTotpFailure', - Regist = '[member.totp] Regist', - RegistSuccess = '[member.totp] RegistSuccess', - RegistFailure = '[member.totp] RegistFailure', + Regist = '[member.totp] Regist', + RegistSuccess = '[member.totp] RegistSuccess', + RegistFailure = '[member.totp] RegistFailure', + + CheckCodeForMember = '[member.totp] CheckCodeForMember', + CheckCodeForMemberSuccess = '[member.totp] CheckCodeForMemberSuccess', + CheckCodeForMemberFailure = '[member.totp] CheckCodeForMemberFailure', } export class CreateTotp implements Action { @@ -52,6 +56,26 @@ export class RegistFailure implements Action { constructor(public payload: RESTError) {} } +// ---------------------------------------------------------------------------------------- + +export class CheckCodeForMember implements Action { + readonly type = ActionType.CheckCodeForMember; + + constructor(public payload: {member: Member, code: string}) {} +} + +export class CheckCodeForMemberSuccess implements Action { + readonly type = ActionType.CheckCodeForMemberSuccess; + + constructor(public payload: void) {} +} + +export class CheckCodeForMemberFailure implements Action { + readonly type = ActionType.CheckCodeForMemberFailure; + + constructor(public payload: RESTError) {} +} + export type Actions = | CreateTotp | CreateTotpSuccess @@ -59,4 +83,7 @@ export type Actions = | Regist | RegistSuccess | RegistFailure + | CheckCodeForMember + | CheckCodeForMemberSuccess + | CheckCodeForMemberFailure ; diff --git a/src/packages/settings/member/store/totp/totp.effect.ts b/src/packages/settings/member/store/totp/totp.effect.ts index 792f8ee..357b832 100644 --- a/src/packages/settings/member/store/totp/totp.effect.ts +++ b/src/packages/settings/member/store/totp/totp.effect.ts @@ -26,6 +26,10 @@ import { RegistSuccess, RegistFailure, + CheckCodeForMember, + CheckCodeForMemberSuccess, + CheckCodeForMemberFailure, + ActionType, } from './totp.action'; @@ -56,14 +60,6 @@ export class Effects { return of(new CreateTotpFailure(error)); }); - @Effect({ dispatch: false }) - createTotpSuccess$ = this.actions$ - .ofType(ActionType.CreateTotpSuccess) - .do(() => { - // Todo TOTP View Print - this.router.navigateByUrl(this._returnURL); - }); - @Effect() regist: Observable = this.actions$ .ofType(ActionType.Regist) @@ -78,4 +74,20 @@ export class Effects { .catch((error: RESTError) => { return of(new RegistFailure(error)); }); + + + @Effect() + checkCodeForMember: Observable = this.actions$ + .ofType(ActionType.CheckCodeForMember) + .map((action: Regist) => action.payload) + .switchMap((payload) => { + // this._returnURL = payload.returnURL; + return this.memberTotpService.checkCodeForMember(payload.member, payload.code); + }) + .map((result: any) => { + return new CheckCodeForMemberSuccess(result); + }) + .catch((error: RESTError) => { + return of(new CheckCodeForMemberFailure(error)); + }); }