| | |
| | |
| | |
| |
|
| | |
| |
|
| | ( function( $, authApp ) { |
| | var $appNameField = $( '#app_name' ), |
| | $approveBtn = $( '#approve' ), |
| | $rejectBtn = $( '#reject' ), |
| | $form = $appNameField.closest( 'form' ), |
| | context = { |
| | userLogin: authApp.user_login, |
| | successUrl: authApp.success, |
| | rejectUrl: authApp.reject |
| | }; |
| |
|
| | $approveBtn.on( 'click', function( e ) { |
| | var name = $appNameField.val(), |
| | appId = $( 'input[name="app_id"]', $form ).val(); |
| |
|
| | e.preventDefault(); |
| |
|
| | if ( $approveBtn.prop( 'aria-disabled' ) ) { |
| | return; |
| | } |
| |
|
| | if ( 0 === name.length ) { |
| | $appNameField.trigger( 'focus' ); |
| | return; |
| | } |
| |
|
| | $approveBtn.prop( 'aria-disabled', true ).addClass( 'disabled' ); |
| |
|
| | var request = { |
| | name: name |
| | }; |
| |
|
| | if ( appId.length > 0 ) { |
| | request.app_id = appId; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | request = wp.hooks.applyFilters( 'wp_application_passwords_approve_app_request', request, context ); |
| |
|
| | wp.apiRequest( { |
| | path: '/wp/v2/users/me/application-passwords?_locale=user', |
| | method: 'POST', |
| | data: request |
| | } ).done( function( response, textStatus, jqXHR ) { |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | wp.hooks.doAction( 'wp_application_passwords_approve_app_request_success', response, textStatus, jqXHR ); |
| |
|
| | var raw = authApp.success, |
| | url, message, $notice; |
| |
|
| | if ( raw ) { |
| | url = raw + ( -1 === raw.indexOf( '?' ) ? '?' : '&' ) + |
| | 'site_url=' + encodeURIComponent( authApp.site_url ) + |
| | '&user_login=' + encodeURIComponent( authApp.user_login ) + |
| | '&password=' + encodeURIComponent( response.password ); |
| |
|
| | window.location = url; |
| | } else { |
| | message = wp.i18n.sprintf( |
| | |
| | '<label for="new-application-password-value">' + wp.i18n.__( 'Your new password for %s is:' ) + '</label>', |
| | '<strong></strong>' |
| | ) + ' <input id="new-application-password-value" type="text" class="code" readonly="readonly" value="" />'; |
| | $notice = $( '<div></div>' ) |
| | .attr( 'role', 'alert' ) |
| | .attr( 'tabindex', -1 ) |
| | .addClass( 'notice notice-success notice-alt' ) |
| | .append( $( '<p></p>' ).addClass( 'application-password-display' ).html( message ) ) |
| | .append( '<p>' + wp.i18n.__( 'Be sure to save this in a safe location. You will not be able to retrieve it.' ) + '</p>' ); |
| |
|
| | |
| | $( 'strong', $notice ).text( response.name ); |
| | $( 'input', $notice ).val( response.password ); |
| |
|
| | $form.replaceWith( $notice ); |
| | $notice.trigger( 'focus' ); |
| | } |
| | } ).fail( function( jqXHR, textStatus, errorThrown ) { |
| | var errorMessage = errorThrown, |
| | error = null; |
| |
|
| | if ( jqXHR.responseJSON ) { |
| | error = jqXHR.responseJSON; |
| |
|
| | if ( error.message ) { |
| | errorMessage = error.message; |
| | } |
| | } |
| |
|
| | var $notice = $( '<div></div>' ) |
| | .attr( 'role', 'alert' ) |
| | .addClass( 'notice notice-error' ) |
| | .append( $( '<p></p>' ).text( errorMessage ) ); |
| |
|
| | $( 'h1' ).after( $notice ); |
| |
|
| | $approveBtn.removeProp( 'aria-disabled', false ).removeClass( 'disabled' ); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | wp.hooks.doAction( 'wp_application_passwords_approve_app_request_error', error, textStatus, errorThrown, jqXHR ); |
| | } ); |
| | } ); |
| |
|
| | $rejectBtn.on( 'click', function( e ) { |
| | e.preventDefault(); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | wp.hooks.doAction( 'wp_application_passwords_reject_app', context ); |
| |
|
| | |
| | window.location = authApp.reject; |
| | } ); |
| |
|
| | $form.on( 'submit', function( e ) { |
| | e.preventDefault(); |
| | } ); |
| | }( jQuery, authApp ) ); |
| |
|