@@ -1283,7 +1283,7 @@ define(function(require) {
12831283 } ,
12841284 error : function ( errorPayload , data , globalHandler ) {
12851285 if ( data . status === 401 && errorPayload . data . hasOwnProperty ( 'multi_factor_request' ) ) {
1286- self . handleMultiFactor ( errorPayload . data , dataRecovery , function ( augmentedDataRecovery ) {
1286+ self . handleMultiFactor ( errorPayload . data , dataRecovery , null , function ( augmentedDataRecovery ) {
12871287 self . recoveryWithResetId ( augmentedDataRecovery , success , error ) ;
12881288 } , function ( ) {
12891289 monster . util . logoutAndReload ( ) ;
@@ -1389,18 +1389,21 @@ define(function(require) {
13891389 // If it's a 401 that is about requesting additional login information via MFA, we need to know if it comes from a reconnect attempt
13901390 // If it comes from a reconnect attempt, then we show a popup to ask them if they want to reconnect.
13911391 // If we don't do that and the system automatically reconnected, then the User would see a popup asking him to re-authenticate Duo without any context.
1392- var handleMultifactor = function ( ) {
1393- self . handleMultiFactor ( errorPayload . data , loginData , function ( augmentedLoginData ) {
1394- self . putAuth ( augmentedLoginData , callback , wrongCredsCallback , pUpdateLayout , additionalArgs ) ;
1395- } , wrongCredsCallback ) ;
1396- } ;
1397-
1398- if ( additionalArgs && additionalArgs . hasOwnProperty ( 'isRetryLoginRequest' ) && additionalArgs . isRetryLoginRequest === true ) {
1399- monster . ui . confirm ( self . i18n . active ( ) . retryLoginConfirmText , function ( ) {
1400- handleMultifactor ( ) ;
1401- } , function ( ) {
1402- monster . util . logoutAndReload ( ) ;
1403- } ) ;
1392+ var handleMultifactor = function ( cancelCallback ) {
1393+ self . handleMultiFactor ( errorPayload . data , loginData , additionalArgs , function ( augmentedLoginData ) {
1394+ self . putAuth ( augmentedLoginData , callback , wrongCredsCallback , pUpdateLayout , additionalArgs ) ;
1395+ } , wrongCredsCallback , cancelCallback ) ;
1396+ } ,
1397+ showReconnectDialog = function ( ) {
1398+ monster . ui . confirm ( self . i18n . active ( ) . retryLoginConfirmText , function ( ) {
1399+ handleMultifactor ( showReconnectDialog ) ;
1400+ } , function ( ) {
1401+ monster . util . logoutAndReload ( ) ;
1402+ } ) ;
1403+ } ;
1404+
1405+ if ( _ . get ( additionalArgs , 'isRetryLoginRequest' , false ) === true ) {
1406+ showReconnectDialog ( ) ;
14041407 } else {
14051408 handleMultifactor ( ) ;
14061409 }
@@ -1414,9 +1417,10 @@ define(function(require) {
14141417 } ) ;
14151418 } ,
14161419
1417- handleMultiFactor : function ( data , loginData , success , error ) {
1420+ handleMultiFactor : function ( data , loginData , additionalArgs , success , error , cancel ) {
14181421 var self = this ,
1419- mfaProvider = data . multi_factor_request . provider_name ;
1422+ mfaProvider = data . multi_factor_request . provider_name ,
1423+ isRetryLoginRequest = _ . get ( additionalArgs , 'isRetryLoginRequest' , false ) ;
14201424
14211425 switch ( mfaProvider ) {
14221426 case 'duo_universal' :
@@ -1427,8 +1431,10 @@ define(function(require) {
14271431 break ;
14281432 case 'otp' :
14291433 self . showOtpVerificationDialog ( {
1434+ isRetryLoginRequest : isRetryLoginRequest ,
14301435 loginData : loginData ,
1431- success : success
1436+ success : success ,
1437+ cancel : cancel
14321438 } ) ;
14331439 break ;
14341440 default :
@@ -1460,24 +1466,34 @@ define(function(require) {
14601466 /**
14611467 * Shows the OTP verification dialog.
14621468 * @param {Object } args
1469+ * @param {Boolean } [args.isRetryLoginRequest] Whether or not is a login retry request
14631470 * @param {Object } args.loginData Login data
14641471 * @param {String } args.loginData.credentials Hashed credentials
14651472 * @param {String } args.loginData.accout_name Account name
14661473 * @param {Function } args.success Login success callback
1474+ * @param {Function } args.cancel Cancel callback
14671475 */
14681476 showOtpVerificationDialog : function ( args ) {
14691477 var self = this ,
14701478 $template = $ ( self . getTemplate ( {
1471- name : 'mfa-otpVerificationDialog'
1479+ name : 'mfa-otpVerificationDialog' ,
1480+ data : {
1481+ isRetryLoginRequest : ! ! args . isRetryLoginRequest
1482+ }
14721483 } ) ) ,
14731484 $dialog = monster . ui . dialog ( $template , {
14741485 title : self . i18n . active ( ) . multiFactor . verification . title
14751486 } ) ,
1476- bindArgs = _ . assign ( {
1477- $dialog : $dialog
1478- } , args ) ;
1487+ bindArgs = _ . chain ( args )
1488+ . pick ( [ 'loginData' , 'success' , 'cancel' ] )
1489+ . assign ( {
1490+ $dialog : $dialog
1491+ } )
1492+ . value ( ) ;
14791493
14801494 self . bindOtpVerificationDialogEvents ( bindArgs ) ;
1495+
1496+ $template . find ( '#mfa_code' ) . focus ( ) ;
14811497 } ,
14821498
14831499 /**
@@ -1488,13 +1504,15 @@ define(function(require) {
14881504 * @param {String } args.loginData.credentials Hashed credentials
14891505 * @param {String } args.loginData.accout_name Account name
14901506 * @param {Function } args.success Login success callback
1507+ * @param {Function } args.cancel Cancel callback
14911508 */
14921509 bindOtpVerificationDialogEvents : function ( args ) {
14931510 var self = this ,
14941511 $dialog = args . $dialog ,
14951512 loginData = args . loginData ,
14961513 validator = args . validator ,
14971514 successCallback = args . success ,
1515+ cancelCallback = args . cancel ,
14981516 $form = $dialog . find ( 'form' ) ,
14991517 validator = monster . ui . validate ( $form , {
15001518 rules : {
@@ -1505,7 +1523,8 @@ define(function(require) {
15051523 } ) ,
15061524 $mfaCode = $form . find ( '#mfa_code' ) ,
15071525 $btnVerify = $dialog . find ( '#btn_mfa_verify' ) ,
1508- isCodeLengthInvalid = true ;
1526+ isCodeLengthInvalid = true ,
1527+ isSubmitted = false ;
15091528
15101529 monster . ui . mask ( $mfaCode , '000000' , {
15111530 placeholder : '______'
@@ -1528,7 +1547,8 @@ define(function(require) {
15281547 $dialog . dialog ( 'close' ) ;
15291548 self . showOtpSetupDialog ( {
15301549 loginData : loginData ,
1531- success : successCallback
1550+ success : successCallback ,
1551+ cancel : cancelCallback
15321552 } ) ;
15331553 } ) ;
15341554
@@ -1576,11 +1596,23 @@ define(function(require) {
15761596 return ;
15771597 }
15781598
1599+ isSubmitted = true ;
1600+
1601+ $dialog . dialog ( 'close' ) ;
1602+
15791603 successCallback ( _ . assign ( {
15801604 multi_factor_response : code
15811605 } , loginData ) ) ;
15821606 } ) ;
15831607 } ) ;
1608+
1609+ $dialog . on ( 'dialogclose' , function ( ) {
1610+ if ( isSubmitted ) {
1611+ return ;
1612+ }
1613+
1614+ cancelCallback && cancelCallback ( ) ;
1615+ } ) ;
15841616 } ,
15851617
15861618 /**
@@ -1594,7 +1626,6 @@ define(function(require) {
15941626 showOtpSetupDialog : function ( args ) {
15951627 var self = this ,
15961628 loginData = args . loginData ,
1597- successCallback = args . success ,
15981629 $template = $ ( self . getTemplate ( {
15991630 name : 'mfa-otpSetupDialog'
16001631 } ) ) ,
@@ -1611,11 +1642,11 @@ define(function(require) {
16111642
16121643 monster . parallel ( {
16131644 bindEvents : function bindEvents ( next ) {
1614- self . bindOtpSetupDialogEvents ( {
1615- $dialog : $dialog ,
1616- loginData : loginData ,
1617- success : successCallback
1618- } ) ;
1645+ var bindArgs = _ . assign ( {
1646+ $dialog : $dialog
1647+ } , args ) ;
1648+
1649+ self . bindOtpSetupDialogEvents ( bindArgs ) ;
16191650
16201651 next ( ) ;
16211652 } ,
@@ -1748,16 +1779,12 @@ define(function(require) {
17481779 bindOtpSetupDialogEvents : function ( args ) {
17491780 var self = this ,
17501781 $dialog = args . $dialog ,
1751- loginData = args . loginData ,
1752- successCallback = args . success ;
1782+ showOtpVerificationDialogArgs = _ . pick ( args , [ 'loginData' , 'success' , 'cancel' ] ) ;
17531783
17541784 $dialog . find ( '#btn_mfa_enter_code' ) . on ( 'click' , function ( e ) {
17551785 e . preventDefault ( ) ;
17561786 $dialog . dialog ( 'close' ) ;
1757- self . showOtpVerificationDialog ( {
1758- loginData : loginData ,
1759- success : successCallback
1760- } ) ;
1787+ self . showOtpVerificationDialog ( showOtpVerificationDialogArgs ) ;
17611788 } ) ;
17621789 } ,
17631790
0 commit comments