2018-04-19 12:35:11 +00:00
|
|
|
import {
|
|
|
|
AfterContentInit,
|
|
|
|
Component,
|
|
|
|
EventEmitter,
|
|
|
|
Input,
|
|
|
|
OnInit,
|
|
|
|
Output
|
|
|
|
} from '@angular/core';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
|
|
|
|
2018-05-24 06:44:13 +00:00
|
|
|
import * as TotpStore from '@overflow/member/store/totp';
|
|
|
|
import { AuthSelector } from '@overflow/member/store';
|
|
|
|
import { TotpSelector } from '@overflow/member/store';
|
2018-05-02 08:09:39 +00:00
|
|
|
import { Member } from '@overflow/commons-typescript/model/member';
|
2018-05-24 06:44:13 +00:00
|
|
|
import {RPCClientError} from '@loafer/ng-rpc';
|
2018-04-19 12:35:11 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-config-setting',
|
|
|
|
templateUrl: './config-setting.component.html',
|
|
|
|
styleUrls: ['./config-setting.component.scss']
|
|
|
|
})
|
|
|
|
export class ConfigSettingComponent implements OnInit, AfterContentInit {
|
|
|
|
member: Member;
|
2018-04-19 13:05:39 +00:00
|
|
|
totpState$ = this.store.pipe(select(TotpSelector.select('totp')));
|
2018-04-19 13:29:06 +00:00
|
|
|
totp: any;
|
2018-04-19 13:05:39 +00:00
|
|
|
totpForm: FormGroup;
|
2018-05-03 07:19:10 +00:00
|
|
|
qrData: string;
|
2018-04-19 13:05:39 +00:00
|
|
|
|
2018-04-19 12:35:11 +00:00
|
|
|
@Input() selectedItem: any;
|
|
|
|
@Output() close = new EventEmitter();
|
|
|
|
@Input() totpSettingDisplay;
|
|
|
|
|
|
|
|
constructor(private activatedRoute: ActivatedRoute,
|
|
|
|
private router: Router,
|
|
|
|
private store: Store<TotpStore.State>,
|
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-04-19 13:29:06 +00:00
|
|
|
this.totpForm = this.formBuilder.group({
|
|
|
|
'code': [
|
|
|
|
[
|
|
|
|
]
|
|
|
|
]
|
|
|
|
});
|
2018-04-19 13:05:39 +00:00
|
|
|
this.totpState$.subscribe(
|
2018-04-19 13:29:06 +00:00
|
|
|
(obj: any) => {
|
|
|
|
console.log(obj);
|
|
|
|
this.totp = obj;
|
2018-04-19 13:05:39 +00:00
|
|
|
},
|
|
|
|
(error: RPCClientError) => {
|
|
|
|
console.log(error.response.message);
|
|
|
|
}
|
|
|
|
);
|
2018-04-19 12:35:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterContentInit() {
|
|
|
|
|
2018-04-19 13:05:39 +00:00
|
|
|
this.store.select(AuthSelector.select('member')).subscribe(
|
|
|
|
(member: Member) => {
|
|
|
|
this.member = member;
|
|
|
|
this.store.dispatch(new TotpStore.CreateTotp(this.member));
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
totpRegistClick() {
|
|
|
|
const code = this.totpForm.value['code'];
|
|
|
|
const secretCode = 'X6AWAK573M5372NM';
|
|
|
|
|
|
|
|
this.store.select(AuthSelector.select('member')).subscribe(
|
|
|
|
(member: Member) => {
|
|
|
|
this.store.dispatch(new TotpStore.Regist({ member, secretCode, code }));
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
);
|
2018-04-19 12:35:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onCancel() {
|
|
|
|
this.close.emit();
|
|
|
|
}
|
|
|
|
}
|