1 2/** 3 * Script for 2FA Authy. 4 * 5 * @param {jQuery} $ jQuery object. 6 * @param {Object} window The window object. 7 */ 8 9 10(function ($, window) { 11 12 jQuery(document).on('click', '[data-check-authy-2fa]', function () { 13 const key = jQuery('#2fa-authy-api').val(); 14 const ajaxURL = (typeof wp2faWizardData != "undefined") ? wp2faWizardData.ajaxURL : ajaxurl; 15 const nonceValue = jQuery(this).attr('data-nonce'); 16 17 jQuery.ajax({ 18 url: ajaxURL, 19 data: { 20 action: 'check_authy_api_key', 21 authy_key: key, 22 _wpnonce: nonceValue 23 }, 24 success: function (data) { 25 if (data.success) { 26 if (jQuery('input#authy').length) { 27 storeKey(ajaxURL, key, nonceValue); 28 } else { 29 displayDialog(wp2faAuthy.keyCheckSuccessful); 30 } 31 } else { 32 displayDialog(data.data); 33 } 34 }, 35 }); 36 }); 37 38 function displayDialog(msg) { 39 jQuery('<div></div>').dialog({ 40 modal: true, 41 title: wp2faAuthy.dialogTitle, 42 dialogClass: "alert", 43 open: function() { 44 jQuery(this).html(msg); 45 }, 46 buttons: { 47 OK: function() { 48 $( this ).dialog( "close" ); 49 } 50 } 51 }); 52 jQuery(".ui-dialog").css({borderRadius: "5px"}); 53 } 54 55 jQuery(document).on('click', '[data-api-setup-wizard]', function (e) { 56 e.preventDefault(); 57 jQuery('#wizard-api-key').slideDown( 600 ); 58 }); 59 60 var iti = jQuery("#wp-2fa-phone").intlTelInput({ 61 initialCountry: "auto", 62 geoIpLookup: function (callback) { 63 jQuery.get("http://ipinfo.io", function () { }, "jsonp").always(function (resp) { 64 var countryCode = (resp && resp.country) ? resp.country : ""; 65 callback(countryCode); 66 }); 67 }, 68 placeholderNumberType: "MOBILE", 69 utilsScript: wp2faAuthy.utilsUrl, 70 }); 71 72 // Checks and validates the given telephone number 73 jQuery(document).on('click', '#authy_tel', function (e) { 74 e.preventDefault(); 75 const errorWrapper = jQuery('#error-msg'); 76 errorWrapper.addClass('hidden'); 77 78 if ('' === jQuery('#wp-2fa-phone').val().trim()) { 79 errorWrapper.html('No number provided'); 80 errorWrapper.removeClass('hidden'); 81 } else { 82 if (!iti.intlTelInput("isValidNumber")) { 83 errorWrapper.html(wp2faAuthy.errorMap[iti.intlTelInput("getValidationError")]); 84 errorWrapper.removeClass('hidden'); 85 } else { 86 var fullNumber = iti.intlTelInput("getNumber"); 87 var countryCode = iti.intlTelInput('getSelectedCountryData').dialCode; 88 var phone = fullNumber.replace("+" + countryCode, ''); 89 90 registerUser(countryCode, phone, jQuery(this).data('nonce')); 91 } 92 } 93 }); 94 95 /** 96 * Responds with error 97 * 98 * @param {string} text 99 */ 100 function displayError(text) { 101 if (jQuery('#error-msg').length) { 102 const errorWrapper = jQuery('#error-msg'); 103 errorWrapper.html(text); 104 errorWrapper.removeClass('hidden'); 105 } 106 } 107 108 /** 109 * Registers Authy user. 110 * 111 * @param {string} countryCode 112 * @param {string} phone 113 */ 114 function registerUser(countryCode, phone, nonce) { 115 const ajaxURL = (typeof wp2faWizardData != "undefined") ? wp2faWizardData.ajaxURL : ajaxurl; 116 jQuery.ajax({ 117 url: ajaxURL, 118 data: { 119 action: 'register_user', 120 country_code: countryCode, 121 phone: phone, 122 _wpnonce: nonce 123 }, 124 success: function (data) { 125 if (data.success) { 126 const currentSubStep = jQuery('.authy-step-setting-wrapper'); 127 const nextSubStep = jQuery(currentSubStep).nextAll('.authy-step-setting-wrapper:not(.active)').filter(':first'); 128 jQuery(currentSubStep).removeClass('active'); 129 jQuery(currentSubStep).addClass('hidden'); 130 jQuery(nextSubStep).addClass('active'); 131 jQuery(nextSubStep).removeClass('hidden'); 132 } else { 133 displayError(data.data); 134 } 135 }, 136 error: function (data) { 137 displayError(data.responseJSON.data[0].message); 138 } 139 }); 140 } 141 142 /** 143 * Stores the provided Authy API key 144 * 145 * @param {string} ajaxURL 146 * @param {string} key 147 */ 148 function storeKey(ajaxURL, key, nonce) { 149 jQuery.ajax({ 150 url: ajaxURL, 151 data: { 152 action: 'store_authy_api_key', 153 authy_api_key: key, 154 _wpnonce: nonce 155 }, 156 success: function (data) { 157 if (data.success) { 158 jQuery('#wizard-api-key').fadeOut(1000); 159 jQuery('input#authy').removeClass('disabled').removeAttr('data-api-setup-wizard').prop('checked', true); 160 } else { 161 alert(data.data); 162 } 163 }, 164 }); 165 } 166 167 /** 168 * Shows verification messages 169 * 170 * @param {string} type 171 * @param {string} text 172 */ 173 function verificationResponse(type, text) { 174 let wrapper = jQuery('.verification-response-authy'); 175 176 if ('error' === type) { 177 wrapper.html('<span style="color:red">
177' + text + '</span>'); 178 } else { 179 wrapper.html('<span style="color:green">' + text + '</span>'); 180 } 181 wrapper.removeClass('hidden'); 182 } 183 184 // Authy validation button 185 jQuery(document).on('click', 'a[data-validate-authy-ajax]', function (e) { 186 e.preventDefault(); 187 188 tokenField = jQuery('#authy-token'); 189 if ('' === tokenField.val().trim()) { 190 verificationResponse('error', 'No token provided'); 191 } else { 192 let isValid = false; 193 let regex = /^[0-9\s]*$/; 194 isValid = regex.test(tokenField.val()); 195 if (!isValid) { 196 verificationResponse('error', 'Invalid token format'); 197 } else { 198 let token = tokenField.val(); 199 let nonce = jQuery(this).data('nonce'); 200 201 checkToken(token, nonce); 202 } 203 } 204 }); 205 206 /** 207 * Checks token against the Authy API 208 * 209 * @param {string} token 210 * @param {string} nonce 211 */ 212 function checkToken(token, nonce) { 213 const ajaxURL = (typeof wp2faWizardData != "undefined") ? wp2faWizardData.ajaxURL : ajaxurl; 214 let closeButton = jQuery('button[data-close-2fa-modal'); 215 let setMethod = (closeButton.length) ? true : false; 216 217 jQuery.ajax({ 218 url: ajaxURL, 219 data: { 220 action: 'check_authy_token', 221 token: token, 222 method: setMethod, 223 _wpnonce: nonce 224 }, 225 success: function (data) { 226 if (data.success) { 227 if (jQuery('a[data-validate-authy-ajax]').length) { 228 // Called from the profile setup - close the wizard 229 let nextSubStep = jQuery( '#2fa-wizard-config-backup-codes' ); 230 jQuery( this ).parent().parent().find( '.active' ).not( '.step-setting-wrapper' ).removeClass( 'active' ); 231 jQuery( '.wizard-step.active' ).removeClass( 'active' ); 232 jQuery( nextSubStep ).addClass( 'active' ); 233 234 jQuery( document ).on( 'click', '#select-backup-method', function( e ) { 235 e.preventDefault(); 236 var backupRadio = jQuery("input[name=backup_method_select]:checked"); 237 238 jQuery( '.wizard-step.active' ).removeClass( 'active' ); 239 jQuery( '#'+backupRadio.data('step') ).addClass( 'active' ); 240 } ); 241 242 jQuery( document ).on( 'click', '[name="save_step"], [data-close-2fa-modal]', function() { 243 if ( 'redirectToUrl' in wp2faWizardData && 244 '' != jQuery.trim( wp2faWizardData.redirectToUrl ) ) { 245 window.location.replace( wp2faWizardData.redirectToUrl ); 246 } else { 247 removeShowParam(); 248 } 249 } ); 250 } 251 } else { 252 alert(data.data); 253 } 254 }, 255 error: function (data) { 256 verificationResponse('error', data.responseJSON.data[0].message); 257 } 258 }); 259 260 } 261 262 var timeOutId = ''; 263 264 jQuery("#authy-onetouch-btn").on("click", function () { 265 jQuery("#wp-2fa-authy-onetouch").css('display', 'none'); 266 jQuery("#wp-2fa-authy").css('display', 'inline-block'); 267 jQuery("#submit").css('display', 'inline-block'); 268 clearTimeout(timeOutId); 269 }); 270 271 jQuery(function () { 272 var storiesInterval = 2000; 273 274 if (jQuery('#wp-2fa-authy-onetouch').length && jQuery('#wp-2fa-authy-onetouch').css('display') !== 'none') { 275 var authyCheck = function () { 276 jQuery.ajax({ 277 type: "GET", 278 url: wp2faAuthy.onetouchAjax, 279 data: { 280 action: 'onetouch_status', 281 one_touch: jQuery('#onetouch_uuid').val(), 282 user: jQuery('#wp-auth-id').val(), 283 _wpnonce: jQuery('#wp-auth-nonce').val(), 284 redirect: jQuery('input[name=redirect_to]').val(), 285 rememberme: jQuery('#rememberme').val() 286 } 287 }).success(function (data) { 288 if (data.data !== undefined && data.data.redirect_to !== undefined) { 289 clearInterval(timeOutId); 290 let wp_auth_check_wrap = jQuery( '#wp-auth-check-wrap', window.parent.document ); 291 if ( wp_auth_check_wrap && wp_auth_check_wrap.is( ':visible' ) ) { 292 jQuery( 'body', window.parent.document ).removeClass( 'modal-open' ); 293 wp_auth_check_wrap.addClass('hidden').css('display', ''); 294 jQuery( '#wp-auth-check-frame', window.parent.document ).remove(); 295 window.onbeforeunload = null; 296 jQuery(window).off('beforeunload'); 297 wp_auth_check_wrap.find( '.wp-auth-check-close' ).click(); 298 } else { 299 window.location.replace(data.data.redirect_to); 300 } 301 } 302 }).fail(function () { 303 console.log(data.responseJSON.data[0].message); 304 }).always(function () { 305 306 }); 307 } 308 309 timeOutId = setInterval(authyCheck, storiesInterval); 310 } 311 }); 312 313}(jQuery, window));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.