totp store modify ing...

This commit is contained in:
geek 2018-03-21 19:45:42 +09:00
parent 89bbf5dee9
commit a38df70dd2
4 changed files with 86 additions and 17 deletions

View File

@ -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';

View File

@ -16,7 +16,7 @@ export class MemberTotpService {
public createTotp(member: Member): Observable<MemberTotp[]> {
// Todo Store get member object
return this.rpcClient.call<MemberTotp[]>('MemberTotpService.createTotp', {Member: {id:1}});
return this.rpcClient.call<MemberTotp[]>('MemberTotpService.createTotp', {Member: member});
}
public regist(member: Member, secretCode: string, code: string): Observable<boolean> {
@ -27,4 +27,8 @@ export class MemberTotpService {
// };
return this.rpcClient.call<boolean>('MemberTotpService.regist', member, secretCode, code);
}
public checkCodeForMember(member: Member, code: string): Observable<boolean> {
return this.rpcClient.call<boolean>('MemberTotpService.checkCodeForMember', member, code);
}
}

View File

@ -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
;

View File

@ -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<Action> = this.actions$
.ofType(ActionType.Regist)
@ -78,4 +74,20 @@ export class Effects {
.catch((error: RESTError) => {
return of(new RegistFailure(error));
});
@Effect()
checkCodeForMember: Observable<Action> = 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));
});
}