| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | function refreshApprovedUserList( currentPage, searchTerm ) { |
| 20 | 20 | var $list = $( '#list_auth_settings_access_users_approved' ); |
| 21 | 21 | var $spinner = $( '<span class="spinner is-active"></span>' ).css({ |
| 22 | 22 | position: 'relative', |
| 23 | - top: '45%', | |
| 23 | + top: '40%', | |
| 24 | 24 | left: '-240px', |
| 25 | 25 | }); |
| 26 | 26 | var $overlay = $( '<div id="list_auth_settings_access_users_approved_overlay"></div>' ).css({ |
| 27 | 27 | 'background-color': '#f1f1f1', |
| @@ -27,9 +27,9 @@ | ||
| 27 | 27 | 'background-color': '#f1f1f1', |
| 28 | 28 | 'z-index': 1, |
| 29 | 29 | opacity: 0.8, |
| 30 | 30 | position: 'absolute', |
| 31 | - top: $list.position().top, | |
| 31 | + top: $list.position().top + parseInt( $list.css( 'margin-top' ) ), | |
| 32 | 32 | left: $list.position().left, |
| 33 | 33 | width: $list.width(), |
| 34 | 34 | height: $list.height(), |
| 35 | 35 | }); |
| @@ -102,35 +102,35 @@ | ||
| 102 | 102 | |
| 103 | 103 | // Update first page button. |
| 104 | 104 | var $first = $( '.first-page' ); |
| 105 | 105 | if ( $first.is( 'a' ) && currentPage <= 1 ) { |
| 106 | - $first.replaceWith( '<span class="first-page tablenav-pages-navspan" aria-hidden="true">«</span>' ); | |
| 106 | + $first.replaceWith( '<span class="button disabled first-page tablenav-pages-navspan" aria-hidden="true">«</span>' ); | |
| 107 | 107 | } else if ( $first.is( 'span' ) && currentPage > 1 ) { |
| 108 | - $first.replaceWith( '<a class="first-page" href="' + updateQueryStringParameter( window.location.href, 'paged', '1' ) + '"><span class="screen-reader-text">' + authL10n.first_page + '</span><span aria-hidden="true">«</span></a>' ); | |
| 108 | + $first.replaceWith( '<a class="button first-page" href="' + updateQueryStringParameter( window.location.href, 'paged', '1' ) + '"><span class="screen-reader-text">' + authL10n.first_page + '</span><span aria-hidden="true">«</span></a>' ); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // Update prev page button. |
| 112 | 112 | var $prev = $( '.prev-page' ); |
| 113 | 113 | if ( $prev.is( 'a' ) && currentPage <= 1 ) { |
| 114 | - $prev.replaceWith( '<span class="prev-page tablenav-pages-navspan" aria-hidden="true">‹</span>' ); | |
| 114 | + $prev.replaceWith( '<span class="button disabled prev-page tablenav-pages-navspan" aria-hidden="true">‹</span>' ); | |
| 115 | 115 | } else if ( currentPage > 1 ) { |
| 116 | - $prev.replaceWith( '<a class="prev-page" href="' + updateQueryStringParameter( window.location.href, 'paged', currentPage - 1 ) + '"><span class="screen-reader-text">' + authL10n.prev_page + '</span><span aria-hidden="true">‹</span></a>' ); | |
| 116 | + $prev.replaceWith( '<a class="button prev-page" href="' + updateQueryStringParameter( window.location.href, 'paged', currentPage - 1 ) + '"><span class="screen-reader-text">' + authL10n.prev_page + '</span><span aria-hidden="true">‹</span></a>' ); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | // Update next button. |
| 120 | 120 | var $next = $( '.next-page' ); |
| 121 | 121 | if ( $next.is( 'a' ) && currentPage >= totalPages ) { |
| 122 | - $next.replaceWith( '<span class="next-page tablenav-pages-navspan" aria-hidden="true">›</span>' ); | |
| 122 | + $next.replaceWith( '<span class="button disabled next-page tablenav-pages-navspan" aria-hidden="true">›</span>' ); | |
| 123 | 123 | } else if ( currentPage < totalPages ) { |
| 124 | - $next.replaceWith( '<a class="next-page" href="' + updateQueryStringParameter( window.location.href, 'paged', currentPage + 1 ) + '"><span class="screen-reader-text">' + authL10n.next_page + '</span><span aria-hidden="true">›</span></a>' ); | |
| 124 | + $next.replaceWith( '<a class="button next-page" href="' + updateQueryStringParameter( window.location.href, 'paged', currentPage + 1 ) + '"><span class="screen-reader-text">' + authL10n.next_page + '</span><span aria-hidden="true">›</span></a>' ); | |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // Update last button. |
| 128 | 128 | var $last = $( '.last-page' ); |
| 129 | 129 | if ( $last.is( 'a' ) && currentPage >= totalPages ) { |
| 130 | - $last.replaceWith( '<span class="last-page tablenav-pages-navspan" aria-hidden="true">»</span>' ); | |
| 130 | + $last.replaceWith( '<span class="button disabled last-page tablenav-pages-navspan" aria-hidden="true">»</span>' ); | |
| 131 | 131 | } else if ( $last.is( 'span' ) && currentPage < totalPages ) { |
| 132 | - $last.replaceWith( '<a class="last-page" href="' + updateQueryStringParameter( window.location.href, 'paged', totalPages ) + '"><span class="screen-reader-text">' + authL10n.next_page + '</span><span aria-hidden="true">»</span></a>' ); | |
| 132 | + $last.replaceWith( '<a class="button last-page" href="' + updateQueryStringParameter( window.location.href, 'paged', totalPages ) + '"><span class="screen-reader-text">' + authL10n.next_page + '</span><span aria-hidden="true">»</span></a>' ); | |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | // Make changes to one of the user lists (pending, approved, blocked) via ajax. |
| @@ -198,9 +198,9 @@ | ||
| 198 | 198 | nonce: nonce, |
| 199 | 199 | }, function( response ) { |
| 200 | 200 | // Server responded, but if success isn't true it failed to save. |
| 201 | 201 | var succeeded = response.success; |
| 202 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 202 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 203 | 203 | var spinnerWait = succeeded ? 500 : 2000; |
| 204 | 204 | |
| 205 | 205 | // Remove any new user entries that were rejected by the server. |
| 206 | 206 | if ( response.invalid_emails.length > 0 ) { |
| @@ -206,10 +206,10 @@ | ||
| 206 | 206 | if ( response.invalid_emails.length > 0 ) { |
| 207 | 207 | for ( var i = 0; i < response.invalid_emails.length; i++ ) { |
| 208 | 208 | var duplicateEmail = response.invalid_emails[i]; |
| 209 | 209 | $( 'li.new-user .auth-email[value="' + duplicateEmail + '"]' ) |
| 210 | - .siblings( '.spinner' ).addClass( 'duplicate' ).append( '<span class="spinner-text" style="color: red;">' + authL10n.duplicate + '.</span>' ) | |
| 211 | - .parent().fadeOut( spinnerWait, function() { $( this ).remove(); }); // jshint ignore:line | |
| 210 | + .siblings( '.spinner' ).addClass( 'duplicate' ).append( '<span class="spinner-text"><span class="attention">' + authL10n.duplicate + '.</span></span>' ) | |
| 211 | + .parent().fadeOut( 2000, function() { $( this ).remove(); }); // jshint ignore:line | |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Show message ('Saved', 'Failed', or 'Saved, removing duplicates'). |
| @@ -222,9 +222,9 @@ | ||
| 222 | 222 | $( 'html' ).removeClass( 'busy' ); |
| 223 | 223 | }).fail( function() { |
| 224 | 224 | // Fail fires if the server doesn't respond or responds with 500 codes |
| 225 | 225 | var succeeded = false; |
| 226 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 226 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 227 | 227 | var spinnerWait = succeeded ? 500 : 2000; |
| 228 | 228 | $( 'form .spinner:not(:has(.spinner-text))' ).append( '<span class="spinner-text">' + spinnerText + '</span>' ).delay( spinnerWait ).hide( animationSpeed, function() { |
| 229 | 229 | $( this ).remove(); |
| 230 | 230 | }); |
| @@ -253,12 +253,11 @@ | ||
| 253 | 253 | 'z-index': 1, |
| 254 | 254 | opacity: 0.8, |
| 255 | 255 | position: 'absolute', |
| 256 | 256 | top: settings.position().top, |
| 257 | - left: settings.position().left - 20, | |
| 258 | - width: '100%', | |
| 259 | - height: settings.height(), | |
| 260 | - 'padding-left': 20, | |
| 257 | + left: settings.position().left, | |
| 258 | + width: settings.width(), | |
| 259 | + height: settings.height() + 50, | |
| 261 | 260 | }); |
| 262 | 261 | overlay.show(); |
| 263 | 262 | } |
| 264 | 263 | } |
| @@ -273,17 +272,16 @@ | ||
| 273 | 272 | |
| 274 | 273 | // Helper function to hide/show wordpress option |
| 275 | 274 | function animateOption( action, option ) { |
| 276 | 275 | if ( action === 'show' ) { |
| 277 | - $( 'div.animated_wrapper', option ).slideDown( animationSpeed ); | |
| 278 | - $( 'th', option ).animate({ padding: '20px 10px 20px 0' }, { duration: animationSpeed }); | |
| 279 | - $( 'td', option ).animate({ padding: '15px 10px' }, { duration: animationSpeed }); | |
| 276 | + option.fadeIn( animationSpeed ); | |
| 277 | + $( 'th, td', option ).removeClass( 'hide-animate hide-no-animate' ); | |
| 280 | 278 | } else if ( action === 'hide' ) { |
| 281 | - $( 'div.animated_wrapper', option ).slideUp( animationSpeed ); | |
| 282 | - $( 'td, th', option ).animate({ padding: '0px' }, { duration: animationSpeed }); | |
| 279 | + option.fadeOut( animationSpeed ); | |
| 280 | + $( 'td, th', option ).addClass( 'hide-animate' ); | |
| 283 | 281 | } else if ( action === 'hide_immediately' ) { |
| 284 | - $( 'div.animated_wrapper', option ).hide(); | |
| 285 | - $( 'td, th', option ).css({ padding: '0px' }); | |
| 282 | + option.hide(); | |
| 283 | + $( 'td, th', option ).addClass( 'hide-no-animate' ); | |
| 286 | 284 | } |
| 287 | 285 | } |
| 288 | 286 | |
| 289 | 287 | // Helper function to grab a querystring param value by name |
| @@ -329,12 +327,14 @@ | ||
| 329 | 327 | } |
| 330 | 328 | return matchingValues; |
| 331 | 329 | } |
| 332 | 330 | |
| 333 | - // Helper function to check if an email address is valid. | |
| 334 | - function validEmail( email ) { | |
| 331 | + // Helper function to check if an email address is valid. If allowWildcardEmail | |
| 332 | + // is true, then any string starting with an @ is valid. | |
| 333 | + function validEmail( email, allowWildcardEmail ) { | |
| 334 | + allowWildcardEmail = typeof allowWildcardEmail !== 'undefined' ? allowWildcardEmail : false; | |
| 335 | 335 | var re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| 336 | - return email.length > 0 && re.test( email ); | |
| 336 | + return email.length > 0 && ( re.test( email ) || email.startsWith( '@' ) ); | |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Helper function to set or update a querystring value. |
| 340 | 340 | function updateQueryStringParameter( uri, key, value ) { |
| @@ -373,8 +373,9 @@ | ||
| 373 | 373 | $( document ).ready( function() { |
| 374 | 374 | // Grab references to form elements that we will show/hide on page load |
| 375 | 375 | /* eslint-disable camelcase */ |
| 376 | 376 | var auth_settings_access_role_receive_pending_emails = $( '#auth_settings_access_role_receive_pending_emails' ).closest( 'tr' ); |
| 377 | + var auth_settings_access_users_receive_pending_emails = $( '#auth_settings_access_users_receive_pending_emails' ).closest( 'tr' ); | |
| 377 | 378 | var auth_settings_access_pending_redirect_to_message = $( '#wp-auth_settings_access_pending_redirect_to_message-wrap' ).closest( 'tr' ); |
| 378 | 379 | var auth_settings_access_blocked_redirect_to_message = $( '#wp-auth_settings_access_blocked_redirect_to_message-wrap' ).closest( 'tr' ); |
| 379 | 380 | var auth_settings_access_should_email_approved_users = $( '#auth_settings_access_should_email_approved_users' ).closest( 'tr' ); |
| 380 | 381 | var auth_settings_access_email_approved_users_subject = $( '#auth_settings_access_email_approved_users_subject' ).closest( 'tr' ); |
| @@ -382,24 +383,87 @@ | ||
| 382 | 383 | var auth_settings_access_public_pages = $( '#auth_settings_access_public_pages' ).closest( 'tr' ); |
| 383 | 384 | var auth_settings_access_redirect_to_login = $( '#radio_auth_settings_access_redirect_to_login' ).closest( 'tr' ); |
| 384 | 385 | var auth_settings_access_public_warning = $( '#radio_auth_settings_access_public_warning' ).closest( 'tr' ); |
| 385 | 386 | var auth_settings_access_redirect_to_message = $( '#wp-auth_settings_access_redirect_to_message-wrap' ).closest( 'tr' ); |
| 387 | + var auth_settings_external_oauth2_auto_login = $( '#auth_settings_oauth2_auto_login' ).closest( 'tr' ); | |
| 388 | + var auth_settings_external_oauth2_num_servers = $( '#auth_settings_oauth2_num_servers' ).closest( 'tr' ); | |
| 389 | + var auth_settings_external_oauth2_servers = []; | |
| 390 | + // OAuth2 settings below are for the first configured OAuth2 server. | |
| 391 | + auth_settings_external_oauth2_servers.push( { | |
| 392 | + provider: $( '#auth_settings_oauth2_provider' ).closest( 'tr' ), | |
| 393 | + custom_label: $( '#auth_settings_oauth2_custom_label' ).closest( 'tr' ), | |
| 394 | + clientid: $( '#auth_settings_oauth2_clientid' ).closest( 'tr' ), | |
| 395 | + clientsecret: $( '#auth_settings_oauth2_clientsecret' ).closest( 'tr' ), | |
| 396 | + hosteddomain: $( '#auth_settings_oauth2_hosteddomain' ).closest( 'tr' ), | |
| 397 | + tenant_id: $( '#auth_settings_oauth2_tenant_id' ).closest( 'tr' ), | |
| 398 | + url_authorize: $( '#auth_settings_oauth2_url_authorize' ).closest( 'tr' ), | |
| 399 | + url_token: $( '#auth_settings_oauth2_url_token' ).closest( 'tr' ), | |
| 400 | + url_resource: $( '#auth_settings_oauth2_url_resource' ).closest( 'tr' ), | |
| 401 | + attr_username: $( '#auth_settings_oauth2_attr_username' ).closest( 'tr' ), | |
| 402 | + attr_email: $( '#auth_settings_oauth2_attr_email' ).closest( 'tr' ), | |
| 403 | + attr_first_name: $( '#auth_settings_oauth2_attr_first_name' ).closest( 'tr' ), | |
| 404 | + attr_last_name: $( '#auth_settings_oauth2_attr_last_name' ).closest( 'tr' ), | |
| 405 | + attr_update_on_login: $( '#auth_settings_oauth2_attr_update_on_login' ).closest( 'tr' ), | |
| 406 | + } ); | |
| 407 | + // OAuth2 settings below are for any additional OAuth2 servers configured (up to 20). | |
| 408 | + for ( var i = 2; i <= parseInt( $( '#auth_settings_oauth2_num_servers' ).val() ) && i <= 20; i++ ) { | |
| 409 | + auth_settings_external_oauth2_servers.push( { | |
| 410 | + provider: $( '#auth_settings_oauth2_provider_' + i ).closest( 'tr' ), | |
| 411 | + custom_label: $( '#auth_settings_oauth2_custom_label_' + i ).closest( 'tr' ), | |
| 412 | + clientid: $( '#auth_settings_oauth2_clientid_' + i ).closest( 'tr' ), | |
| 413 | + clientsecret: $( '#auth_settings_oauth2_clientsecret_' + i ).closest( 'tr' ), | |
| 414 | + hosteddomain: $( '#auth_settings_oauth2_hosteddomain_' + i ).closest( 'tr' ), | |
| 415 | + tenant_id: $( '#auth_settings_oauth2_tenant_id_' + i ).closest( 'tr' ), | |
| 416 | + url_authorize: $( '#auth_settings_oauth2_url_authorize_' + i ).closest( 'tr' ), | |
| 417 | + url_token: $( '#auth_settings_oauth2_url_token_' + i ).closest( 'tr' ), | |
| 418 | + url_resource: $( '#auth_settings_oauth2_url_resource_' + i ).closest( 'tr' ), | |
| 419 | + attr_username: $( '#auth_settings_oauth2_attr_username_' + i ).closest( 'tr' ), | |
| 420 | + attr_email: $( '#auth_settings_oauth2_attr_email_' + i ).closest( 'tr' ), | |
| 421 | + attr_first_name: $( '#auth_settings_oauth2_attr_first_name_' + i ).closest( 'tr' ), | |
| 422 | + attr_last_name: $( '#auth_settings_oauth2_attr_last_name_' + i ).closest( 'tr' ), | |
| 423 | + attr_update_on_login: $( '#auth_settings_oauth2_attr_update_on_login_' + i ).closest( 'tr' ), | |
| 424 | + } ); | |
| 425 | + } | |
| 386 | 426 | var auth_settings_external_google_clientid = $( '#auth_settings_google_clientid' ).closest( 'tr' ); |
| 387 | 427 | var auth_settings_external_google_clientsecret = $( '#auth_settings_google_clientsecret' ).closest( 'tr' ); |
| 388 | 428 | var auth_settings_external_google_hosteddomain = $( '#auth_settings_google_hosteddomain' ).closest( 'tr' ); |
| 389 | - var auth_settings_external_cas_custom_label = $( '#auth_settings_cas_custom_label' ).closest( 'tr' ); | |
| 390 | - var auth_settings_external_cas_host = $( '#auth_settings_cas_host' ).closest( 'tr' ); | |
| 391 | - var auth_settings_external_cas_port = $( '#auth_settings_cas_port' ).closest( 'tr' ); | |
| 392 | - var auth_settings_external_cas_path = $( '#auth_settings_cas_path' ).closest( 'tr' ); | |
| 393 | - var auth_settings_external_cas_version = $( '#auth_settings_cas_version' ).closest( 'tr' ); | |
| 394 | - var auth_settings_external_cas_attr_email = $( '#auth_settings_cas_attr_email' ).closest( 'tr' ); | |
| 395 | - var auth_settings_external_cas_attr_first_name = $( '#auth_settings_cas_attr_first_name' ).closest( 'tr' ); | |
| 396 | - var auth_settings_external_cas_attr_last_name = $( '#auth_settings_cas_attr_last_name' ).closest( 'tr' ); | |
| 397 | - var auth_settings_external_cas_attr_update_on_login = $( '#auth_settings_cas_attr_update_on_login' ).closest( 'tr' ); | |
| 398 | 429 | var auth_settings_external_cas_auto_login = $( '#auth_settings_cas_auto_login' ).closest( 'tr' ); |
| 430 | + var auth_settings_external_cas_num_servers = $( '#auth_settings_cas_num_servers' ).closest( 'tr' ); | |
| 431 | + var auth_settings_external_cas_servers = []; | |
| 432 | + // CAS settings below are for the first configured CAS server. | |
| 433 | + auth_settings_external_cas_servers.push( { | |
| 434 | + custom_label: $( '#auth_settings_cas_custom_label' ).closest( 'tr' ), | |
| 435 | + host: $( '#auth_settings_cas_host' ).closest( 'tr' ), | |
| 436 | + port: $( '#auth_settings_cas_port' ).closest( 'tr' ), | |
| 437 | + path: $( '#auth_settings_cas_path' ).closest( 'tr' ), | |
| 438 | + method: $( '#auth_settings_cas_method' ).closest( 'tr' ), | |
| 439 | + version: $( '#auth_settings_cas_version' ).closest( 'tr' ), | |
| 440 | + attr_email: $( '#auth_settings_cas_attr_email' ).closest( 'tr' ), | |
| 441 | + attr_first_name: $( '#auth_settings_cas_attr_first_name' ).closest( 'tr' ), | |
| 442 | + attr_last_name: $( '#auth_settings_cas_attr_last_name' ).closest( 'tr' ), | |
| 443 | + attr_update_on_login: $( '#auth_settings_cas_attr_update_on_login' ).closest( 'tr' ), | |
| 444 | + link_on_username: $( '#auth_settings_cas_link_on_username' ).closest( 'tr' ), | |
| 445 | + } ); | |
| 446 | + // CAS settings below are for any additional CAS servers configured (up to 10). | |
| 447 | + for ( var i = 2; i <= parseInt( $( '#auth_settings_cas_num_servers' ).val() ) && i <= 10; i++ ) { | |
| 448 | + auth_settings_external_cas_servers.push( { | |
| 449 | + custom_label: $( '#auth_settings_cas_custom_label_' + i ).closest( 'tr' ), | |
| 450 | + host: $( '#auth_settings_cas_host_' + i ).closest( 'tr' ), | |
| 451 | + port: $( '#auth_settings_cas_port_' + i ).closest( 'tr' ), | |
| 452 | + path: $( '#auth_settings_cas_path_' + i ).closest( 'tr' ), | |
| 453 | + method: $( '#auth_settings_cas_method_' + i ).closest( 'tr' ), | |
| 454 | + version: $( '#auth_settings_cas_version_' + i ).closest( 'tr' ), | |
| 455 | + attr_email: $( '#auth_settings_cas_attr_email_' + i ).closest( 'tr' ), | |
| 456 | + attr_first_name: $( '#auth_settings_cas_attr_first_name_' + i ).closest( 'tr' ), | |
| 457 | + attr_last_name: $( '#auth_settings_cas_attr_last_name_' + i ).closest( 'tr' ), | |
| 458 | + attr_update_on_login: $( '#auth_settings_cas_attr_update_on_login_' + i ).closest( 'tr' ), | |
| 459 | + link_on_username: $( '#auth_settings_cas_link_on_username_' + i ).closest( 'tr' ), | |
| 460 | + } ); | |
| 461 | + } | |
| 399 | 462 | var auth_settings_external_ldap_host = $( '#auth_settings_ldap_host' ).closest( 'tr' ); |
| 400 | 463 | var auth_settings_external_ldap_port = $( '#auth_settings_ldap_port' ).closest( 'tr' ); |
| 401 | 464 | var auth_settings_external_ldap_search_base = $( '#auth_settings_ldap_search_base' ).closest( 'tr' ); |
| 465 | + var auth_settings_external_ldap_search_filter = $( '#auth_settings_ldap_search_filter' ).closest( 'tr' ); | |
| 402 | 466 | var auth_settings_external_ldap_uid = $( '#auth_settings_ldap_uid' ).closest( 'tr' ); |
| 403 | 467 | var auth_settings_external_ldap_attr_email = $( '#auth_settings_ldap_attr_email' ).closest( 'tr' ); |
| 404 | 468 | var auth_settings_external_ldap_user = $( '#auth_settings_ldap_user' ).closest( 'tr' ); |
| 405 | 469 | var auth_settings_external_ldap_password = $( '#auth_settings_ldap_password' ).closest( 'tr' ); |
| @@ -407,57 +471,16 @@ | ||
| 407 | 471 | var auth_settings_external_ldap_lostpassword_url = $( '#auth_settings_ldap_lostpassword_url' ).closest( 'tr' ); |
| 408 | 472 | var auth_settings_external_ldap_attr_first_name = $( '#auth_settings_ldap_attr_first_name' ).closest( 'tr' ); |
| 409 | 473 | var auth_settings_external_ldap_attr_last_name = $( '#auth_settings_ldap_attr_last_name' ).closest( 'tr' ); |
| 410 | 474 | var auth_settings_external_ldap_attr_update_on_login = $( '#auth_settings_ldap_attr_update_on_login' ).closest( 'tr' ); |
| 475 | + var auth_settings_external_ldap_test_user = $( '#auth_settings_ldap_test_user' ).closest( 'tr' ); | |
| 476 | + var auth_settings_advanced_disable_wp_login_bypass_usernames = $( '#auth_settings_advanced_disable_wp_login_bypass_usernames' ).closest( 'tr' ); | |
| 411 | 477 | /* eslint-enable */ |
| 412 | 478 | |
| 413 | - // Wrap the th and td in the rows above so we can animate their heights (can't animate tr heights with jquery) | |
| 414 | - $( 'th, td', auth_settings_access_role_receive_pending_emails ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 415 | - $( 'th, td', auth_settings_access_pending_redirect_to_message ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 416 | - $( 'th, td', auth_settings_access_blocked_redirect_to_message ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 417 | - $( 'th, td', auth_settings_access_should_email_approved_users ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 418 | - $( 'th, td', auth_settings_access_email_approved_users_subject ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 419 | - $( 'th, td', auth_settings_access_email_approved_users_body ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 420 | - $( 'th, td', auth_settings_access_public_pages ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 421 | - $( 'th, td', auth_settings_access_redirect_to_login ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 422 | - $( 'th, td', auth_settings_access_public_warning ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 423 | - $( 'th, td', auth_settings_access_redirect_to_message ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 424 | - $( 'th, td', auth_settings_external_google_clientid ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 425 | - $( 'th, td', auth_settings_external_google_clientsecret ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 426 | - $( 'th, td', auth_settings_external_google_hosteddomain ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 427 | - $( 'th, td', auth_settings_external_cas_custom_label ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 428 | - $( 'th, td', auth_settings_external_cas_host ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 429 | - $( 'th, td', auth_settings_external_cas_port ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 430 | - $( 'th, td', auth_settings_external_cas_path ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 431 | - $( 'th, td', auth_settings_external_cas_version ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 432 | - $( 'th, td', auth_settings_external_cas_attr_email ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 433 | - $( 'th, td', auth_settings_external_cas_attr_first_name ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 434 | - $( 'th, td', auth_settings_external_cas_attr_last_name ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 435 | - $( 'th, td', auth_settings_external_cas_attr_update_on_login ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 436 | - $( 'th, td', auth_settings_external_cas_auto_login ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 437 | - $( 'th, td', auth_settings_external_ldap_host ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 438 | - $( 'th, td', auth_settings_external_ldap_port ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 439 | - $( 'th, td', auth_settings_external_ldap_search_base ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 440 | - $( 'th, td', auth_settings_external_ldap_uid ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 441 | - $( 'th, td', auth_settings_external_ldap_attr_email ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 442 | - $( 'th, td', auth_settings_external_ldap_user ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 443 | - $( 'th, td', auth_settings_external_ldap_password ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 444 | - $( 'th, td', auth_settings_external_ldap_tls ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 445 | - $( 'th, td', auth_settings_external_ldap_lostpassword_url ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 446 | - $( 'th, td', auth_settings_external_ldap_attr_first_name ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 447 | - $( 'th, td', auth_settings_external_ldap_attr_last_name ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 448 | - $( 'th, td', auth_settings_external_ldap_attr_update_on_login ).wrapInner( '<div class="animated_wrapper" />' ); | |
| 449 | - | |
| 450 | - // If we're viewing the dashboard widget, reset a couple of the relevant | |
| 451 | - // option variables (since they aren't nested in table rows). | |
| 452 | - if ( $( '#auth_dashboard_widget' ).length ) { | |
| 453 | - // Remove the helper link, since there are no tabs on the dashboard widget | |
| 454 | - $( '#dashboard_link_approved_users' ).contents().unwrap(); | |
| 455 | - } | |
| 456 | - | |
| 457 | 479 | // Hide settings unless "Only approved users" is checked |
| 458 | 480 | if ( ! $( '#radio_auth_settings_access_who_can_login_approved_users' ).is( ':checked' ) ) { |
| 459 | 481 | animateOption( 'hide_immediately', auth_settings_access_role_receive_pending_emails ); |
| 482 | + animateOption( 'hide_immediately', auth_settings_access_users_receive_pending_emails ); | |
| 460 | 483 | animateOption( 'hide_immediately', auth_settings_access_pending_redirect_to_message ); |
| 461 | 484 | animateOption( 'hide_immediately', auth_settings_access_blocked_redirect_to_message ); |
| 462 | 485 | animateOption( 'hide_immediately', auth_settings_access_should_email_approved_users ); |
| 463 | 486 | } |
| @@ -475,50 +498,45 @@ | ||
| 475 | 498 | animateOption( 'hide_immediately', auth_settings_access_public_warning ); |
| 476 | 499 | animateOption( 'hide_immediately', auth_settings_access_redirect_to_message ); |
| 477 | 500 | } |
| 478 | 501 | |
| 479 | - // Hide Google options if unchecked | |
| 480 | - if ( ! $( '#auth_settings_google' ).is( ':checked' ) ) { | |
| 481 | - animateOption( 'hide_immediately', auth_settings_external_google_clientid ); | |
| 482 | - animateOption( 'hide_immediately', auth_settings_external_google_clientsecret ); | |
| 483 | - animateOption( 'hide_immediately', auth_settings_external_google_hosteddomain ); | |
| 484 | - } | |
| 502 | + // Hide External Service tabs if provider is unchecked. | |
| 503 | + $( '.nav-tab-wrapper .nav-tab-external_oauth2' ).toggle( $( '#auth_settings_oauth2' ).is( ':checked' ) ); | |
| 504 | + $( '.nav-tab-wrapper .nav-tab-external_oidc' ).toggle( $( '#auth_settings_oidc' ).is( ':checked' ) ); | |
| 505 | + $( '.nav-tab-wrapper .nav-tab-external_google' ).toggle( $( '#auth_settings_google' ).is( ':checked' ) ); | |
| 506 | + $( '.nav-tab-wrapper .nav-tab-external_cas' ).toggle( $( '#auth_settings_cas' ).is( ':checked' ) ); | |
| 507 | + $( '.nav-tab-wrapper .nav-tab-external_ldap' ).toggle( $( '#auth_settings_ldap' ).is( ':checked' ) ); | |
| 485 | 508 | |
| 486 | - // Hide CAS options if unchecked | |
| 487 | - if ( ! $( '#auth_settings_cas' ).is( ':checked' ) ) { | |
| 488 | - animateOption( 'hide_immediately', auth_settings_external_cas_custom_label ); | |
| 489 | - animateOption( 'hide_immediately', auth_settings_external_cas_host ); | |
| 490 | - animateOption( 'hide_immediately', auth_settings_external_cas_port ); | |
| 491 | - animateOption( 'hide_immediately', auth_settings_external_cas_path ); | |
| 492 | - animateOption( 'hide_immediately', auth_settings_external_cas_version ); | |
| 493 | - animateOption( 'hide_immediately', auth_settings_external_cas_attr_email ); | |
| 494 | - animateOption( 'hide_immediately', auth_settings_external_cas_attr_first_name ); | |
| 495 | - animateOption( 'hide_immediately', auth_settings_external_cas_attr_last_name ); | |
| 496 | - animateOption( 'hide_immediately', auth_settings_external_cas_attr_update_on_login ); | |
| 497 | - animateOption( 'hide_immediately', auth_settings_external_cas_auto_login ); | |
| 498 | - } | |
| 509 | + // Hide some OAuth2 options based on current settings. | |
| 510 | + auth_settings_external_oauth2_servers.forEach( function( server ) { | |
| 511 | + // Hide OAuth2 generic options if OAuth2 provider is unchecked or generic isn't chosen. | |
| 512 | + if ( 'generic' !== server.provider.find( 'select' ).val() ) { | |
| 513 | + animateOption( 'hide_immediately', server.url_authorize ); | |
| 514 | + animateOption( 'hide_immediately', server.url_token ); | |
| 515 | + animateOption( 'hide_immediately', server.url_resource ); | |
| 516 | + animateOption( 'hide_immediately', server.attr_username ); | |
| 517 | + animateOption( 'hide_immediately', server.attr_email ); | |
| 518 | + animateOption( 'hide_immediately', server.attr_first_name ); | |
| 519 | + animateOption( 'hide_immediately', server.attr_last_name ); | |
| 520 | + animateOption( 'hide_immediately', server.attr_update_on_login ); | |
| 521 | + } | |
| 522 | + // Hide OAuth2 Tenant ID if OAuth2 provider is unchecked or azure isn't chosen. | |
| 523 | + if ( 'azure' !== server.provider.find( 'select' ).val() ) { | |
| 524 | + animateOption( 'hide_immediately', server.tenant_id ); | |
| 525 | + } | |
| 526 | + } ); | |
| 499 | 527 | |
| 500 | - // Hide LDAP options if unchecked | |
| 501 | - if ( ! $( '#auth_settings_ldap' ).is( ':checked' ) ) { | |
| 502 | - animateOption( 'hide_immediately', auth_settings_external_ldap_host ); | |
| 503 | - animateOption( 'hide_immediately', auth_settings_external_ldap_port ); | |
| 504 | - animateOption( 'hide_immediately', auth_settings_external_ldap_search_base ); | |
| 505 | - animateOption( 'hide_immediately', auth_settings_external_ldap_uid ); | |
| 506 | - animateOption( 'hide_immediately', auth_settings_external_ldap_attr_email ); | |
| 507 | - animateOption( 'hide_immediately', auth_settings_external_ldap_user ); | |
| 508 | - animateOption( 'hide_immediately', auth_settings_external_ldap_password ); | |
| 509 | - animateOption( 'hide_immediately', auth_settings_external_ldap_tls ); | |
| 510 | - animateOption( 'hide_immediately', auth_settings_external_ldap_lostpassword_url ); | |
| 511 | - animateOption( 'hide_immediately', auth_settings_external_ldap_attr_first_name ); | |
| 512 | - animateOption( 'hide_immediately', auth_settings_external_ldap_attr_last_name ); | |
| 513 | - animateOption( 'hide_immediately', auth_settings_external_ldap_attr_update_on_login ); | |
| 528 | + // Hide Bypass Usernames if Disable WordPress logins is unchecked. | |
| 529 | + if ( ! $( '#auth_settings_advanced_disable_wp_login' ).is( ':checked' ) ) { | |
| 530 | + animateOption( 'hide_immediately', auth_settings_advanced_disable_wp_login_bypass_usernames ); | |
| 514 | 531 | } |
| 515 | 532 | |
| 516 | 533 | // Event handler: Hide "Handle unauthorized visitors" option if access is granted to "Everyone" |
| 517 | - $( 'input[name="auth_settings[access_who_can_login]"]' ).change( function() { | |
| 534 | + $( 'input[name="auth_settings[access_who_can_login]"]' ).on( 'change', function() { | |
| 518 | 535 | // Hide settings unless "Only approved users" is checked |
| 519 | 536 | var action = $( '#radio_auth_settings_access_who_can_login_approved_users' ).is( ':checked' ) ? 'show' : 'hide'; |
| 520 | 537 | animateOption( action, auth_settings_access_role_receive_pending_emails ); |
| 538 | + animateOption( action, auth_settings_access_users_receive_pending_emails ); | |
| 521 | 539 | animateOption( action, auth_settings_access_pending_redirect_to_message ); |
| 522 | 540 | animateOption( action, auth_settings_access_blocked_redirect_to_message ); |
| 523 | 541 | animateOption( action, auth_settings_access_should_email_approved_users ); |
| 524 | 542 | action = action === 'show' && $( '#auth_settings_access_should_email_approved_users' ).is( ':checked' ) ? 'show' : 'hide_immediately'; |
| @@ -526,9 +544,9 @@ | ||
| 526 | 544 | animateOption( action, auth_settings_access_email_approved_users_body ); |
| 527 | 545 | }); |
| 528 | 546 | |
| 529 | 547 | // Event handler: Hide Welcome email body/subject options if "Send welcome email" is off. |
| 530 | - $( 'input[name="auth_settings[access_should_email_approved_users]"]' ).change( function() { | |
| 548 | + $( 'input[name="auth_settings[access_should_email_approved_users]"]' ).on( 'change', function() { | |
| 531 | 549 | var action = $( this ).is( ':checked' ) ? 'show' : 'hide'; |
| 532 | 550 | animateOption( action, auth_settings_access_email_approved_users_subject ); |
| 533 | 551 | animateOption( action, auth_settings_access_email_approved_users_body ); |
| 534 | 552 | }); |
| @@ -533,9 +551,9 @@ | ||
| 533 | 551 | animateOption( action, auth_settings_access_email_approved_users_body ); |
| 534 | 552 | }); |
| 535 | 553 | |
| 536 | 554 | // Event handler: Hide "Handle unauthorized visitors" option if access is granted to "Everyone" |
| 537 | - $( 'input[name="auth_settings[access_who_can_view]"]' ).change( function() { | |
| 555 | + $( 'input[name="auth_settings[access_who_can_view]"]' ).on( 'change', function() { | |
| 538 | 556 | var action = $( '#radio_auth_settings_access_who_can_view_everyone' ).is( ':checked' ) ? 'hide' : 'show'; |
| 539 | 557 | animateOption( action, auth_settings_access_redirect_to_login ); |
| 540 | 558 | animateOption( action, auth_settings_access_redirect_to_message ); |
| 541 | 559 | animateOption( action, auth_settings_access_public_pages ); |
| @@ -541,48 +559,75 @@ | ||
| 541 | 559 | animateOption( action, auth_settings_access_public_pages ); |
| 542 | 560 | animateOption( action, auth_settings_access_public_warning ); |
| 543 | 561 | }); |
| 544 | 562 | |
| 545 | - // Event handler: Show/hide Google options based on checkbox | |
| 546 | - $( 'input[name="auth_settings[google]"]' ).change( function() { | |
| 547 | - var action = $( this ).is( ':checked' ) ? 'show' : 'hide'; | |
| 548 | - animateOption( action, auth_settings_external_google_clientid ); | |
| 549 | - animateOption( action, auth_settings_external_google_clientsecret ); | |
| 550 | - animateOption( action, auth_settings_external_google_hosteddomain ); | |
| 563 | + // Event handler: Show/hide OAuth2 tab based on checkbox. | |
| 564 | + $( 'input[name="auth_settings[oauth2]"]' ).on( 'change', function() { | |
| 565 | + $( '.nav-tab-wrapper .nav-tab-external_oauth2' ).toggle( $( this ).is( ':checked' ) ); | |
| 551 | 566 | }); |
| 552 | 567 | |
| 553 | - // Event handler: Show/hide CAS options based on checkbox | |
| 554 | - $( 'input[name="auth_settings[cas]"]' ).change( function() { | |
| 555 | - var action = $( this ).is( ':checked' ) ? 'show' : 'hide'; | |
| 556 | - animateOption( action, auth_settings_external_cas_custom_label ); | |
| 557 | - animateOption( action, auth_settings_external_cas_host ); | |
| 558 | - animateOption( action, auth_settings_external_cas_port ); | |
| 559 | - animateOption( action, auth_settings_external_cas_path ); | |
| 560 | - animateOption( action, auth_settings_external_cas_version ); | |
| 561 | - animateOption( action, auth_settings_external_cas_attr_email ); | |
| 562 | - animateOption( action, auth_settings_external_cas_attr_first_name ); | |
| 563 | - animateOption( action, auth_settings_external_cas_attr_last_name ); | |
| 564 | - animateOption( action, auth_settings_external_cas_attr_update_on_login ); | |
| 565 | - animateOption( action, auth_settings_external_cas_auto_login ); | |
| 568 | + // Event handler: Show/hide OAuth2 generic/azure options based on provider. | |
| 569 | + auth_settings_external_oauth2_servers.forEach( function( server ) { | |
| 570 | + server.provider.find( 'select' ).on( 'change', function() { | |
| 571 | + var action = 'generic' === $( this ).val() ? 'show' : 'hide'; | |
| 572 | + animateOption( action, server.url_authorize ); | |
| 573 | + animateOption( action, server.url_token ); | |
| 574 | + animateOption( action, server.url_resource ); | |
| 575 | + animateOption( action, server.attr_username ); | |
| 576 | + animateOption( action, server.attr_email ); | |
| 577 | + animateOption( action, server.attr_first_name ); | |
| 578 | + animateOption( action, server.attr_last_name ); | |
| 579 | + animateOption( action, server.attr_update_on_login ); | |
| 580 | + action = 'azure' === $( this ).val() ? 'show' : 'hide'; | |
| 581 | + animateOption( action, server.tenant_id ); | |
| 582 | + }); | |
| 566 | 583 | }); |
| 567 | 584 | |
| 568 | - // Event handler: Show/hide LDAP options based on checkbox | |
| 569 | - $( 'input[name="auth_settings[ldap]"]' ).change( function() { | |
| 585 | + // Event handler: Show/hide OIDC tab based on checkbox | |
| 586 | + $( 'input[name="auth_settings[oidc]"]' ).on( 'change', function() { | |
| 587 | + $( '.nav-tab-wrapper .nav-tab-external_oidc' ).toggle( $( this ).is( ':checked' ) ); | |
| 588 | + }); | |
| 589 | + | |
| 590 | + // Event handler: Show/hide Google tab based on checkbox | |
| 591 | + $( 'input[name="auth_settings[google]"]' ).on( 'change', function() { | |
| 592 | + $( '.nav-tab-wrapper .nav-tab-external_google' ).toggle( $( this ).is( ':checked' ) ); | |
| 593 | + }); | |
| 594 | + | |
| 595 | + // Event handler: Show/hide CAS tab based on checkbox | |
| 596 | + $( 'input[name="auth_settings[cas]"]' ).on( 'change', function() { | |
| 597 | + $( '.nav-tab-wrapper .nav-tab-external_cas' ).toggle( $( this ).is( ':checked' ) ); | |
| 598 | + }); | |
| 599 | + | |
| 600 | + // Event handler: Show/hide LDAP tab based on checkbox | |
| 601 | + $( 'input[name="auth_settings[ldap]"]' ).on( 'change', function() { | |
| 602 | + $( '.nav-tab-wrapper .nav-tab-external_ldap' ).toggle( $( this ).is( ':checked' ) ); | |
| 603 | + }); | |
| 604 | + | |
| 605 | + // Event handler: Show/hide Bypass Usernames based on Disable WordPress Logins checkbox. | |
| 606 | + $( 'input[name="auth_settings[advanced_disable_wp_login]"]' ).on( 'change', function() { | |
| 570 | 607 | var action = $( this ).is( ':checked' ) ? 'show' : 'hide'; |
| 571 | - animateOption( action, auth_settings_external_ldap_host ); | |
| 572 | - animateOption( action, auth_settings_external_ldap_port ); | |
| 573 | - animateOption( action, auth_settings_external_ldap_search_base ); | |
| 574 | - animateOption( action, auth_settings_external_ldap_uid ); | |
| 575 | - animateOption( action, auth_settings_external_ldap_attr_email ); | |
| 576 | - animateOption( action, auth_settings_external_ldap_user ); | |
| 577 | - animateOption( action, auth_settings_external_ldap_password ); | |
| 578 | - animateOption( action, auth_settings_external_ldap_tls ); | |
| 579 | - animateOption( action, auth_settings_external_ldap_lostpassword_url ); | |
| 580 | - animateOption( action, auth_settings_external_ldap_attr_first_name ); | |
| 581 | - animateOption( action, auth_settings_external_ldap_attr_last_name ); | |
| 582 | - animateOption( action, auth_settings_external_ldap_attr_update_on_login ); | |
| 608 | + animateOption( action, auth_settings_advanced_disable_wp_login_bypass_usernames ); | |
| 583 | 609 | }); |
| 584 | 610 | |
| 611 | + // Event handler: Test LDAP settings. | |
| 612 | + $( '#ldap_test_user_submit' ).on( 'click', function( event ) { | |
| 613 | + event.preventDefault(); | |
| 614 | + $( 'html' ).addClass( 'busy' ); | |
| 615 | + $( '#ldap_test_user_spinner' ).addClass( 'is-active' ); | |
| 616 | + | |
| 617 | + $.post( ajaxurl, { | |
| 618 | + action: 'auth_settings_ldap_test_user', | |
| 619 | + username: $( 'input[name="auth_settings[ldap_test_user]"]' ).val(), | |
| 620 | + password: $( 'input#auth_settings_ldap_test_pass' ).val(), | |
| 621 | + nonce: $( '#nonce_save_auth_settings' ).val(), | |
| 622 | + }).done( function ( data ) { | |
| 623 | + $( '#ldap_test_user_result' ).show().val( data.message ); | |
| 624 | + }).always( function () { | |
| 625 | + $( 'html' ).removeClass( 'busy' ); | |
| 626 | + $( '#ldap_test_user_spinner' ).removeClass( 'is-active' ); | |
| 627 | + }); | |
| 628 | + } ); | |
| 629 | + | |
| 585 | 630 | // Show save button if usermeta field is modified. |
| 586 | 631 | $( 'form input.auth-usermeta' ).on( 'keyup', function( event ) { |
| 587 | 632 | // Don't do anything if tab or arrow keys were pressed. |
| 588 | 633 | if ( event.which === 9 || event.which === 37 || event.which === 38 || event.which === 39 || event.which === 40 ) { |
| @@ -621,22 +666,26 @@ | ||
| 621 | 666 | selectableHeader: '<div class="custom-header">' + authL10n.private_pages + '</div>', |
| 622 | 667 | selectionHeader: '<div class="custom-header">' + authL10n.public_pages + '</div>', |
| 623 | 668 | }); |
| 624 | 669 | |
| 625 | - // Switch to the first tab (or the tab indicated in sessionStorage, or the querystring). | |
| 626 | - var tab = ''; | |
| 627 | - if ( getQuerystringValuesByKey( 'tab' ).length > 0 ) { | |
| 628 | - tab = getQuerystringValuesByKey( 'tab' )[0]; | |
| 629 | - } else if ( sessionStorage.getItem( 'tab' ) ) { | |
| 630 | - tab = sessionStorage.getItem( 'tab' ); | |
| 670 | + // Switch to the first tab (or the tab indicated in sessionStorage, or the | |
| 671 | + // querystring). Note: only do this on the settings page, not the dashboard | |
| 672 | + // widget. | |
| 673 | + if ( ! $( '#auth_dashboard_widget' ).length ) { | |
| 674 | + var tab = ''; | |
| 675 | + if ( getQuerystringValuesByKey( 'tab' ).length > 0 ) { | |
| 676 | + tab = getQuerystringValuesByKey( 'tab' )[0]; | |
| 677 | + } else if ( sessionStorage.getItem( 'tab' ) ) { | |
| 678 | + tab = sessionStorage.getItem( 'tab' ); | |
| 679 | + } | |
| 680 | + if ( $.inArray( tab, [ 'access_lists', 'access_login', 'access_public', 'external', 'external_oauth2', 'external_oidc', 'external_google', 'external_cas', 'external_ldap', 'advanced' ] ) < 0 ) { | |
| 681 | + tab = 'access_lists'; | |
| 682 | + } | |
| 683 | + window.chooseTab( tab, animationSpeed ); | |
| 631 | 684 | } |
| 632 | - if ( $.inArray( tab, [ 'access_lists', 'access_login', 'access_public', 'external', 'advanced' ] ) < 0 ) { | |
| 633 | - tab = 'access_lists'; | |
| 634 | - } | |
| 635 | - window.chooseTab( tab, animationSpeed ); | |
| 636 | 685 | |
| 637 | 686 | // Hide/show multisite settings based on override checkbox. |
| 638 | - $( 'input[name="auth_settings[multisite_override]"]' ).change( function() { | |
| 687 | + $( 'input[name="auth_settings[multisite_override]"]' ).on( 'change', function() { | |
| 639 | 688 | hideMultisiteSettingsIfDisabled(); |
| 640 | 689 | }); |
| 641 | 690 | hideMultisiteSettingsIfDisabled(); |
| 642 | 691 | |
| @@ -686,11 +735,42 @@ | ||
| 686 | 735 | // Enable growable textarea for new user field. |
| 687 | 736 | $( 'textarea#new_approved_user_email' ).autogrow(); |
| 688 | 737 | |
| 689 | 738 | // Enable growable textarea for config fields. |
| 739 | + $( 'textarea#auth_settings_ldap_host' ).autogrow(); | |
| 690 | 740 | $( 'textarea#auth_settings_ldap_search_base' ).autogrow(); |
| 741 | + $( 'textarea#auth_settings_ldap_search_filter' ).autogrow(); | |
| 742 | + $( 'textarea#auth_settings_oauth2_hosteddomain' ).autogrow(); | |
| 691 | 743 | $( 'textarea#auth_settings_google_hosteddomain' ).autogrow(); |
| 744 | + $( 'textarea#auth_settings_advanced_disable_wp_login_bypass_usernames' ).autogrow(); | |
| 692 | 745 | |
| 746 | + // Enable select2 new user email notification dropdown. | |
| 747 | + $( 'select#auth_settings_access_users_receive_pending_emails' ).select2({ | |
| 748 | + ajax: { | |
| 749 | + url: ajaxurl, | |
| 750 | + dataType: 'json', | |
| 751 | + method: 'POST', | |
| 752 | + data: function ( params ) { | |
| 753 | + return { | |
| 754 | + action: 'auth_settings_search_users', | |
| 755 | + nonce: $( '#nonce_save_auth_settings' ).val(), | |
| 756 | + query: params.term, | |
| 757 | + page: params.page || 1, | |
| 758 | + }; | |
| 759 | + }, | |
| 760 | + delay: 250, // Delay in milliseconds after user stops typing before sending the request. | |
| 761 | + }, | |
| 762 | + closeOnSelect: true, // Controls whether the dropdown is closed after a selection is made. | |
| 763 | + maximumInputLength: 50, // Maximum number of characters that may be provided for a search term. | |
| 764 | + minimumInputLength: 1, // Minimum number of characters required to start a search. | |
| 765 | + placeholder: authL10n.select_users, | |
| 766 | + templateSelection: function( data ) { | |
| 767 | + // Show just the username (data.id); fall back to the full display: username (email). | |
| 768 | + return data.id || data.text; | |
| 769 | + }, | |
| 770 | + width: '100%', | |
| 771 | + // minimumResultsForSearch: 10, | |
| 772 | + }); | |
| 693 | 773 | }); |
| 694 | 774 | |
| 695 | 775 | |
| 696 | 776 | /** |
| @@ -723,8 +803,11 @@ | ||
| 723 | 803 | |
| 724 | 804 | // Save user's active tab to sessionStorage (so we can restore it on reload). |
| 725 | 805 | // Note: session storage persists until the browser tab is closed. |
| 726 | 806 | sessionStorage.setItem( 'tab', listName ); |
| 807 | + | |
| 808 | + // Check whether to fade logo. | |
| 809 | + fadeLogo(); | |
| 727 | 810 | }; |
| 728 | 811 | |
| 729 | 812 | // Hide (with overlay) site options if overridden by a multisite option. |
| 730 | 813 | window.hideMultisiteOverriddenOptions = function() { |
| @@ -729,9 +812,9 @@ | ||
| 729 | 812 | // Hide (with overlay) site options if overridden by a multisite option. |
| 730 | 813 | window.hideMultisiteOverriddenOptions = function() { |
| 731 | 814 | $( '.auth_multisite_override_overlay' ).each( function() { |
| 732 | 815 | // Option to hide is stored in the overlay's id with 'overlay-hide-' prefix. |
| 733 | - var optionContainerToHide = $( this ).closest( 'tr' ); | |
| 816 | + var optionContainerToHide = $( this ).closest( 'td' ); | |
| 734 | 817 | if ( optionContainerToHide.length > 0 ) { |
| 735 | 818 | $( this ).css({ |
| 736 | 819 | 'background-color': '#f1f1f1', |
| 737 | 820 | 'z-index': 1, |
| @@ -736,10 +819,9 @@ | ||
| 736 | 819 | 'background-color': '#f1f1f1', |
| 737 | 820 | 'z-index': 1, |
| 738 | 821 | opacity: 0.8, |
| 739 | 822 | position: 'absolute', |
| 740 | - top: optionContainerToHide.position().top, | |
| 741 | - left: optionContainerToHide.position().left, | |
| 823 | + top: optionContainerToHide.css('padding-top'), | |
| 742 | 824 | width: '100%', |
| 743 | 825 | height: optionContainerToHide.height(), |
| 744 | 826 | }); |
| 745 | 827 | $( this ).show(); |
| @@ -780,15 +862,14 @@ | ||
| 780 | 862 | usermeta: usermeta, |
| 781 | 863 | nonce: nonce, |
| 782 | 864 | }, function( response ) { |
| 783 | 865 | var succeeded = response === 'success'; |
| 784 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 866 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 785 | 867 | var spinnerWait = succeeded ? 500 : 2000; |
| 786 | 868 | |
| 787 | 869 | // Enable inputs, remove spinner. |
| 788 | 870 | $caller.removeAttr( 'disabled' ); |
| 789 | 871 | $usermeta.removeAttr( 'disabled' ); |
| 790 | - $caller.css( 'display', 'none' ); | |
| 791 | 872 | $( 'form .spinner:not(:has(.spinner-text))' ).animate( { width: '60px' }, 'fast' ).append( '<span class="spinner-text">' + spinnerText + '</span>' ).delay( spinnerWait ).hide( animationSpeed, function() { |
| 792 | 873 | $( this ).remove(); |
| 793 | 874 | }); |
| 794 | 875 | $( 'html' ).removeClass( 'busy' ); |
| @@ -794,15 +875,14 @@ | ||
| 794 | 875 | $( 'html' ).removeClass( 'busy' ); |
| 795 | 876 | |
| 796 | 877 | }).fail( function() { |
| 797 | 878 | var succeeded = false; |
| 798 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 879 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 799 | 880 | var spinnerWait = succeeded ? 500 : 2000; |
| 800 | 881 | |
| 801 | 882 | // Enable inputs, remove spinner. |
| 802 | 883 | $caller.removeAttr( 'disabled' ); |
| 803 | 884 | $usermeta.removeAttr( 'disabled' ); |
| 804 | - $caller.css( 'display', 'none' ); | |
| 805 | 885 | $( 'form .spinner:not(:has(.spinner-text))' ).animate( { width: '60px' }, 'fast' ).append( '<span class="spinner-text">' + spinnerText + '</span>' ).delay( spinnerWait ).hide( animationSpeed, function() { |
| 806 | 886 | $( this ).remove(); |
| 807 | 887 | }); |
| 808 | 888 | $( 'html' ).removeClass( 'busy' ); |
| @@ -844,9 +924,10 @@ | ||
| 844 | 924 | // Skip email address validation if adding from pending list (not user-editable). |
| 845 | 925 | var skipValidation = $( caller ).parent().parent().attr( 'id' ) === 'list_auth_settings_access_users_pending'; |
| 846 | 926 | |
| 847 | 927 | // Skip email address validation if we're banning an existing user (since they're already in a list). |
| 848 | - skipValidation = skipValidation || $( caller ).attr( 'id' ).indexOf( 'block_user' ) > -1; | |
| 928 | + var blockingNewUser = $( caller ).attr( 'id' ).indexOf( 'block_user_new' ) > -1; | |
| 929 | + skipValidation = skipValidation || ( $( caller ).attr( 'id' ).indexOf( 'block_user' ) > -1 && ! blockingNewUser ); | |
| 849 | 930 | |
| 850 | 931 | // Set default for multisite flag (run different save routine if multisite) |
| 851 | 932 | isMultisite = 'undefined' !== typeof isMultisite ? isMultisite : false; |
| 852 | 933 | |
| @@ -878,9 +959,9 @@ | ||
| 878 | 959 | // Remove any invalid email addresses. |
| 879 | 960 | if ( ! skipValidation ) { |
| 880 | 961 | // Check if the email(s) being added is well-formed. |
| 881 | 962 | emails = emails.filter( function( emailToValidate ) { |
| 882 | - return validEmail( emailToValidate ); | |
| 963 | + return validEmail( emailToValidate, blockingNewUser ); | |
| 883 | 964 | }); |
| 884 | 965 | // Remove any duplicates in the list of emails to add. |
| 885 | 966 | emails = removeDuplicatesFromArrayOfStrings( emails ); |
| 886 | 967 | } |
| @@ -914,11 +995,12 @@ | ||
| 914 | 995 | }) |
| 915 | 996 | ); |
| 916 | 997 | |
| 917 | 998 | // Add the new item. |
| 918 | - var authJsPrefix = isMultisite ? 'authMultisite' : 'auth'; | |
| 919 | - var localIcon = shouldCreateLocalAccount ? ' <a title="' + authL10n.local_wordpress_user + '" class="auth-local-user"><span class="glyphicon glyphicon-user"></span></a>' : ''; | |
| 920 | - var banButton = list === 'approved' && ! isMultisite ? '<a class="button" id="block_user_' + nextId + '" onclick="' + authJsPrefix + 'AddUser( this, \'blocked\', false ); ' + authJsPrefix + 'IgnoreUser( this, \'approved\' );" title="' + authL10n.block_ban_user + '"><span class="glyphicon glyphicon-ban-circle"></span></a>' : ''; | |
| 999 | + var authJsPrefix = isMultisite ? 'authMultisite' : 'auth'; | |
| 1000 | + var multisiteIcon = isMultisite ? '<a title="WordPress Multisite user" class="button disabled auth-multisite-user dashicons-before dashicons-admin-site"></a>' : ''; | |
| 1001 | + var banButton = isMultisite || 'approved' !== list ? '' : '<a class="button button-primary dashicons-before dashicons-remove" id="block_user_' + nextId + '" onclick="' + authJsPrefix + 'AddUser( this, \'blocked\', false ); ' + authJsPrefix + 'IgnoreUser( this, \'approved\' );" title="' + authL10n.block_ban_user + '"></a>'; | |
| 1002 | + var ignoreButton = '<a class="button dashicons-before dashicons-no" id="ignore_user_' + nextId + '" onclick="' + authJsPrefix + 'IgnoreUser( this, \'' + list + '\' );" title="' + authL10n.remove_user + '"></a>'; | |
| 921 | 1003 | $( ' \ |
| 922 | 1004 | <li id="new_user_' + nextId + '" class="new-user" style="display: none;"> \ |
| 923 | 1005 | <input type="text" id="auth_settings_access_users_' + list + '_' + nextId + '" name="auth_settings[access_users_' + list + '][' + nextId + '][email]" value="' + user.email + '" readonly="true" class="auth-email" /> \ |
| 924 | 1006 | <select name="auth_settings[access_users_' + list + '][' + nextId + '][role]" class="auth-role" onchange="' + authJsPrefix + 'ChangeRole( this );"> \ |
| @@ -923,11 +1005,9 @@ | ||
| 923 | 1005 | <input type="text" id="auth_settings_access_users_' + list + '_' + nextId + '" name="auth_settings[access_users_' + list + '][' + nextId + '][email]" value="' + user.email + '" readonly="true" class="auth-email" /> \ |
| 924 | 1006 | <select name="auth_settings[access_users_' + list + '][' + nextId + '][role]" class="auth-role" onchange="' + authJsPrefix + 'ChangeRole( this );"> \ |
| 925 | 1007 | </select> \ |
| 926 | 1008 | <input type="text" name="auth_settings[access_users_' + list + '][' + nextId + '][date_added]" value="' + getShortDate() + '" readonly="true" class="auth-date-added" /> \ |
| 927 | - ' + banButton + ' \ | |
| 928 | - <a class="button" id="ignore_user_' + nextId + '" onclick="' + authJsPrefix + 'IgnoreUser( this, \'' + list + '\' );" title="' + authL10n.remove_user + '"><span class="glyphicon glyphicon-remove"></span></a> \ | |
| 929 | - ' + localIcon + ' \ | |
| 1009 | + ' + multisiteIcon + banButton + ignoreButton + ' \ | |
| 930 | 1010 | <span class="spinner is-active"></span> \ |
| 931 | 1011 | </li> \ |
| 932 | 1012 | ' ).appendTo( '#list_auth_settings_access_users_' + list ).slideDown( 250 ); |
| 933 | 1013 | |
| @@ -1031,18 +1111,23 @@ | ||
| 1031 | 1111 | left: $( caller ).position().left + $( caller ).width() + 20, |
| 1032 | 1112 | }); |
| 1033 | 1113 | $( caller ).after( $spinner ); |
| 1034 | 1114 | |
| 1035 | - // Get form elements to save | |
| 1036 | - var nonce_save_auth_settings = $( '#nonce_save_auth_settings' ).val(); | |
| 1115 | + // Get form elements to save. | |
| 1116 | + var params = { | |
| 1117 | + action: 'save_auth_multisite_settings', | |
| 1118 | + nonce: $( '#nonce_save_auth_settings' ).val(), | |
| 1119 | + }; | |
| 1037 | 1120 | |
| 1038 | - var multisite_override = $( '#auth_settings_multisite_override' ).is( ':checked' ) ? '1' : ''; | |
| 1121 | + params.multisite_override = $( '#auth_settings_multisite_override' ).is( ':checked' ) ? '1' : ''; | |
| 1039 | 1122 | |
| 1040 | - var access_who_can_login = $( 'form input[name="auth_settings[access_who_can_login]"]:checked' ).val(); | |
| 1123 | + params.prevent_override_multisite = $( '#auth_settings_prevent_override_multisite' ).is( ':checked' ) ? '1' : ''; | |
| 1041 | 1124 | |
| 1042 | - var access_who_can_view = $( 'form input[name="auth_settings[access_who_can_view]"]:checked' ).val(); | |
| 1125 | + params.access_who_can_login = $( 'form input[name="auth_settings[access_who_can_login]"]:checked' ).val(); | |
| 1043 | 1126 | |
| 1044 | - var access_users_approved = {}; | |
| 1127 | + params.access_who_can_view = $( 'form input[name="auth_settings[access_who_can_view]"]:checked' ).val(); | |
| 1128 | + | |
| 1129 | + params.access_users_approved = {}; | |
| 1045 | 1130 | $( '#list_auth_settings_access_users_approved li' ).each( function( index ) { |
| 1046 | 1131 | var user = {}; |
| 1047 | 1132 | user.email = $( '.auth-email', this ).val(); |
| 1048 | 1133 | user.role = $( '.auth-role', this ).val(); |
| @@ -1047,45 +1132,140 @@ | ||
| 1047 | 1132 | user.email = $( '.auth-email', this ).val(); |
| 1048 | 1133 | user.role = $( '.auth-role', this ).val(); |
| 1049 | 1134 | user.date_added = $( '.auth-date-added', this ).val(); |
| 1050 | 1135 | user.local_user = $( '.auth-local-user', this ).length !== 0; |
| 1051 | - access_users_approved[index] = user; | |
| 1136 | + params.access_users_approved[index] = user; | |
| 1052 | 1137 | }); |
| 1053 | 1138 | |
| 1054 | - var access_default_role = $( '#auth_settings_access_default_role' ).val(); | |
| 1139 | + params.access_default_role = $( '#auth_settings_access_default_role' ).val(); | |
| 1055 | 1140 | |
| 1056 | - var google = $( '#auth_settings_google' ).is( ':checked' ) ? '1' : ''; | |
| 1057 | - var google_clientid = $( '#auth_settings_google_clientid' ).val(); | |
| 1058 | - var google_clientsecret = $( '#auth_settings_google_clientsecret' ).val(); | |
| 1059 | - var google_hosteddomain = $( '#auth_settings_google_hosteddomain' ).val(); | |
| 1141 | + params.oauth2 = $( '#auth_settings_oauth2' ).is( ':checked' ) ? '1' : ''; | |
| 1142 | + params.oauth2_auto_login = $( '#auth_settings_oauth2_auto_login' ).val(); | |
| 1143 | + params.oauth2_num_servers = parseInt( $( '#auth_settings_oauth2_num_servers' ).val() ); | |
| 1144 | + params.oauth2_provider = $( '#auth_settings_oauth2_provider' ).val(); | |
| 1145 | + params.oauth2_custom_label = $( '#auth_settings_oauth2_custom_label' ).val(); | |
| 1146 | + params.oauth2_clientid = $( '#auth_settings_oauth2_clientid' ).val(); | |
| 1147 | + params.oauth2_clientsecret = $( '#auth_settings_oauth2_clientsecret' ).val(); | |
| 1148 | + params.oauth2_hosteddomain = $( '#auth_settings_oauth2_hosteddomain' ).val(); | |
| 1149 | + params.oauth2_tenant_id = $( '#auth_settings_oauth2_tenant_id' ).val(); | |
| 1150 | + params.oauth2_url_authorize = $( '#auth_settings_oauth2_url_authorize' ).val(); | |
| 1151 | + params.oauth2_url_token = $( '#auth_settings_oauth2_url_token' ).val(); | |
| 1152 | + params.oauth2_url_resource = $( '#auth_settings_oauth2_url_resource' ).val(); | |
| 1153 | + params.oauth2_attr_username = $( '#auth_settings_oauth2_attr_username' ).val(); | |
| 1154 | + params.oauth2_attr_email = $( '#auth_settings_oauth2_attr_email' ).val(); | |
| 1155 | + params.oauth2_attr_first_name = $( '#auth_settings_oauth2_attr_first_name' ).val(); | |
| 1156 | + params.oauth2_attr_last_name = $( '#auth_settings_oauth2_attr_last_name' ).val(); | |
| 1157 | + params.oauth2_attr_update_on_login = $( '#auth_settings_oauth2_attr_update_on_login' ).val(); | |
| 1158 | + if ( params.oauth2_num_servers > 1 ) { | |
| 1159 | + for ( var oauth2_num_server = 2; oauth2_num_server <= params.oauth2_num_servers && oauth2_num_server <= 20; oauth2_num_server++ ) { | |
| 1160 | + params['oauth2_provider_' + oauth2_num_server] = $( '#auth_settings_oauth2_provider_' + oauth2_num_server ).val(); | |
| 1161 | + params['oauth2_custom_label_' + oauth2_num_server] = $( '#auth_settings_oauth2_custom_label_' + oauth2_num_server ).val(); | |
| 1162 | + params['oauth2_clientid_' + oauth2_num_server] = $( '#auth_settings_oauth2_clientid_' + oauth2_num_server ).val(); | |
| 1163 | + params['oauth2_clientsecret_' + oauth2_num_server] = $( '#auth_settings_oauth2_clientsecret_' + oauth2_num_server ).val(); | |
| 1164 | + params['oauth2_hosteddomain_' + oauth2_num_server] = $( '#auth_settings_oauth2_hosteddomain_' + oauth2_num_server ).val(); | |
| 1165 | + params['oauth2_tenant_id_' + oauth2_num_server] = $( '#auth_settings_oauth2_tenant_id_' + oauth2_num_server ).val(); | |
| 1166 | + params['oauth2_url_authorize_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_authorize_' + oauth2_num_server ).val(); | |
| 1167 | + params['oauth2_url_token_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_token_' + oauth2_num_server ).val(); | |
| 1168 | + params['oauth2_url_resource_' + oauth2_num_server] = $( '#auth_settings_oauth2_url_resource_' + oauth2_num_server ).val(); | |
| 1169 | + params['oauth2_attr_username_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_username_' + oauth2_num_server ).val(); | |
| 1170 | + params['oauth2_attr_email_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_email_' + oauth2_num_server ).val(); | |
| 1171 | + params['oauth2_attr_first_name_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_first_name_' + oauth2_num_server ).val(); | |
| 1172 | + params['oauth2_attr_last_name_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_last_name_' + oauth2_num_server ).val(); | |
| 1173 | + params['oauth2_attr_update_on_login_' + oauth2_num_server] = $( '#auth_settings_oauth2_attr_update_on_login_' + oauth2_num_server ).val(); | |
| 1174 | + } | |
| 1175 | + } | |
| 1060 | 1176 | |
| 1061 | - var cas = $( '#auth_settings_cas' ).is( ':checked' ) ? '1' : ''; | |
| 1062 | - var cas_custom_label = $( '#auth_settings_cas_custom_label' ).val(); | |
| 1063 | - var cas_host = $( '#auth_settings_cas_host' ).val(); | |
| 1064 | - var cas_port = $( '#auth_settings_cas_port' ).val(); | |
| 1065 | - var cas_path = $( '#auth_settings_cas_path' ).val(); | |
| 1066 | - var cas_version = $( '#auth_settings_cas_version' ).val(); | |
| 1067 | - var cas_attr_email = $( '#auth_settings_cas_attr_email' ).val(); | |
| 1068 | - var cas_attr_first_name = $( '#auth_settings_cas_attr_first_name' ).val(); | |
| 1069 | - var cas_attr_last_name = $( '#auth_settings_cas_attr_last_name' ).val(); | |
| 1070 | - var cas_attr_update_on_login = $( '#auth_settings_cas_attr_update_on_login' ).is( ':checked' ) ? '1' : ''; | |
| 1071 | - var cas_auto_login = $( '#auth_settings_cas_auto_login' ).is( ':checked' ) ? '1' : ''; | |
| 1177 | + params.oidc = $( '#auth_settings_oidc' ).is( ':checked' ) ? '1' : ''; | |
| 1178 | + params.oidc_auto_login = $( '#auth_settings_oidc_auto_login' ).val(); | |
| 1179 | + params.oidc_num_servers = parseInt( $( '#auth_settings_oidc_num_servers' ).val() ); | |
| 1180 | + params.oidc_custom_label = $( '#auth_settings_oidc_custom_label' ).val(); | |
| 1181 | + params.oidc_issuer = $( '#auth_settings_oidc_issuer' ).val(); | |
| 1182 | + params.oidc_client_id = $( '#auth_settings_oidc_client_id' ).val(); | |
| 1183 | + params.oidc_client_secret = $( '#auth_settings_oidc_client_secret' ).val(); | |
| 1184 | + params.oidc_scopes = $( '#auth_settings_oidc_scopes' ).val(); | |
| 1185 | + params.oidc_prompt = $( '#auth_settings_oidc_prompt' ).val(); | |
| 1186 | + params.oidc_login_hint = $( '#auth_settings_oidc_login_hint' ).val(); | |
| 1187 | + params.oidc_max_age = $( '#auth_settings_oidc_max_age' ).val(); | |
| 1188 | + params.oidc_attr_username = $( '#auth_settings_oidc_attr_username' ).val(); | |
| 1189 | + params.oidc_attr_email = $( '#auth_settings_oidc_attr_email' ).val(); | |
| 1190 | + params.oidc_attr_first_name = $( '#auth_settings_oidc_attr_first_name' ).val(); | |
| 1191 | + params.oidc_attr_last_name = $( '#auth_settings_oidc_attr_last_name' ).val(); | |
| 1192 | + params.oidc_attr_update_on_login = $( '#auth_settings_oidc_attr_update_on_login' ).val(); | |
| 1193 | + params.oidc_require_verified_email = $( '#auth_settings_oidc_require_verified_email' ).is( ':checked' ) ? '1' : ''; | |
| 1194 | + params.oidc_link_on_username = $( '#auth_settings_oidc_link_on_username' ).is( ':checked' ) ? '1' : ''; | |
| 1195 | + params.oidc_hosteddomain = $( '#auth_settings_oidc_hosteddomain' ).val(); | |
| 1196 | + if ( params.oidc_num_servers > 1 ) { | |
| 1197 | + for ( var oidc_num_server = 2; oidc_num_server <= params.oidc_num_servers && oidc_num_server <= 20; oidc_num_server++ ) { | |
| 1198 | + params['oidc_custom_label_' + oidc_num_server] = $( '#auth_settings_oidc_custom_label_' + oidc_num_server ).val(); | |
| 1199 | + params['oidc_issuer_' + oidc_num_server] = $( '#auth_settings_oidc_issuer_' + oidc_num_server ).val(); | |
| 1200 | + params['oidc_client_id_' + oidc_num_server] = $( '#auth_settings_oidc_client_id_' + oidc_num_server ).val(); | |
| 1201 | + params['oidc_client_secret_' + oidc_num_server] = $( '#auth_settings_oidc_client_secret_' + oidc_num_server ).val(); | |
| 1202 | + params['oidc_scopes_' + oidc_num_server] = $( '#auth_settings_oidc_scopes_' + oidc_num_server ).val(); | |
| 1203 | + params['oidc_prompt_' + oidc_num_server] = $( '#auth_settings_oidc_prompt_' + oidc_num_server ).val(); | |
| 1204 | + params['oidc_login_hint_' + oidc_num_server] = $( '#auth_settings_oidc_login_hint_' + oidc_num_server ).val(); | |
| 1205 | + params['oidc_max_age_' + oidc_num_server] = $( '#auth_settings_oidc_max_age_' + oidc_num_server ).val(); | |
| 1206 | + params['oidc_attr_username_' + oidc_num_server] = $( '#auth_settings_oidc_attr_username_' + oidc_num_server ).val(); | |
| 1207 | + params['oidc_attr_email_' + oidc_num_server] = $( '#auth_settings_oidc_attr_email_' + oidc_num_server ).val(); | |
| 1208 | + params['oidc_attr_first_name_' + oidc_num_server] = $( '#auth_settings_oidc_attr_first_name_' + oidc_num_server ).val(); | |
| 1209 | + params['oidc_attr_last_name_' + oidc_num_server] = $( '#auth_settings_oidc_attr_last_name_' + oidc_num_server ).val(); | |
| 1210 | + params['oidc_attr_update_on_login_' + oidc_num_server] = $( '#auth_settings_oidc_attr_update_on_login_' + oidc_num_server ).val(); | |
| 1211 | + params['oidc_require_verified_email_' + oidc_num_server] = $( '#auth_settings_oidc_require_verified_email_' + oidc_num_server ).is( ':checked' ) ? '1' : ''; | |
| 1212 | + params['oidc_link_on_username_' + oidc_num_server] = $( '#auth_settings_oidc_link_on_username_' + oidc_num_server ).is( ':checked' ) ? '1' : ''; | |
| 1213 | + } | |
| 1214 | + } | |
| 1072 | 1215 | |
| 1073 | - var ldap = $( '#auth_settings_ldap' ).is( ':checked' ) ? '1' : ''; | |
| 1074 | - var ldap_host = $( '#auth_settings_ldap_host' ).val(); | |
| 1075 | - var ldap_port = $( '#auth_settings_ldap_port' ).val(); | |
| 1076 | - var ldap_search_base = $( '#auth_settings_ldap_search_base' ).val(); | |
| 1077 | - var ldap_uid = $( '#auth_settings_ldap_uid' ).val(); | |
| 1078 | - var ldap_attr_email = $( '#auth_settings_ldap_attr_email' ).val(); | |
| 1079 | - var ldap_user = $( '#auth_settings_ldap_user' ).val(); | |
| 1080 | - var ldap_password = $( '#auth_settings_ldap_password' ).val(); | |
| 1081 | - var ldap_tls = $( '#auth_settings_ldap_tls' ).is( ':checked' ) ? '1' : ''; | |
| 1082 | - var ldap_lostpassword_url = $( '#auth_settings_ldap_lostpassword_url' ).val(); | |
| 1083 | - var ldap_attr_first_name = $( '#auth_settings_ldap_attr_first_name' ).val(); | |
| 1084 | - var ldap_attr_last_name = $( '#auth_settings_ldap_attr_last_name' ).val(); | |
| 1085 | - var ldap_attr_update_on_login = $( '#auth_settings_ldap_attr_update_on_login' ).is( ':checked' ) ? '1' : ''; | |
| 1216 | + params.google = $( '#auth_settings_google' ).is( ':checked' ) ? '1' : ''; | |
| 1217 | + params.google_clientid = $( '#auth_settings_google_clientid' ).val(); | |
| 1218 | + params.google_clientsecret = $( '#auth_settings_google_clientsecret' ).val(); | |
| 1219 | + params.google_hosteddomain = $( '#auth_settings_google_hosteddomain' ).val(); | |
| 1086 | 1220 | |
| 1087 | - var advanced_lockouts = { | |
| 1221 | + params.cas = $( '#auth_settings_cas' ).is( ':checked' ) ? '1' : ''; | |
| 1222 | + params.cas_auto_login = $( '#auth_settings_cas_auto_login' ).val(); | |
| 1223 | + params.cas_num_servers = parseInt( $( '#auth_settings_cas_num_servers' ).val() ); | |
| 1224 | + params.cas_custom_label = $( '#auth_settings_cas_custom_label' ).val(); | |
| 1225 | + params.cas_host = $( '#auth_settings_cas_host' ).val(); | |
| 1226 | + params.cas_port = $( '#auth_settings_cas_port' ).val(); | |
| 1227 | + params.cas_path = $( '#auth_settings_cas_path' ).val(); | |
| 1228 | + params.cas_method = $( '#auth_settings_cas_method' ).val(); | |
| 1229 | + params.cas_version = $( '#auth_settings_cas_version' ).val(); | |
| 1230 | + params.cas_attr_email = $( '#auth_settings_cas_attr_email' ).val(); | |
| 1231 | + params.cas_attr_first_name = $( '#auth_settings_cas_attr_first_name' ).val(); | |
| 1232 | + params.cas_attr_last_name = $( '#auth_settings_cas_attr_last_name' ).val(); | |
| 1233 | + params.cas_attr_update_on_login = $( '#auth_settings_cas_attr_update_on_login' ).val(); | |
| 1234 | + params.cas_link_on_username = $( '#auth_settings_cas_link_on_username' ).is( ':checked' ) ? '1' : ''; | |
| 1235 | + if ( params.cas_num_servers > 1 ) { | |
| 1236 | + for ( var cas_num_server = 2; cas_num_server <= params.cas_num_servers && cas_num_server <= 10; cas_num_server++ ) { | |
| 1237 | + params['cas_custom_label_' + cas_num_server] = $( '#auth_settings_cas_custom_label_' + cas_num_server ).val(); | |
| 1238 | + params['cas_host_' + cas_num_server] = $( '#auth_settings_cas_host_' + cas_num_server ).val(); | |
| 1239 | + params['cas_port_' + cas_num_server] = $( '#auth_settings_cas_port_' + cas_num_server ).val(); | |
| 1240 | + params['cas_path_' + cas_num_server] = $( '#auth_settings_cas_path_' + cas_num_server ).val(); | |
| 1241 | + params['cas_method_' + cas_num_server] = $( '#auth_settings_cas_method_' + cas_num_server ).val(); | |
| 1242 | + params['cas_version_' + cas_num_server] = $( '#auth_settings_cas_version_' + cas_num_server ).val(); | |
| 1243 | + params['cas_attr_email_' + cas_num_server] = $( '#auth_settings_cas_attr_email_' + cas_num_server ).val(); | |
| 1244 | + params['cas_attr_first_name_' + cas_num_server] = $( '#auth_settings_cas_attr_first_name_' + cas_num_server ).val(); | |
| 1245 | + params['cas_attr_last_name_' + cas_num_server] = $( '#auth_settings_cas_attr_last_name_' + cas_num_server ).val(); | |
| 1246 | + params['cas_attr_update_on_login_' + cas_num_server] = $( '#auth_settings_cas_attr_update_on_login_' + cas_num_server ).val(); | |
| 1247 | + params['cas_link_on_username_' + cas_num_server] = $( '#auth_settings_cas_link_on_username_' + cas_num_server ).is( ':checked' ) ? '1' : ''; | |
| 1248 | + } | |
| 1249 | + } | |
| 1250 | + | |
| 1251 | + params.ldap = $( '#auth_settings_ldap' ).is( ':checked' ) ? '1' : ''; | |
| 1252 | + params.ldap_host = $( '#auth_settings_ldap_host' ).val(); | |
| 1253 | + params.ldap_port = $( '#auth_settings_ldap_port' ).val(); | |
| 1254 | + params.ldap_search_base = $( '#auth_settings_ldap_search_base' ).val(); | |
| 1255 | + params.ldap_search_filter = $( '#auth_settings_ldap_search_filter' ).val(); | |
| 1256 | + params.ldap_uid = $( '#auth_settings_ldap_uid' ).val(); | |
| 1257 | + params.ldap_attr_email = $( '#auth_settings_ldap_attr_email' ).val(); | |
| 1258 | + params.ldap_user = $( '#auth_settings_ldap_user' ).val(); | |
| 1259 | + params.ldap_password = $( '#auth_settings_ldap_password' ).val(); | |
| 1260 | + params.ldap_tls = $( '#auth_settings_ldap_tls' ).is( ':checked' ) ? '1' : ''; | |
| 1261 | + params.ldap_lostpassword_url = $( '#auth_settings_ldap_lostpassword_url' ).val(); | |
| 1262 | + params.ldap_attr_first_name = $( '#auth_settings_ldap_attr_first_name' ).val(); | |
| 1263 | + params.ldap_attr_last_name = $( '#auth_settings_ldap_attr_last_name' ).val(); | |
| 1264 | + params.ldap_attr_update_on_login = $( '#auth_settings_ldap_attr_update_on_login' ).val(); | |
| 1265 | + params.ldap_test_user = $( '#auth_settings_ldap_test_user' ).val(); | |
| 1266 | + | |
| 1267 | + params.advanced_lockouts = { | |
| 1088 | 1268 | attempts_1: $( '#auth_settings_advanced_lockouts_attempts_1' ).val(), |
| 1089 | 1269 | duration_1: $( '#auth_settings_advanced_lockouts_duration_1' ).val(), |
| 1090 | 1270 | attempts_2: $( '#auth_settings_advanced_lockouts_attempts_2' ).val(), |
| 1091 | 1271 | duration_2: $( '#auth_settings_advanced_lockouts_duration_2' ).val(), |
| @@ -1090,59 +1270,19 @@ | ||
| 1090 | 1270 | attempts_2: $( '#auth_settings_advanced_lockouts_attempts_2' ).val(), |
| 1091 | 1271 | duration_2: $( '#auth_settings_advanced_lockouts_duration_2' ).val(), |
| 1092 | 1272 | reset_duration: $( '#auth_settings_advanced_lockouts_reset_duration' ).val(), |
| 1093 | 1273 | }; |
| 1094 | - var advanced_hide_wp_login = $( '#auth_settings_advanced_hide_wp_login' ).is( ':checked' ) ? '1' : ''; | |
| 1095 | - var advanced_widget_enabled = $( '#auth_settings_advanced_widget_enabled' ).is( ':checked' ) ? '1' : ''; | |
| 1096 | - var advanced_users_per_page = $( '#auth_settings_advanced_users_per_page' ).val(); | |
| 1097 | - var advanced_users_sort_by = $( '#auth_settings_advanced_users_sort_by' ).val(); | |
| 1098 | - var advanced_users_sort_order = $( '#auth_settings_advanced_users_sort_order' ).val(); | |
| 1274 | + params.advanced_hide_wp_login = $( '#auth_settings_advanced_hide_wp_login' ).is( ':checked' ) ? '1' : ''; | |
| 1275 | + params.advanced_disable_wp_login = $( '#auth_settings_advanced_disable_wp_login' ).is( ':checked' ) ? '1' : ''; | |
| 1276 | + params.advanced_disable_wp_login_bypass_usernames = $( '#auth_settings_advanced_disable_wp_login_bypass_usernames' ).val(); | |
| 1277 | + params.advanced_widget_enabled = $( '#auth_settings_advanced_widget_enabled' ).is( ':checked' ) ? '1' : ''; | |
| 1278 | + params.advanced_users_per_page = $( '#auth_settings_advanced_users_per_page' ).val(); | |
| 1279 | + params.advanced_users_sort_by = $( '#auth_settings_advanced_users_sort_by' ).val(); | |
| 1280 | + params.advanced_users_sort_order = $( '#auth_settings_advanced_users_sort_order' ).val(); | |
| 1099 | 1281 | |
| 1100 | - $.post( ajaxurl, { | |
| 1101 | - action: 'save_auth_multisite_settings', | |
| 1102 | - nonce: nonce_save_auth_settings, | |
| 1103 | - multisite_override: multisite_override, | |
| 1104 | - access_who_can_login: access_who_can_login, | |
| 1105 | - access_who_can_view: access_who_can_view, | |
| 1106 | - access_users_approved: access_users_approved, | |
| 1107 | - access_default_role: access_default_role, | |
| 1108 | - google: google, | |
| 1109 | - google_clientid: google_clientid, | |
| 1110 | - google_clientsecret: google_clientsecret, | |
| 1111 | - google_hosteddomain: google_hosteddomain, | |
| 1112 | - cas: cas, | |
| 1113 | - cas_custom_label: cas_custom_label, | |
| 1114 | - cas_host: cas_host, | |
| 1115 | - cas_port: cas_port, | |
| 1116 | - cas_path: cas_path, | |
| 1117 | - cas_version: cas_version, | |
| 1118 | - cas_attr_email: cas_attr_email, | |
| 1119 | - cas_attr_first_name: cas_attr_first_name, | |
| 1120 | - cas_attr_last_name: cas_attr_last_name, | |
| 1121 | - cas_attr_update_on_login: cas_attr_update_on_login, | |
| 1122 | - cas_auto_login: cas_auto_login, | |
| 1123 | - ldap: ldap, | |
| 1124 | - ldap_host: ldap_host, | |
| 1125 | - ldap_port: ldap_port, | |
| 1126 | - ldap_search_base: ldap_search_base, | |
| 1127 | - ldap_uid: ldap_uid, | |
| 1128 | - ldap_attr_email: ldap_attr_email, | |
| 1129 | - ldap_user: ldap_user, | |
| 1130 | - ldap_password: ldap_password, | |
| 1131 | - ldap_tls: ldap_tls, | |
| 1132 | - ldap_lostpassword_url: ldap_lostpassword_url, | |
| 1133 | - ldap_attr_first_name: ldap_attr_first_name, | |
| 1134 | - ldap_attr_last_name: ldap_attr_last_name, | |
| 1135 | - ldap_attr_update_on_login: ldap_attr_update_on_login, | |
| 1136 | - advanced_lockouts: advanced_lockouts, | |
| 1137 | - advanced_hide_wp_login: advanced_hide_wp_login, | |
| 1138 | - advanced_users_per_page: advanced_users_per_page, | |
| 1139 | - advanced_users_sort_by: advanced_users_sort_by, | |
| 1140 | - advanced_users_sort_order: advanced_users_sort_order, | |
| 1141 | - advanced_widget_enabled: advanced_widget_enabled, | |
| 1142 | - }, function( response ) { | |
| 1282 | + $.post( ajaxurl, params, function( response ) { | |
| 1143 | 1283 | var succeeded = response === 'success'; |
| 1144 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 1284 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 1145 | 1285 | var spinnerWait = succeeded ? 500 : 2000; |
| 1146 | 1286 | $( 'form .spinner:not(:has(.spinner-text))' ).append( '<span class="spinner-text">' + spinnerText + '</span>' ).delay( spinnerWait ).hide( animationSpeed, function() { |
| 1147 | 1287 | $( this ).remove(); |
| 1148 | 1288 | }); |
| @@ -1149,12 +1289,19 @@ | ||
| 1149 | 1289 | $( caller ).removeAttr( 'disabled' ); |
| 1150 | 1290 | |
| 1151 | 1291 | // Disable wait cursor. |
| 1152 | 1292 | $( 'html' ).removeClass( 'busy' ); |
| 1293 | + | |
| 1294 | + // If the save was successful, and we have more than 1 CAS or OAuth2 | |
| 1295 | + // servers configured, reload the page to render the additional CAS/Oauth2 | |
| 1296 | + // server settings fields. | |
| 1297 | + if ( succeeded && ( params.cas_num_servers > 1 || params.oauth2_num_servers > 1 ) ) { | |
| 1298 | + location.reload(); | |
| 1299 | + } | |
| 1153 | 1300 | }).fail( function() { |
| 1154 | 1301 | // Fail fires if the server doesn't respond |
| 1155 | 1302 | var succeeded = false; |
| 1156 | - var spinnerText = succeeded ? authL10n.saved + '.' : '<span style="color: red;">' + authL10n.failed + '.</span>'; | |
| 1303 | + var spinnerText = succeeded ? authL10n.saved + '.' : '<span class="attention">' + authL10n.failed + '.</span>'; | |
| 1157 | 1304 | var spinnerWait = succeeded ? 500 : 2000; |
| 1158 | 1305 | $( 'form .spinner:not(:has(.spinner-text))' ).append( '<span class="spinner-text">' + spinnerText + '</span>' ).delay( spinnerWait ).hide( animationSpeed, function() { |
| 1159 | 1306 | $( this ).remove(); |
| 1160 | 1307 | }); |
| @@ -1164,8 +1311,29 @@ | ||
| 1164 | 1311 | $( 'html' ).removeClass( 'busy' ); |
| 1165 | 1312 | }); |
| 1166 | 1313 | }; |
| 1167 | 1314 | /* eslint-enable camelcase */ |
| 1315 | + | |
| 1316 | + // Fade in/out Authorizer logo in bottom right on Settings. | |
| 1317 | + $(document).on( 'scroll', function () { | |
| 1318 | + fadeLogo(); | |
| 1319 | + }); | |
| 1320 | + | |
| 1321 | + function fadeLogo() { | |
| 1322 | + if ( getScrollPercent() < 90 ) { | |
| 1323 | + $( '#wpwrap' ).removeClass( 'not-faded' ); | |
| 1324 | + } else { | |
| 1325 | + $( '#wpwrap' ).addClass( 'not-faded' ); | |
| 1326 | + } | |
| 1327 | + } | |
| 1328 | + | |
| 1329 | + function getScrollPercent() { | |
| 1330 | + var h = document.documentElement, | |
| 1331 | + b = document.body, | |
| 1332 | + st = 'scrollTop', | |
| 1333 | + sh = 'scrollHeight'; | |
| 1334 | + return ( h[st] || b[st] ) / ( ( h[sh] || b[sh] ) - h.clientHeight ) * 100; | |
| 1335 | + } | |
| 1168 | 1336 | |
| 1169 | 1337 | /* ======================================================================== |
| 1170 | 1338 | * Portions below from Bootstrap. |
| 1171 | 1339 | * ======================================================================== |