| 1 |
jQuery(window).on('load',function () { |
| 2 |
// Enable auth modals |
| 3 |
uwp_init_auth_modal();uwp_switch_reg_form_init(); |
| 4 |
}); |
| 5 |
|
| 6 |
|
| 7 |
(function( $, window, undefined ) { |
| 8 |
$(document).ready(function() { |
| 9 |
var showChar = uwp_localize_data.uwp_more_char_limit; |
| 10 |
var ellipsestext = uwp_localize_data.uwp_more_ellipses_text; |
| 11 |
var moretext = uwp_localize_data.uwp_more_text; |
| 12 |
var lesstext = uwp_localize_data.uwp_less_text; |
| 13 |
$('.uwp_more').each(function() { |
| 14 |
var content = $.trim($(this).text()); |
| 15 |
var length = $( this ).data( 'maxchar' ); |
| 16 |
if(length > 0 ){ |
| 17 |
showChar = length; |
| 18 |
} |
| 19 |
if(content.length > showChar) { |
| 20 |
|
| 21 |
var c = content.substr(0, showChar); |
| 22 |
var h = content.substr(showChar, content.length - showChar); |
| 23 |
var html = uwp_nl2br(c) + '<span class="uwp_more_ellipses">' + ellipsestext+ ' </span><span class="uwp_more_content"><span style="display: none;">' + uwp_nl2br(h) + '</span> <a href="" class="uwp_more_link">' + moretext + '</a></span>'; |
| 24 |
|
| 25 |
$(this).html(html); |
| 26 |
} |
| 27 |
|
| 28 |
}); |
| 29 |
|
| 30 |
$(".uwp_more_link").on('click', function(){ |
| 31 |
if($(this).hasClass("uwp_less")) { |
| 32 |
$(this).removeClass("uwp_less"); |
| 33 |
$(this).html(moretext); |
| 34 |
} else { |
| 35 |
$(this).addClass("uwp_less"); |
| 36 |
$(this).html(lesstext); |
| 37 |
} |
| 38 |
$(this).parent().prev().toggle(); |
| 39 |
$(this).prev().toggle(); |
| 40 |
return false; |
| 41 |
}); |
| 42 |
|
| 43 |
// set the current user selection if set |
| 44 |
if (typeof(Storage) !== "undefined") { |
| 45 |
var $storage_key = "uwp_list_view"; |
| 46 |
var $list = jQuery('.uwp-users-loop > .row'); |
| 47 |
if (!$list.length) { |
| 48 |
$list = jQuery('.uwp-profile-cpt-loop > .row'); |
| 49 |
$storage_key = "uwp_cpt_list_view"; |
| 50 |
} |
| 51 |
var $noStore = false; |
| 52 |
var uwp_list_view = localStorage.getItem($storage_key); |
| 53 |
setTimeout(function () { |
| 54 |
if (!uwp_list_view) { |
| 55 |
$noStore = true; |
| 56 |
if ($list.hasClass('row-cols-md-0')) { |
| 57 |
uwp_list_view = 0; |
| 58 |
} else if ($list.hasClass('row-cols-md-1')) { |
| 59 |
uwp_list_view = 1; |
| 60 |
} else if ($list.hasClass('row-cols-md-2')) { |
| 61 |
uwp_list_view = 2; |
| 62 |
} else if ($list.hasClass('row-cols-md-3')) { |
| 63 |
uwp_list_view = 3; |
| 64 |
} else if ($list.hasClass('row-cols-md-4')) { |
| 65 |
uwp_list_view = 4; |
| 66 |
} else if ($list.hasClass('row-cols-md-5')) { |
| 67 |
uwp_list_view = 5; |
| 68 |
} else { |
| 69 |
uwp_list_view = 3; |
| 70 |
} |
| 71 |
} |
| 72 |
uwp_list_view_select(uwp_list_view, $noStore); |
| 73 |
}, 10); // we need to give it a very short time so the page loads the actual html |
| 74 |
} |
| 75 |
}); |
| 76 |
}( jQuery, window )); |
| 77 |
|
| 78 |
|
| 79 |
(function( $, window, undefined ) { |
| 80 |
|
| 81 |
var uwp_popup_type; |
| 82 |
|
| 83 |
$(document).ready( function() { |
| 84 |
$( '.uwp-profile-modal-form-trigger' ).on( 'click', function( event ) { |
| 85 |
event.preventDefault(); |
| 86 |
|
| 87 |
uwp_popup_type = $( this ).data( 'type' ); |
| 88 |
|
| 89 |
// do something with the file here |
| 90 |
var data = { |
| 91 |
'action': 'uwp_ajax_image_crop_popup_form', |
| 92 |
'type': uwp_popup_type |
| 93 |
}; |
| 94 |
|
| 95 |
var container = jQuery('#uwp-popup-modal-wrap'); |
| 96 |
container.show(); |
| 97 |
|
| 98 |
jQuery.post(uwp_localize_data.ajaxurl, data, function(response) { |
| 99 |
$(document.body).append("<div id='uwp-modal-backdrop'></div>"); |
| 100 |
container.replaceWith(response); |
| 101 |
}); |
| 102 |
}); |
| 103 |
}); |
| 104 |
|
| 105 |
$(document).ready(function() { |
| 106 |
$( '.uwp_upload_file_remove' ).on( 'click', function( event ) { |
| 107 |
event.preventDefault(); |
| 108 |
|
| 109 |
var $this = $(this); |
| 110 |
var htmlvar = $this.data( 'htmlvar' ); |
| 111 |
var uid = $this.data( 'uid' ); |
| 112 |
|
| 113 |
var data = { |
| 114 |
'action': 'uwp_upload_file_remove', |
| 115 |
'htmlvar': htmlvar, |
| 116 |
'uid': uid, |
| 117 |
'security': uwp_localize_data.basicNonce |
| 118 |
}; |
| 119 |
|
| 120 |
if ($this.closest("form").find('.uwp-field-error').length) { |
| 121 |
$this.closest("form").find('.uwp-field-error').remove(); |
| 122 |
} |
| 123 |
|
| 124 |
jQuery.ajax({ |
| 125 |
url: uwp_localize_data.ajaxurl, |
| 126 |
type: 'POST', |
| 127 |
data: data, |
| 128 |
dataType: 'json' |
| 129 |
}).done(function(res, textStatus, jqXHR) { |
| 130 |
if (res && typeof res == 'object') { |
| 131 |
if (res.success) { |
| 132 |
$("#"+htmlvar+"_row").find(".uwp_file_preview_wrap").remove(); |
| 133 |
$("#"+htmlvar).closest("td").find(".uwp_file_preview_wrap").remove(); |
| 134 |
if($('input[name='+htmlvar+']').data( 'is-required' )){ |
| 135 |
$('input[name='+htmlvar+']').prop('required',true); |
| 136 |
} |
| 137 |
} else if (res.data && typeof res.data == 'object' && res.data.message) { |
| 138 |
$this.parent(".uwp_file_preview_wrap").append('<div class="uwp-field-error">' + res.data.message + '</div>'); |
| 139 |
} |
| 140 |
} |
| 141 |
}); |
| 142 |
}); |
| 143 |
}); |
| 144 |
|
| 145 |
}( jQuery, window )); |
| 146 |
|
| 147 |
(function( $, window, undefined ) { |
| 148 |
$(document).ready(function() { |
| 149 |
$( '#uwp_layout' ).on( 'change', function() { |
| 150 |
var layout = $(this).val(); |
| 151 |
var container = $('#uwp_user_items_layout'); |
| 152 |
container.removeClass(); |
| 153 |
if (layout == 'list') { |
| 154 |
container.addClass('uwp-users-list-wrap uwp_listview'); |
| 155 |
} else if (layout == '2col') { |
| 156 |
container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_2col'); |
| 157 |
} else if (layout == '3col') { |
| 158 |
container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_3col'); |
| 159 |
} else if (layout == '4col') { |
| 160 |
container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_4col'); |
| 161 |
} else if (layout == '5col') { |
| 162 |
container.addClass('uwp-users-list-wrap uwp_gridview uwp_gridview_5col'); |
| 163 |
} else { |
| 164 |
container.addClass('uwp-users-list-wrap uwp_listview'); |
| 165 |
} |
| 166 |
}); |
| 167 |
|
| 168 |
jQuery( document ).ready(function($) { |
| 169 |
$( '#uwp_login_modal form.uwp-login-form' ).on( 'submit', function( e ) { |
| 170 |
e.preventDefault(); |
| 171 |
uwp_ajax_login(this); |
| 172 |
}); |
| 173 |
}); |
| 174 |
|
| 175 |
function uwp_ajax_login($this) { |
| 176 |
|
| 177 |
$('#uwp_login_modal .uwp-login-ajax-notice').remove(); |
| 178 |
$('#uwp_login_modal form.uwp-login-form').prev('.alert').remove(); |
| 179 |
|
| 180 |
var data = jQuery($this).serialize()+ "&action=uwp_ajax_login"; |
| 181 |
|
| 182 |
jQuery.post(uwp_localize_data.ajaxurl, data, function(response) { |
| 183 |
if (typeof response === 'string') { |
| 184 |
response = jQuery.parseJSON(response); |
| 185 |
} |
| 186 |
|
| 187 |
if(response.success === false || response.error){ |
| 188 |
$('#uwp_login_modal form.uwp-login-form').before(response.data && response.data.message ? response.data.message : response.message); |
| 189 |
} else if (response.success === true && response.data && response.data.is_2fa) { |
| 190 |
$('#uwp_login_modal form.uwp-login-form').replaceWith(response.data.html); |
| 191 |
$('#uwp_login_modal form.validate_2fa_form').on('submit', function(e) { |
| 192 |
e.preventDefault(); |
| 193 |
uwp_ajax_login_2fa('form.validate_2fa_form', ''); |
| 194 |
}); |
| 195 |
$('#uwp_login_modal form.validate_2fa_backup_codes_form').on('submit', function(e) { |
| 196 |
e.preventDefault(); |
| 197 |
uwp_ajax_login_2fa('form.validate_2fa_backup_codes_form', ''); |
| 198 |
}); |
| 199 |
$('#uwp_login_modal .uwp-2fa-email-resend').on('click', function(e) { |
| 200 |
e.preventDefault(); |
| 201 |
uwp_ajax_login_2fa('form.validate_2fa_form', '&wp-2fa-email-code-resend=1', this); |
| 202 |
}); |
| 203 |
} else { |
| 204 |
$('#uwp_login_modal form.uwp-login-form').before(response.data && response.data.message ? response.data.message : response.message); |
| 205 |
setTimeout(function(){location.reload()}, 1200) |
| 206 |
} |
| 207 |
|
| 208 |
}); |
| 209 |
} |
| 210 |
|
| 211 |
function uwp_ajax_login_2fa(type, fields, btnEl) { |
| 212 |
$('#uwp_login_modal .uwp-login-ajax-notice').remove(); |
| 213 |
$('#uwp_login_modal ' + type).prev('.alert').remove(); |
| 214 |
|
| 215 |
var data = jQuery('#uwp_login_modal ' + type).serialize() + '&action=uwp_ajax_login_process_2fa' + fields; |
| 216 |
|
| 217 |
jQuery.post(uwp_localize_data.ajaxurl, data, function(response) { |
| 218 |
if (typeof response === 'string') { |
| 219 |
response = jQuery.parseJSON(response); |
| 220 |
} |
| 221 |
|
| 222 |
if (response.success === false || response.error) { |
| 223 |
$('#uwp_login_modal ' + type).before(response.data && response.data.message ? response.data.message : response.message); |
| 224 |
$('#uwp_login_modal ' + type).find('.uwp-2fa-submit').prop('disabled', false); |
| 225 |
if (btnEl) { |
| 226 |
$(btnEl).prop('disabled', false); |
| 227 |
} |
| 228 |
} else { |
| 229 |
$('#uwp_login_modal ' + type).before(response.data && response.data.message ? response.data.message : response.message); |
| 230 |
if (response.data && response.data.redirect) { |
| 231 |
setTimeout(function(){location.href = response.data.redirect}, 1200); |
| 232 |
} else { |
| 233 |
setTimeout(function(){location.reload()}, 1200); |
| 234 |
} |
| 235 |
} |
| 236 |
}); |
| 237 |
} |
| 238 |
|
| 239 |
}); |
| 240 |
}( jQuery, window )); |
| 241 |
|
| 242 |
function uwp_nl2br(str, is_xhtml) { |
| 243 |
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>'; |
| 244 |
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2'); |
| 245 |
} |
| 246 |
|
| 247 |
function uwp_list_view_select($val, $noStore) { |
| 248 |
|
| 249 |
var $storage_key = "uwp_list_view"; |
| 250 |
var $list = jQuery('.uwp-users-loop > .row'); |
| 251 |
if (!$list.length) { |
| 252 |
$list = jQuery('.uwp-profile-cpt-loop > .row'); |
| 253 |
$storage_key = "uwp_cpt_list_view"; |
| 254 |
} |
| 255 |
|
| 256 |
var $listSelect = jQuery('.uwp-list-view-select'); |
| 257 |
if ($val == 0) { |
| 258 |
$list.removeClass('row-cols-sm-2 row-cols-md-2 row-cols-md-3 row-cols-md-4 row-cols-md-5').addClass('row-cols-md-0'); |
| 259 |
$listSelect.find('button').removeClass('active'); |
| 260 |
$listSelect.find('button.uwp-list-view-select-list').addClass('active'); |
| 261 |
} else { |
| 262 |
$listSelect.find('button').removeClass('active'); |
| 263 |
$listSelect.find('button.uwp-list-view-select-grid').addClass('active'); |
| 264 |
$listSelect.find('button[data-gridview="' + $val + '"]').addClass('active'); |
| 265 |
$list.removeClass('row-cols-md-0 row-cols-md-2 row-cols-md-3 row-cols-md-4 row-cols-md-5').addClass('row-cols-sm-2 row-cols-md-' + $val); |
| 266 |
} |
| 267 |
|
| 268 |
// only store if it was a user action |
| 269 |
if (!$noStore) { |
| 270 |
// store the user selection |
| 271 |
localStorage.setItem($storage_key, $val); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
function uwp_profile_image_change(type){ |
| 276 |
// remove it first |
| 277 |
jQuery('.uwp-profile-image-change-modal').remove(); |
| 278 |
|
| 279 |
var $modal = '<div class="modal fade uwp-profile-image-change-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-profile-modal-title" aria-hidden="true"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="uwp-profile-modal-title"></h5></div><div class="modal-body text-center"><i class="fas fa-circle-notch fa-spin fa-3x"></i></div></div></div></div>'; |
| 280 |
jQuery('body').append($modal); |
| 281 |
|
| 282 |
// jQuery('.uwp-profile-image-change-modal').modal({ |
| 283 |
// backdrop: 'static' |
| 284 |
// }); |
| 285 |
|
| 286 |
if ( window.bootstrap && window.bootstrap.Modal ) { |
| 287 |
var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-profile-image-change-modal')); |
| 288 |
authModal.show(); |
| 289 |
} else { |
| 290 |
jQuery('.uwp-profile-image-change-modal').modal({ |
| 291 |
backdrop: 'static' |
| 292 |
}); |
| 293 |
} |
| 294 |
|
| 295 |
// do something with the file here |
| 296 |
var data = { |
| 297 |
'action': 'uwp_ajax_image_crop_popup_form', |
| 298 |
'type': type, |
| 299 |
'style': 'bootstrap' |
| 300 |
}; |
| 301 |
|
| 302 |
jQuery.post(uwp_localize_data.ajaxurl, data, function(response) { |
| 303 |
jQuery('.uwp-profile-image-change-modal .modal-content').html(response); |
| 304 |
}); |
| 305 |
} |
| 306 |
|
| 307 |
function uwp_init_auth_modal(){ |
| 308 |
|
| 309 |
// open login form |
| 310 |
if(uwp_localize_data.login_modal) { |
| 311 |
jQuery('.users-wp-login-nav a, .uwp-login-link, [data-uwp-link="login"]').off('click'); |
| 312 |
jQuery('.users-wp-login-nav a, .uwp-login-link, [data-uwp-link="login"]').on('click', function (e) { |
| 313 |
uwp_cancelBubble(e); |
| 314 |
uwp_modal_login_form(); |
| 315 |
return false; |
| 316 |
}); |
| 317 |
} |
| 318 |
|
| 319 |
// open the register form |
| 320 |
if(uwp_localize_data.register_modal) { |
| 321 |
jQuery('.users-wp-register-nav a, .uwp-register-link, [data-uwp-link="register"]').off('click'); |
| 322 |
jQuery('.users-wp-register-nav a, .uwp-register-link, [data-uwp-link="register"]').on('click', function (e) { |
| 323 |
uwp_cancelBubble(e); |
| 324 |
uwp_modal_register_form(); |
| 325 |
return false; |
| 326 |
}); |
| 327 |
} |
| 328 |
|
| 329 |
// open the forgot password form |
| 330 |
if(uwp_localize_data.forgot_modal) { |
| 331 |
jQuery('.users-wp-forgot-nav a, .uwp-forgot-password-link, [data-uwp-link="forgot-password"]').off('click'); |
| 332 |
jQuery('.users-wp-forgot-nav a, .uwp-forgot-password-link, [data-uwp-link="forgot-password"]').on('click', function (e) { |
| 333 |
uwp_cancelBubble(e); |
| 334 |
uwp_modal_forgot_password_form(); |
| 335 |
return false; |
| 336 |
}); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
function uwp_modal_loading(inputs) { |
| 341 |
$input_single = '<span class="badge badge-pill badge-light p-3 mt-3 w-100 bg-loading"> </span>'; |
| 342 |
$inputs = inputs ? $input_single.repeat(inputs) : $input_single; |
| 343 |
|
| 344 |
var $modal_content = '<div class="modal-header">' + |
| 345 |
'<span class="badge badge-pill badge-light p-0 mt-2 w-25 bg-loading"> </span></div>' + |
| 346 |
'<div class="modal-body text-center">' + $inputs + '</div>'; |
| 347 |
var $modal = '<div class="modal fade uwp-auth-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-profile-modal-title" aria-hidden="true">' + |
| 348 |
'<div class="modal-dialog modal-dialog-centered">' + |
| 349 |
'<div class="modal-content">' + |
| 350 |
$modal_content + |
| 351 |
'</div></div></div>'; |
| 352 |
|
| 353 |
if (!jQuery('.uwp-auth-modal').length) { |
| 354 |
jQuery('body').append($modal); |
| 355 |
} else { |
| 356 |
jQuery('.uwp-auth-modal .modal-content').html($modal_content); |
| 357 |
} |
| 358 |
|
| 359 |
jQuery('.modal-backdrop').remove(); |
| 360 |
|
| 361 |
if (window.bootstrap && window.bootstrap.Modal) { |
| 362 |
var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-auth-modal')); |
| 363 |
authModal.show(); |
| 364 |
} else { |
| 365 |
jQuery('.uwp-auth-modal').modal(); |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
/** |
| 370 |
* Get the login form via ajax and load it in a modal. |
| 371 |
*/ |
| 372 |
function uwp_modal_login_form(){ |
| 373 |
var data = { |
| 374 |
'action': 'uwp_ajax_login_form' // deliberately no nonce for caching reasons |
| 375 |
}; |
| 376 |
jQuery.ajax({ |
| 377 |
type: "POST", |
| 378 |
url: uwp_localize_data.ajaxurl, |
| 379 |
data: data, |
| 380 |
beforeSend: function() { |
| 381 |
uwp_modal_loading(4); |
| 382 |
}, |
| 383 |
success: function(data) { |
| 384 |
if(data.success){ |
| 385 |
jQuery('.uwp-auth-modal .modal-content').html(data.data); |
| 386 |
setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation |
| 387 |
|
| 388 |
// process login form |
| 389 |
jQuery( '.uwp-auth-modal .modal-content form.uwp-login-form' ).on( 'submit', function( e ) { |
| 390 |
e.preventDefault(e); |
| 391 |
uwp_modal_login_form_process(); |
| 392 |
}); |
| 393 |
} |
| 394 |
uwp_init_auth_modal(); |
| 395 |
} |
| 396 |
}); |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* Check if we are waiting on a recaptcha callback. |
| 401 |
* |
| 402 |
* @param $form |
| 403 |
* @returns {boolean} |
| 404 |
*/ |
| 405 |
function uwp_maybe_check_recaptcha($form){ |
| 406 |
if(typeof uwp_recaptcha_loops === 'undefined' || !uwp_recaptcha_loops){uwp_recaptcha_loops = 1;} |
| 407 |
if(jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').length && jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').val() == ''){ |
| 408 |
setTimeout(function(){ |
| 409 |
// remove the original spinner |
| 410 |
jQuery('.uwp-auth-modal .modal-content button[type="submit"] i.fa-spin,.uwp-auth-modal .modal-content button[type="submit"] svg.fa-spin').remove(); |
| 411 |
|
| 412 |
// bail and add warning if still no recaptcha after 5 loops` |
| 413 |
if(uwp_recaptcha_loops>=6){ |
| 414 |
jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').prop('disabled', false); |
| 415 |
jQuery('.uwp-auth-modal .modal-content .uwp_register_submit').prop('disabled', false); |
| 416 |
jQuery('.uwp-auth-modal .modal-content .uwp_forgot_submit').prop('disabled', false); |
| 417 |
jQuery('.uwp-auth-modal .modal-content .uwp-captcha-render').addClass("alert alert-danger"); |
| 418 |
|
| 419 |
// maybe show general error |
| 420 |
if(jQuery('.uwp-auth-modal .modal-content .modal-error').html()==''){ |
| 421 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html("<div class='alert alert-danger'>"+uwp_localize_data.error_retry+"</div>"); |
| 422 |
} |
| 423 |
|
| 424 |
return false; |
| 425 |
} |
| 426 |
|
| 427 |
if($form=='login'){ |
| 428 |
uwp_modal_login_form_process(); |
| 429 |
}else if($form == 'register'){ |
| 430 |
uwp_modal_register_form_process(); |
| 431 |
}else if($form == 'forgot'){ |
| 432 |
uwp_modal_forgot_password_form_process(); |
| 433 |
} |
| 434 |
}, 500); // 6 x 500 = 3 seconds we wait for response before showing error. |
| 435 |
uwp_recaptcha_loops++; |
| 436 |
return false; |
| 437 |
} |
| 438 |
uwp_recaptcha_loops = 0; |
| 439 |
return true; |
| 440 |
} |
| 441 |
|
| 442 |
/** |
| 443 |
* Maybe reset the recaptcha on ajax submit fail. |
| 444 |
*/ |
| 445 |
function uwp_maybe_reset_recaptcha() { |
| 446 |
if( jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').length ){ |
| 447 |
var id = jQuery('.uwp-auth-modal .modal-content .g-recaptcha-response').attr('id'); |
| 448 |
uwp_reset_captcha(id); |
| 449 |
} |
| 450 |
|
| 451 |
document.dispatchEvent(new Event('ayecode_reset_captcha')); |
| 452 |
} |
| 453 |
|
| 454 |
/** |
| 455 |
* Submit the login form via ajax. |
| 456 |
*/ |
| 457 |
function uwp_modal_login_form_process(){ |
| 458 |
var data = jQuery(".modal-content form.uwp-login-form").serialize() + '&action=uwp_ajax_login'; |
| 459 |
$button_text = jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html(); |
| 460 |
jQuery.ajax({ |
| 461 |
type: "POST", |
| 462 |
url: uwp_localize_data.ajaxurl, |
| 463 |
data: data, |
| 464 |
beforeSend: function() { |
| 465 |
jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit |
| 466 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages |
| 467 |
return uwp_maybe_check_recaptcha('login'); |
| 468 |
}, |
| 469 |
success: function(data) { |
| 470 |
if(data.success==true){ |
| 471 |
jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html($button_text).prop('disabled', true);// remove spinner |
| 472 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 473 |
// Show success message for 1 second before redirecting. |
| 474 |
if(data.data.is_2fa){ |
| 475 |
jQuery(".modal-content form.uwp-login-form").replaceWith(data.data.html); |
| 476 |
|
| 477 |
jQuery( '.uwp-auth-modal .modal-content form.validate_2fa_form' ).on( 'submit', function( e ) { |
| 478 |
e.preventDefault(e); |
| 479 |
uwp_modal_login_form_2fa_process('form.validate_2fa_form', ''); |
| 480 |
}); |
| 481 |
|
| 482 |
jQuery( '.uwp-auth-modal .modal-content form.validate_2fa_backup_codes_form' ).on( 'submit', function( e ) { |
| 483 |
e.preventDefault(e); |
| 484 |
uwp_modal_login_form_2fa_process('form.validate_2fa_backup_codes_form', ''); |
| 485 |
}); |
| 486 |
|
| 487 |
jQuery( '.uwp-auth-modal .modal-content .uwp-2fa-email-resend' ).on( 'click', function( e ) { |
| 488 |
e.preventDefault(e); |
| 489 |
uwp_modal_login_form_2fa_process('form.validate_2fa_form', '&wp-2fa-email-code-resend=1', jQuery(this)); |
| 490 |
}); |
| 491 |
} else { |
| 492 |
if(data.data.redirect){ |
| 493 |
setTimeout(function(){ |
| 494 |
location.href = data.data.redirect; |
| 495 |
}, 1000); |
| 496 |
} else { |
| 497 |
setTimeout(function(){ |
| 498 |
location.reload(); |
| 499 |
}, 1000); |
| 500 |
} |
| 501 |
} |
| 502 |
|
| 503 |
}else if(data.success===false){ |
| 504 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 505 |
jQuery('.uwp-auth-modal .modal-content .uwp_login_submit').html($button_text).prop('disabled', false);// enable submit |
| 506 |
uwp_maybe_reset_recaptcha(); |
| 507 |
} |
| 508 |
uwp_init_auth_modal(); |
| 509 |
} |
| 510 |
}); |
| 511 |
} |
| 512 |
|
| 513 |
function uwp_modal_login_form_2fa_process(type, fields, $button){ |
| 514 |
var data = jQuery(".modal-content " + type).serialize() + '&action=uwp_ajax_login_process_2fa'+fields; |
| 515 |
if (!$button) { |
| 516 |
$button = jQuery('.uwp-auth-modal .modal-content '+type).find('.uwp-2fa-submit'); |
| 517 |
} |
| 518 |
$button_text = $button.html(); |
| 519 |
jQuery.ajax({ |
| 520 |
type: "POST", |
| 521 |
url: uwp_localize_data.ajaxurl, |
| 522 |
data: data, |
| 523 |
beforeSend: function() { |
| 524 |
$button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit |
| 525 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages |
| 526 |
}, |
| 527 |
success: function(data) { |
| 528 |
if(data.success==true){ |
| 529 |
$button.html($button_text).prop('disabled', true);// remove spinner |
| 530 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 531 |
// Show success message for 1 second before redirecting. |
| 532 |
if(data.data.redirect){ |
| 533 |
setTimeout(function(){ |
| 534 |
location.href = data.data.redirect; |
| 535 |
}, 1000); |
| 536 |
} else { |
| 537 |
setTimeout(function(){ |
| 538 |
location.reload(); |
| 539 |
}, 1000); |
| 540 |
} |
| 541 |
|
| 542 |
}else if(data.success===false){ |
| 543 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 544 |
$button.html($button_text).prop('disabled', false);// enable submit |
| 545 |
} |
| 546 |
uwp_init_auth_modal(); |
| 547 |
} |
| 548 |
}); |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
/** |
| 553 |
* Get the register form via ajax and load it in a modal. |
| 554 |
*/ |
| 555 |
function uwp_modal_register_form(form_id){ |
| 556 |
var data = { |
| 557 |
'action': 'uwp_ajax_register_form', // deliberately no nonce for caching reasons |
| 558 |
'form_id': form_id, |
| 559 |
}; |
| 560 |
jQuery.ajax({ |
| 561 |
type: "POST", |
| 562 |
url: uwp_localize_data.ajaxurl, |
| 563 |
data: data, |
| 564 |
beforeSend: function() { |
| 565 |
uwp_modal_loading(6); |
| 566 |
}, |
| 567 |
success: function(data) { |
| 568 |
if(data.success){ |
| 569 |
jQuery('.uwp-auth-modal .modal-content').html(data.data); |
| 570 |
setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation |
| 571 |
|
| 572 |
// process register form |
| 573 |
jQuery(".uwp-auth-modal .modal-content form.uwp-registration-form").submit(function(e){ |
| 574 |
e.preventDefault(e); |
| 575 |
uwp_modal_register_form_process(); |
| 576 |
}); |
| 577 |
} |
| 578 |
uwp_init_auth_modal();aui_init_select2();uwp_switch_reg_form_init();aui_init(); |
| 579 |
} |
| 580 |
}); |
| 581 |
} |
| 582 |
|
| 583 |
/** |
| 584 |
* Load register form via AJAX for normal (non-modal) forms. |
| 585 |
*/ |
| 586 |
function uwp_load_register_form(form_id, form, activeElement) { |
| 587 |
var data = { |
| 588 |
'action': 'uwp_ajax_register_form', |
| 589 |
'form_id': form_id, |
| 590 |
}; |
| 591 |
|
| 592 |
jQuery.ajax({ |
| 593 |
type: "POST", |
| 594 |
url: uwp_localize_data.ajaxurl, |
| 595 |
data: data, |
| 596 |
beforeSend: function() { |
| 597 |
jQuery(document).trigger('uwp_form_loading', { form_id, form }); |
| 598 |
|
| 599 |
if (activeElement) { |
| 600 |
activeElement.addClass('active'); |
| 601 |
} |
| 602 |
var $inputDivs = form.find('input, select, textarea').not('#uwp-form-type-select'); |
| 603 |
var $placeholder = '<div class="badge badge-pill badge-light p-3 mt-3 w-100 bg-loading"> </div>'; |
| 604 |
|
| 605 |
// Replace each input's parent div with the placeholder |
| 606 |
$inputDivs.each(function() { |
| 607 |
jQuery(this).replaceWith($placeholder); |
| 608 |
}); |
| 609 |
|
| 610 |
// Remove everything else in the form except the placeholders |
| 611 |
form.children().not('.badge, #uwp-form-select').remove(); |
| 612 |
}, |
| 613 |
success: function(data) { |
| 614 |
if(data.success){ |
| 615 |
var $returnedForm = jQuery(data.data).find('form'); |
| 616 |
var $formSelector = form.find('#uwp-form-select'); |
| 617 |
|
| 618 |
form.html($returnedForm.html()); |
| 619 |
|
| 620 |
if (!$returnedForm.find('#uwp-form-select').length && !$returnedForm.find('#uwp-form-select-ajax').length && $formSelector) { |
| 621 |
form.prepend($formSelector); |
| 622 |
} |
| 623 |
|
| 624 |
form.find('#uwp-form-select-ajax').attr('id', 'uwp-form-select'); |
| 625 |
|
| 626 |
jQuery(document).trigger('uwp_form_loaded', { form_id, form, html: data.data }); |
| 627 |
} |
| 628 |
|
| 629 |
uwp_init_auth_modal(); |
| 630 |
aui_init_select2(); |
| 631 |
uwp_switch_reg_form_init(); |
| 632 |
} |
| 633 |
}); |
| 634 |
} |
| 635 |
|
| 636 |
function uwp_switch_reg_form_init() { |
| 637 |
// Handle button clicks for lightbox (AJAX modal) |
| 638 |
jQuery( '#uwp-form-select-ajax a' ).off( 'click.uwpSwitchRegForm' ).on( 'click.uwpSwitchRegForm', function( e ) { |
| 639 |
e.preventDefault(e); |
| 640 |
var form_id = jQuery(this).attr('data-form_id'); |
| 641 |
uwp_modal_register_form(form_id); |
| 642 |
}); |
| 643 |
|
| 644 |
// Handle select dropdown for lightbox (AJAX modal) |
| 645 |
jQuery( '#uwp-form-select-ajax select#uwp-form-type-select' ).off( 'change.uwpSwitchRegForm' ).on( 'change.uwpSwitchRegForm', function( e ) { |
| 646 |
var form_id = jQuery(this).find('option:selected').attr('data-form_id'); |
| 647 |
uwp_modal_register_form(form_id); |
| 648 |
}); |
| 649 |
|
| 650 |
// Handle button clicks for normal forms |
| 651 |
jQuery( '#uwp-form-select a' ).off( 'click.uwpSwitchRegForm' ).on( 'click.uwpSwitchRegForm', function( e ) { |
| 652 |
e.preventDefault(e); |
| 653 |
var self = jQuery(this); |
| 654 |
var form_id = self.attr('data-form_id'); |
| 655 |
var form = self.parents('form'); |
| 656 |
jQuery('#uwp-form-select a').removeClass('active'); |
| 657 |
|
| 658 |
uwp_load_register_form(form_id, form, self); |
| 659 |
}); |
| 660 |
|
| 661 |
// Handle select dropdown for normal forms |
| 662 |
jQuery( '#uwp-form-select select#uwp-form-type-select' ).off( 'change.uwpSwitchRegForm' ).on( 'change.uwpSwitchRegForm', function( e ) { |
| 663 |
var self = jQuery(this); |
| 664 |
var form_id = self.find('option:selected').attr('data-form_id'); |
| 665 |
var form = self.parents('form'); |
| 666 |
|
| 667 |
uwp_load_register_form(form_id, form); |
| 668 |
}); |
| 669 |
} |
| 670 |
|
| 671 |
/** |
| 672 |
* Submit the login form via ajax. |
| 673 |
*/ |
| 674 |
function uwp_modal_register_form_process(){ |
| 675 |
var data = jQuery(".modal-content form.uwp-registration-form").serialize() + '&action=uwp_ajax_register'; |
| 676 |
$button = jQuery('.uwp-auth-modal .modal-content .uwp_register_submit'); |
| 677 |
$button_text = $button.html(); |
| 678 |
jQuery.ajax({ |
| 679 |
type: "POST", |
| 680 |
url: uwp_localize_data.ajaxurl, |
| 681 |
data: data, |
| 682 |
beforeSend: function() { |
| 683 |
$button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit |
| 684 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages |
| 685 |
return uwp_maybe_check_recaptcha('register'); |
| 686 |
}, |
| 687 |
success: function(data) { |
| 688 |
if(data.success){ |
| 689 |
$button.html($button_text).prop('disabled', true);// remove spinner |
| 690 |
|
| 691 |
if(data.data.message){ |
| 692 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 693 |
jQuery(".modal-content form.uwp-registration-form").trigger('reset'); |
| 694 |
setTimeout(function(){ |
| 695 |
if(data.data.redirect){ |
| 696 |
window.location = data.data.redirect; |
| 697 |
} |
| 698 |
}, 3000); |
| 699 |
}else{ |
| 700 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 701 |
} |
| 702 |
|
| 703 |
}else if(data.success===false){ |
| 704 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data.message); |
| 705 |
$button.html($button_text).prop('disabled', false);// enable submit |
| 706 |
uwp_maybe_reset_recaptcha(); |
| 707 |
} |
| 708 |
uwp_init_auth_modal();aui_init_select2();uwp_switch_reg_form_init(); |
| 709 |
} |
| 710 |
}); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
/** |
| 715 |
* Get the forgot password form via ajax and load it in a modal. |
| 716 |
*/ |
| 717 |
function uwp_modal_forgot_password_form(){ |
| 718 |
var data = { |
| 719 |
'action': 'uwp_ajax_forgot_password_form' // deliberately no nonce for caching reasons |
| 720 |
}; |
| 721 |
jQuery.ajax({ |
| 722 |
type: "POST", |
| 723 |
url: uwp_localize_data.ajaxurl, |
| 724 |
data: data, |
| 725 |
beforeSend: function() { |
| 726 |
uwp_modal_loading(2); |
| 727 |
}, |
| 728 |
success: function(data) { |
| 729 |
if(data.success){ |
| 730 |
jQuery('.uwp-auth-modal .modal-content').html(data.data); |
| 731 |
setTimeout(function(){jQuery('.uwp-auth-modal .modal-content input:visible:enabled:first').focus().unbind('focus');}, 300); // set focus on the first input after load animation |
| 732 |
|
| 733 |
// process login form |
| 734 |
jQuery( '.uwp-auth-modal .modal-content form.uwp-forgot-form' ).on( 'submit', function( e ) { |
| 735 |
e.preventDefault(e); |
| 736 |
uwp_modal_forgot_password_form_process(); |
| 737 |
}); |
| 738 |
} |
| 739 |
uwp_init_auth_modal(); |
| 740 |
} |
| 741 |
}); |
| 742 |
} |
| 743 |
|
| 744 |
/** |
| 745 |
* Submit the forgot password form via ajax. |
| 746 |
*/ |
| 747 |
function uwp_modal_forgot_password_form_process(){ |
| 748 |
var data = jQuery(".modal-content form.uwp-forgot-form").serialize() + '&action=uwp_ajax_forgot_password'; |
| 749 |
$button = jQuery('.uwp-auth-modal .modal-content .uwp_forgot_submit'); |
| 750 |
$button_text = $button.html(); |
| 751 |
jQuery.ajax({ |
| 752 |
type: "POST", |
| 753 |
url: uwp_localize_data.ajaxurl, |
| 754 |
data: data, |
| 755 |
beforeSend: function() { |
| 756 |
$button.html('<i class="fas fa-circle-notch fa-spin"></i> ' + $button_text).prop('disabled', true);// disable submit |
| 757 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(''); // clear error messages |
| 758 |
return uwp_maybe_check_recaptcha('forgot'); |
| 759 |
}, |
| 760 |
success: function(data) { |
| 761 |
if(data.success){ |
| 762 |
$button.html($button_text).prop('disabled', true);// remove spinner |
| 763 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data); |
| 764 |
setTimeout(function(){ |
| 765 |
jQuery('.uwp-auth-modal').modal('hide'); |
| 766 |
}, 2000); |
| 767 |
}else if(data.success===false){ |
| 768 |
jQuery('.uwp-auth-modal .modal-content .modal-error').html(data.data); |
| 769 |
$button.html($button_text).prop('disabled', false);// enable submit |
| 770 |
uwp_maybe_reset_recaptcha(); |
| 771 |
} |
| 772 |
uwp_init_auth_modal(); |
| 773 |
} |
| 774 |
}); |
| 775 |
} |
| 776 |
|
| 777 |
/** |
| 778 |
* A password strength indicator. |
| 779 |
* |
| 780 |
* @param $pass1 |
| 781 |
* @param $pass2 |
| 782 |
* @param $strengthResult |
| 783 |
* @param $submitButton |
| 784 |
* @param blacklistArray |
| 785 |
* @returns {*|number} |
| 786 |
*/ |
| 787 |
function uwp_checkPasswordStrength( $pass1, |
| 788 |
$pass2, |
| 789 |
$strengthResult, |
| 790 |
$submitButton, |
| 791 |
blacklistArray ) { |
| 792 |
var pass1 = $pass1.val(); |
| 793 |
var pass2 = $pass2.val(); |
| 794 |
|
| 795 |
// maybe insert |
| 796 |
if(!jQuery('#uwp-password-strength').length && pass1){ |
| 797 |
if($pass2.length){ |
| 798 |
$container = $pass2.closest('.uwp-password-wrap'); |
| 799 |
}else{ |
| 800 |
$container = $pass1.closest('.uwp-password-wrap'); |
| 801 |
} |
| 802 |
$container.append( '<div class="progress mt-1"><div id="uwp-password-strength" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0;"></div></div>' ); |
| 803 |
$strengthResult = jQuery('#uwp-password-strength'); |
| 804 |
}else if(!pass1 && !pass2){ |
| 805 |
$strengthResult.parent().remove(); |
| 806 |
} |
| 807 |
|
| 808 |
if ( parseInt(uwp_localize_data.uwp_pass_strength) > 0 ) { |
| 809 |
$submitButton.attr('disabled', 'disabled'); |
| 810 |
} |
| 811 |
|
| 812 |
// Reset the form & meter |
| 813 |
$strengthResult.removeClass( 'short bad good strong bg-warning bg-success bg-danger' ); |
| 814 |
|
| 815 |
// Extend our blacklist array with those from the inputs & site data |
| 816 |
blacklistArray = blacklistArray.concat( wp.passwordStrength.userInputDisallowedList() ); |
| 817 |
|
| 818 |
// Get the password strength |
| 819 |
var strength = wp.passwordStrength.meter( pass1, blacklistArray, pass2 ); |
| 820 |
|
| 821 |
// Add the strength meter results |
| 822 |
switch ( strength ) { |
| 823 |
|
| 824 |
case -1: |
| 825 |
$strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.unknown ); |
| 826 |
break; |
| 827 |
|
| 828 |
case 2: |
| 829 |
$strengthResult.addClass( 'bad bg-danger' ).html( pwsL10n.bad ).width('50%'); |
| 830 |
break; |
| 831 |
|
| 832 |
case 3: |
| 833 |
$strengthResult.addClass( 'good bg-warning' ).html( pwsL10n.good ).width('75%'); |
| 834 |
break; |
| 835 |
|
| 836 |
case 4: |
| 837 |
$strengthResult.addClass( 'strong bg-success' ).html( pwsL10n.strong ).width('100%'); |
| 838 |
break; |
| 839 |
|
| 840 |
case 5: |
| 841 |
$strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.mismatch ).width('25%'); |
| 842 |
break; |
| 843 |
|
| 844 |
default: |
| 845 |
$strengthResult.addClass( 'short bg-danger' ).html( pwsL10n.short ).width('25%'); |
| 846 |
|
| 847 |
} |
| 848 |
|
| 849 |
// set the status of the submit button |
| 850 |
if ( parseInt(uwp_localize_data.uwp_pass_strength) > 0) { |
| 851 |
if($pass2.length){ |
| 852 |
$container = $pass2.closest('.uwp-password-wrap'); |
| 853 |
}else{ |
| 854 |
$container = $pass1.closest('.uwp-password-wrap'); |
| 855 |
} |
| 856 |
$container.find('small').remove(); |
| 857 |
|
| 858 |
if(4 == parseInt(uwp_localize_data.uwp_pass_strength) && strength === 4){ |
| 859 |
$submitButton.removeAttr( 'disabled' ); |
| 860 |
} else if(3 == parseInt(uwp_localize_data.uwp_pass_strength) && (strength === 3 || strength === 4)){ |
| 861 |
$submitButton.removeAttr( 'disabled' ); |
| 862 |
} else { |
| 863 |
$container.append("<small class='text-danger'>"+uwp_localize_data.uwp_strong_pass_msg+"</small>"); |
| 864 |
} |
| 865 |
} |
| 866 |
|
| 867 |
return strength; |
| 868 |
} |
| 869 |
|
| 870 |
/** |
| 871 |
* Prevent onclick affecting parent elements. |
| 872 |
* |
| 873 |
* @param e |
| 874 |
*/ |
| 875 |
function uwp_cancelBubble(e){ |
| 876 |
var evt = e ? e:window.event; |
| 877 |
if (evt.stopPropagation) evt.stopPropagation(); |
| 878 |
if (evt.cancelBubble!=null) evt.cancelBubble = true; |
| 879 |
} |
| 880 |
|
| 881 |
function uwp_gd_delete_post($post_id){ |
| 882 |
var message = geodir_params.my_place_listing_del; |
| 883 |
if (confirm(message)) { |
| 884 |
|
| 885 |
jQuery.ajax({ |
| 886 |
url: uwp_localize_data.ajaxurl, |
| 887 |
type: 'POST', |
| 888 |
dataType: 'json', |
| 889 |
data: { |
| 890 |
action: 'geodir_user_delete_post', |
| 891 |
security: geodir_params.basic_nonce, |
| 892 |
post_id: $post_id |
| 893 |
}, |
| 894 |
timeout: 20000, |
| 895 |
success: function(data) { |
| 896 |
|
| 897 |
if(data.success){ |
| 898 |
var $modal_content = '<div class="alert alert-success m-0"><i class="fas fa-check-circle"></i> '+ data.data.message +'</div>'; |
| 899 |
}else{ |
| 900 |
var $modal_content = '<div class="alert alert-danger m-0"><i class="fas fa-exclamation-circle"></i> '+ data.data.message +'</div>'; |
| 901 |
} |
| 902 |
|
| 903 |
var $modal = '<div class="modal fade uwp-gd-modal bsui" tabindex="-1" role="dialog" aria-labelledby="uwp-gd-modal-title" aria-hidden="true">' + |
| 904 |
'<div class="modal-dialog modal-dialog-centered">' + |
| 905 |
'<div class="modal-content">' + |
| 906 |
$modal_content + |
| 907 |
'</div></div></div>'; |
| 908 |
|
| 909 |
if(!jQuery('.uwp-gd-modal').length){ |
| 910 |
jQuery('body').append($modal); |
| 911 |
}else{ |
| 912 |
jQuery('.uwp-gd-modal .modal-content').html($modal_content); |
| 913 |
} |
| 914 |
|
| 915 |
// jQuery('.uwp-gd-modal').modal(); |
| 916 |
|
| 917 |
if ( window.bootstrap && window.bootstrap.Modal ) { |
| 918 |
var authModal = new window.bootstrap.Modal(document.querySelector('.uwp-gd-modal')); |
| 919 |
authModal.show(); |
| 920 |
} else { |
| 921 |
jQuery('.uwp-gd-modal').modal(); |
| 922 |
} |
| 923 |
|
| 924 |
if(data.success){ |
| 925 |
setTimeout(function() { |
| 926 |
location.reload(); |
| 927 |
}, 3000); |
| 928 |
} |
| 929 |
} |
| 930 |
}); |
| 931 |
|
| 932 |
return true; |
| 933 |
} else { |
| 934 |
return false; |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
/** |
| 939 |
* Use the same two-step AJAX login flow on an in-page form as the login modal. |
| 940 |
* This lets Wordfence validate the password first and return a separate 2FA form. |
| 941 |
*/ |
| 942 |
(function ($) { |
| 943 |
$(document).ready(function () { |
| 944 |
if (!uwp_localize_data.wordfence_2fa_active) { |
| 945 |
return; |
| 946 |
} |
| 947 |
|
| 948 |
$('form.uwp-login-form').each(function () { |
| 949 |
var $form = $(this); |
| 950 |
|
| 951 |
if ($form.closest('#uwp_login_modal, .uwp-auth-modal').length) { |
| 952 |
return; |
| 953 |
} |
| 954 |
|
| 955 |
$form.on('submit.uwpPageLogin', function (e) { |
| 956 |
e.preventDefault(); |
| 957 |
uwp_page_login_process($form); |
| 958 |
}); |
| 959 |
}); |
| 960 |
}); |
| 961 |
|
| 962 |
function uwp_page_login_process($form) { |
| 963 |
var $submit = $form.find('.uwp_login_submit'); |
| 964 |
var buttonText = $submit.html(); |
| 965 |
|
| 966 |
$form.prev('.alert').remove(); |
| 967 |
$submit.prop('disabled', true); |
| 968 |
|
| 969 |
$.post(uwp_localize_data.ajaxurl, $form.serialize() + '&action=uwp_ajax_login', function (response) { |
| 970 |
if (typeof response === 'string') { |
| 971 |
response = $.parseJSON(response); |
| 972 |
} |
| 973 |
|
| 974 |
if (response.success === true && response.data && response.data.is_2fa) { |
| 975 |
var $twoFactorMarkup = $(response.data.html); |
| 976 |
var $twoFactorForm = $twoFactorMarkup.filter('form.validate_2fa_form') |
| 977 |
.add($twoFactorMarkup.find('form.validate_2fa_form')).first(); |
| 978 |
|
| 979 |
$form.replaceWith($twoFactorMarkup); |
| 980 |
bind_2fa_form($twoFactorForm); |
| 981 |
$twoFactorForm.find('input:visible:enabled:first').trigger('focus'); |
| 982 |
return; |
| 983 |
} |
| 984 |
|
| 985 |
if (response.success === true) { |
| 986 |
if (response.data && response.data.message) { |
| 987 |
$form.before(response.data.message); |
| 988 |
} |
| 989 |
window.setTimeout(function () { |
| 990 |
if (response.data && response.data.redirect) { |
| 991 |
window.location.href = response.data.redirect; |
| 992 |
} else { |
| 993 |
window.location.reload(); |
| 994 |
} |
| 995 |
}, 1000); |
| 996 |
return; |
| 997 |
} |
| 998 |
|
| 999 |
$form.before(response.data && response.data.message ? response.data.message : response.message); |
| 1000 |
$submit.html(buttonText).prop('disabled', false); |
| 1001 |
document.dispatchEvent(new Event('ayecode_reset_captcha')); |
| 1002 |
}).fail(function () { |
| 1003 |
$submit.html(buttonText).prop('disabled', false); |
| 1004 |
}); |
| 1005 |
} |
| 1006 |
|
| 1007 |
function bind_2fa_form($form) { |
| 1008 |
$form.on('submit.uwpPageLogin2fa', function (e) { |
| 1009 |
e.preventDefault(); |
| 1010 |
|
| 1011 |
var $submit = $form.find('.uwp-2fa-submit'); |
| 1012 |
$form.prev('.alert').remove(); |
| 1013 |
$submit.prop('disabled', true); |
| 1014 |
|
| 1015 |
$.post(uwp_localize_data.ajaxurl, $form.serialize() + '&action=uwp_ajax_login_process_2fa', function (response) { |
| 1016 |
if (typeof response === 'string') { |
| 1017 |
response = $.parseJSON(response); |
| 1018 |
} |
| 1019 |
|
| 1020 |
$form.before(response.data && response.data.message ? response.data.message : response.message); |
| 1021 |
|
| 1022 |
if (response.success === true) { |
| 1023 |
window.setTimeout(function () { |
| 1024 |
if (response.data && response.data.redirect) { |
| 1025 |
window.location.href = response.data.redirect; |
| 1026 |
} else { |
| 1027 |
window.location.reload(); |
| 1028 |
} |
| 1029 |
}, 1000); |
| 1030 |
} else { |
| 1031 |
$submit.prop('disabled', false); |
| 1032 |
} |
| 1033 |
}).fail(function () { |
| 1034 |
$submit.prop('disabled', false); |
| 1035 |
}); |
| 1036 |
}); |
| 1037 |
} |
| 1038 |
})(jQuery); |