| 1 |
/** |
| 2 |
* MetaSync Whitelabel Password Gate |
| 3 |
* |
| 4 |
* Extracted for Phase 5, #887 — Part B JS extraction. |
| 5 |
* Handles the whitelabel password login screen: focus, enter-key submit, |
| 6 |
* and the "Forgot Password" recovery AJAX flow. |
| 7 |
* |
| 8 |
* Localized data object: metasyncWhitelabelData |
| 9 |
* - recoverNonce (string) — nonce for metasync_recover_password AJAX action |
| 10 |
* |
| 11 |
* @since Phase 5 |
| 12 |
* @see wp_localize_script() call in class-metasync-admin.php |
| 13 |
* @global metasyncWhitelabelData |
| 14 |
*/ |
| 15 |
/* global metasyncWhitelabelData */ |
| 16 |
|
| 17 |
jQuery(document).ready(function($) { |
| 18 |
// Focus on password field when page loads |
| 19 |
$('#whitelabel_password').focus(); |
| 20 |
|
| 21 |
// Add enter key support |
| 22 |
$('#whitelabel_password').on('keypress', function(e) { |
| 23 |
if (e.which === 13) { |
| 24 |
$(this).closest('form').submit(); |
| 25 |
} |
| 26 |
}); |
| 27 |
|
| 28 |
// Handle forgot password link |
| 29 |
$('#metasync-forgot-password-link').on('click', function(e) { |
| 30 |
e.preventDefault(); |
| 31 |
|
| 32 |
var $link = $(this); |
| 33 |
var $message = $('#metasync-recovery-message'); |
| 34 |
|
| 35 |
// Disable link and show loading state |
| 36 |
$link.css('pointer-events', 'none').css('opacity', '0.6'); |
| 37 |
$message.removeClass('success error').hide(); |
| 38 |
$message.text('\u23F3 Sending recovery email...').css('background', '#f0f6fc').css('color', '#0c5ba5').css('border', '1px solid #cfe2f3').fadeIn(200); |
| 39 |
|
| 40 |
// Send AJAX request |
| 41 |
$.ajax({ |
| 42 |
url: ajaxurl, |
| 43 |
type: 'POST', |
| 44 |
data: { |
| 45 |
action: 'metasync_recover_password', |
| 46 |
nonce: metasyncWhitelabelData.recoverNonce |
| 47 |
}, |
| 48 |
success: function(response) { |
| 49 |
$link.css('pointer-events', 'auto').css('opacity', '1'); |
| 50 |
|
| 51 |
if (response.success) { |
| 52 |
$message.addClass('success').text('\u2705 ' + response.data.message) |
| 53 |
.css('background', '#d4edda') |
| 54 |
.css('color', '#155724') |
| 55 |
.css('border', '1px solid #c3e6cb'); |
| 56 |
} else { |
| 57 |
$message.addClass('error').text('\u274C ' + response.data.message) |
| 58 |
.css('background', '#f8d7da') |
| 59 |
.css('color', '#721c24') |
| 60 |
.css('border', '1px solid #f5c6cb'); |
| 61 |
} |
| 62 |
}, |
| 63 |
error: function() { |
| 64 |
$link.css('pointer-events', 'auto').css('opacity', '1'); |
| 65 |
$message.addClass('error').text('\u274C An error occurred. Please try again.') |
| 66 |
.css('background', '#f8d7da') |
| 67 |
.css('color', '#721c24') |
| 68 |
.css('border', '1px solid #f5c6cb'); |
| 69 |
} |
| 70 |
}); |
| 71 |
}); |
| 72 |
}); |
| 73 |
|