@@ -2,23 +2,10 @@ import { Meteor } from 'meteor/meteor';
22import { SHA256 } from 'meteor/sha' ;
33import toastr from 'toastr' ;
44
5- import { modal } from '../../ui-utils/client' ;
6- import { t , APIClient } from '../../utils/client' ;
5+ import { t } from '../../utils/client' ;
6+ import { imperativeModal } from '../../../client/lib/imperativeModal' ;
7+ import TwoFactorModal from '../../../client/components/TwoFactorModal' ;
78
8- const methods = {
9- totp : {
10- text : 'Open_your_authentication_app_and_enter_the_code' ,
11- } ,
12- email : {
13- text : 'Verify_your_email_for_the_code_we_sent' ,
14- html : true ,
15- } ,
16- password : {
17- title : 'Please_enter_your_password' ,
18- text : 'For_your_security_you_must_enter_your_current_password_to_continue' ,
19- inputType : 'password' ,
20- } ,
21- } ;
229
2310export function process2faReturn ( { error, result, originalCallback, onCode, emailOrUsername } ) {
2411 if ( ! error || ( error . error !== 'totp-required' && error . errorType !== 'totp-required' ) ) {
@@ -31,34 +18,20 @@ export function process2faReturn({ error, result, originalCallback, onCode, emai
3118 emailOrUsername = Meteor . user ( ) . username ;
3219 }
3320
34- modal . open ( {
35- title : t ( methods [ method ] . title || 'Two Factor Authentication' ) ,
36- text : t ( methods [ method ] . text ) ,
37- html : methods [ method ] . html ,
38- type : 'input' ,
39- inputActionText : method === 'email' && emailOrUsername && t ( 'Send_me_the_code_again' ) ,
40- async inputAction ( e ) {
41- const { value } = e . currentTarget ;
42- e . currentTarget . value = t ( 'Sending' ) ;
43-
44- await APIClient . v1 . post ( 'users.2fa.sendEmailCode' , { emailOrUsername } ) ;
45-
46- e . currentTarget . value = value ;
21+ imperativeModal . open ( {
22+ component : TwoFactorModal ,
23+ props : {
24+ method,
25+ onConfirm : ( code , method ) => {
26+ onCode ( method === 'password' ? SHA256 ( code ) : code , method ) ;
27+ imperativeModal . close ( ) ;
28+ } ,
29+ onClose : ( ) => {
30+ imperativeModal . close ( ) ;
31+ originalCallback ( new Meteor . Error ( 'totp-canceled' ) ) ;
32+ } ,
33+ emailOrUsername ,
4734 } ,
48- inputType : methods [ method ] . inputType || 'text' ,
49- showCancelButton : true ,
50- closeOnConfirm : true ,
51- confirmButtonText : t ( 'Verify' ) ,
52- cancelButtonText : t ( 'Cancel' ) ,
53- } , ( code ) => {
54- if ( code === false ) {
55- return originalCallback ( new Meteor . Error ( 'totp-canceled' ) ) ;
56- }
57-
58- if ( method === 'password' ) {
59- code = SHA256 ( code ) ;
60- }
61- onCode ( code , method ) ;
6235 } ) ;
6336}
6437
0 commit comments