← All changes
|
includes/widgets/Login_Register_Form/script.js
+23
-29
51.1.36
→
51.1.86
View file →
| @@ -27,9 +27,8 @@ | ||
| 27 | 27 | const isAjaxEnabled = $wrapper.data('ajax') === true; |
| 28 | 28 | |
| 29 | 29 | // Get widget settings from data attributes |
| 30 | 30 | const widgetSettings = { |
| 31 | - recaptcha_secret_key: $wrapper.data('recaptcha-secret-key') || '', | |
| 32 | 31 | recaptcha_score_threshold: $wrapper.data('recaptcha-threshold') || '0.5', |
| 33 | 32 | redirect_after_login: $wrapper.data('redirect-login') || '', |
| 34 | 33 | redirect_after_register: $wrapper.data('redirect-register') || '', |
| 35 | 34 | terms_required: $wrapper.data('terms-required') || 'no', |
| @@ -40,11 +39,8 @@ | ||
| 40 | 39 | admin_email_address: $wrapper.data('admin-email-address') || '', |
| 41 | 40 | admin_email_subject: $wrapper.data('admin-email-subject') || '', |
| 42 | 41 | admin_email_content: $wrapper.data('admin-email-content') || '', |
| 43 | 42 | enable_mailchimp_integration: $wrapper.data('enable-mailchimp') || 'no', |
| 44 | - mailchimp_api_key: $wrapper.data('mailchimp-api-key') || '', | |
| 45 | - mailchimp_list_id: $wrapper.data('mailchimp-list-id') || '', | |
| 46 | - mailchimp_double_optin: $wrapper.data('mailchimp-double-optin') || 'no', | |
| 47 | 43 | auto_login_after_register: $wrapper.data('auto-login') || 'yes' |
| 48 | 44 | }; |
| 49 | 45 | |
| 50 | 46 | // Form toggle functionality |
| @@ -124,8 +120,9 @@ | ||
| 124 | 120 | |
| 125 | 121 | function handleLoginSubmission($form, $wrapper, widgetId, widgetSettings) { |
| 126 | 122 | const $messageContainer = $form.closest('.king-addons-login-register-form').find('.king-addons-form-message'); |
| 127 | 123 | const $submitButton = $form.find('.king-addons-login-button'); |
| 124 | + const postId = $wrapper.data('post-id') || 0; | |
| 128 | 125 | |
| 129 | 126 | // Clear previous messages |
| 130 | 127 | clearMessages($wrapper); |
| 131 | 128 | |
| @@ -130,9 +127,9 @@ | ||
| 130 | 127 | clearMessages($wrapper); |
| 131 | 128 | |
| 132 | 129 | // Check if variables are defined |
| 133 | 130 | if (typeof king_addons_login_register_vars === 'undefined') { |
| 134 | - console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 131 | + // console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 135 | 132 | showMessage($messageContainer, 'Configuration error. Please refresh the page.', 'error'); |
| 136 | 133 | return; |
| 137 | 134 | } |
| 138 | 135 | |
| @@ -143,9 +140,9 @@ | ||
| 143 | 140 | username: $form.find('[name="username"]').val(), |
| 144 | 141 | password: $form.find('[name="password"]').val(), |
| 145 | 142 | remember: $form.find('[name="remember"]').is(':checked') ? 1 : 0, |
| 146 | 143 | widget_id: widgetId, |
| 147 | - recaptcha_secret_key: widgetSettings.recaptcha_secret_key, | |
| 144 | + post_id: postId, | |
| 148 | 145 | recaptcha_score_threshold: widgetSettings.recaptcha_score_threshold, |
| 149 | 146 | redirect_after_login: widgetSettings.redirect_after_login |
| 150 | 147 | }; |
| 151 | 148 | |
| @@ -154,9 +151,9 @@ | ||
| 154 | 151 | if (recaptchaResponse) { |
| 155 | 152 | formData['g-recaptcha-response'] = recaptchaResponse; |
| 156 | 153 | } |
| 157 | 154 | |
| 158 | - console.log('Submitting login form with data:', formData); | |
| 155 | + // console.log('Submitting login form with data:', formData); | |
| 159 | 156 | |
| 160 | 157 | // Validate required fields |
| 161 | 158 | if (!formData.username || !formData.password) { |
| 162 | 159 | showMessage($messageContainer, 'Please fill in all required fields.', 'error'); |
| @@ -191,11 +188,11 @@ | ||
| 191 | 188 | showMessage($messageContainer, response.data.message || 'An error occurred. Please try again.', 'error'); |
| 192 | 189 | } |
| 193 | 190 | }, |
| 194 | 191 | error: function(xhr, status, error) { |
| 195 | - console.error('Login AJAX Error:', error); | |
| 196 | - console.error('Login XHR response:', xhr.responseText); | |
| 197 | - console.error('Login XHR status code:', xhr.status); | |
| 192 | + // console.error('Login AJAX Error:', error); | |
| 193 | + // console.error('Login XHR response:', xhr.responseText); | |
| 194 | + // console.error('Login XHR status code:', xhr.status); | |
| 198 | 195 | |
| 199 | 196 | let errorMessage = 'Network error. Please check your connection and try again.'; |
| 200 | 197 | |
| 201 | 198 | // Try to parse error response |
| @@ -219,8 +216,9 @@ | ||
| 219 | 216 | |
| 220 | 217 | function handleRegisterSubmission($form, $wrapper, widgetId, widgetSettings) { |
| 221 | 218 | const $messageContainer = $form.closest('.king-addons-login-register-form').find('.king-addons-form-message'); |
| 222 | 219 | const $submitButton = $form.find('.king-addons-register-button'); |
| 220 | + const postId = $wrapper.data('post-id') || 0; | |
| 223 | 221 | |
| 224 | 222 | // Clear previous messages |
| 225 | 223 | clearMessages($wrapper); |
| 226 | 224 | |
| @@ -225,9 +223,9 @@ | ||
| 225 | 223 | clearMessages($wrapper); |
| 226 | 224 | |
| 227 | 225 | // Check if variables are defined |
| 228 | 226 | if (typeof king_addons_login_register_vars === 'undefined') { |
| 229 | - console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 227 | + // console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 230 | 228 | showMessage($messageContainer, 'Configuration error. Please refresh the page.', 'error'); |
| 231 | 229 | return; |
| 232 | 230 | } |
| 233 | 231 | |
| @@ -239,9 +237,9 @@ | ||
| 239 | 237 | username: $form.find('[name="username"]').val(), |
| 240 | 238 | password: $form.find('[name="password"]').val(), |
| 241 | 239 | confirm_password: $form.find('[name="confirm_password"]').val(), |
| 242 | 240 | widget_id: widgetId, |
| 243 | - recaptcha_secret_key: widgetSettings.recaptcha_secret_key, | |
| 241 | + post_id: postId, | |
| 244 | 242 | recaptcha_score_threshold: widgetSettings.recaptcha_score_threshold, |
| 245 | 243 | redirect_after_register: widgetSettings.redirect_after_register, |
| 246 | 244 | terms_required: widgetSettings.terms_required, |
| 247 | 245 | enable_user_email: widgetSettings.enable_user_email, |
| @@ -251,11 +249,8 @@ | ||
| 251 | 249 | admin_email_address: widgetSettings.admin_email_address, |
| 252 | 250 | admin_email_subject: widgetSettings.admin_email_subject, |
| 253 | 251 | admin_email_content: widgetSettings.admin_email_content, |
| 254 | 252 | enable_mailchimp_integration: widgetSettings.enable_mailchimp_integration, |
| 255 | - mailchimp_api_key: widgetSettings.mailchimp_api_key, | |
| 256 | - mailchimp_list_id: widgetSettings.mailchimp_list_id, | |
| 257 | - mailchimp_double_optin: widgetSettings.mailchimp_double_optin, | |
| 258 | 253 | auto_login_after_register: widgetSettings.auto_login_after_register |
| 259 | 254 | }; |
| 260 | 255 | |
| 261 | 256 | // Add additional fields if they exist |
| @@ -322,12 +317,12 @@ | ||
| 322 | 317 | // Add custom fields to form data if any exist |
| 323 | 318 | if (Object.keys(customFields).length > 0) { |
| 324 | 319 | formData.custom_fields = customFields; |
| 325 | 320 | formData.custom_field_labels = customFieldLabels; |
| 326 | - console.log('Found custom fields:', customFields); | |
| 327 | - console.log('Field labels:', customFieldLabels); | |
| 321 | + // console.log('Found custom fields:', customFields); | |
| 322 | + // console.log('Field labels:', customFieldLabels); | |
| 328 | 323 | } else { |
| 329 | - console.log('No custom fields found'); | |
| 324 | + // console.log('No custom fields found'); | |
| 330 | 325 | } |
| 331 | 326 | |
| 332 | 327 | // Add reCAPTCHA response if present |
| 333 | 328 | const recaptchaResponse = $form.find('[name="g-recaptcha-response"]').val(); |
| @@ -334,9 +329,9 @@ | ||
| 334 | 329 | if (recaptchaResponse) { |
| 335 | 330 | formData['g-recaptcha-response'] = recaptchaResponse; |
| 336 | 331 | } |
| 337 | 332 | |
| 338 | - console.log('Submitting registration form with data:', formData); | |
| 333 | + // console.log('Submitting registration form with data:', formData); | |
| 339 | 334 | |
| 340 | 335 | // Client-side validation |
| 341 | 336 | const validationResult = validateRegistrationForm(formData); |
| 342 | 337 | if (!validationResult.valid) { |
| @@ -408,11 +403,11 @@ | ||
| 408 | 403 | } else { |
| 409 | 404 | showMessage($messageContainer, response.data.message || 'Registration failed. Please try again.', 'error'); |
| 410 | 405 | } |
| 411 | 406 | }).fail(function(xhr, status, error) { |
| 412 | - console.error('Registration AJAX Error:', error); | |
| 413 | - console.error('Registration XHR response:', xhr.responseText); | |
| 414 | - console.error('Registration XHR status code:', xhr.status); | |
| 407 | + // console.error('Registration AJAX Error:', error); | |
| 408 | + // console.error('Registration XHR response:', xhr.responseText); | |
| 409 | + // console.error('Registration XHR status code:', xhr.status); | |
| 415 | 410 | |
| 416 | 411 | let errorMessage = 'Network error. Please check your connection and try again.'; |
| 417 | 412 | |
| 418 | 413 | // Try to parse error response |
| @@ -440,9 +435,9 @@ | ||
| 440 | 435 | clearMessages($wrapper); |
| 441 | 436 | |
| 442 | 437 | // Check if variables are defined |
| 443 | 438 | if (typeof king_addons_login_register_vars === 'undefined') { |
| 444 | - console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 439 | + // console.error('King Addons Login Register: AJAX variables not loaded'); | |
| 445 | 440 | showMessage($messageContainer, 'Configuration error. Please refresh the page.', 'error'); |
| 446 | 441 | return; |
| 447 | 442 | } |
| 448 | 443 | |
| @@ -478,11 +473,11 @@ | ||
| 478 | 473 | showMessage($messageContainer, response.data.message || 'Lost password request failed. Please try again.', 'error'); |
| 479 | 474 | } |
| 480 | 475 | }, |
| 481 | 476 | error: function(xhr, status, error) { |
| 482 | - console.error('Lost Password AJAX Error:', error); | |
| 483 | - console.error('Lost Password XHR response:', xhr.responseText); | |
| 484 | - console.error('Lost Password XHR status code:', xhr.status); | |
| 477 | + // console.error('Lost Password AJAX Error:', error); | |
| 478 | + // console.error('Lost Password XHR response:', xhr.responseText); | |
| 479 | + // console.error('Lost Password XHR status code:', xhr.status); | |
| 485 | 480 | |
| 486 | 481 | let errorMessage = 'Network error. Please check your connection and try again.'; |
| 487 | 482 | |
| 488 | 483 | // Try to parse error response |
| @@ -790,9 +785,9 @@ | ||
| 790 | 785 | action: 'king_addons_google_login', |
| 791 | 786 | nonce: king_addons_login_register_vars.social_login_nonce, |
| 792 | 787 | google_token: response.credential, |
| 793 | 788 | widget_id: widgetId, |
| 794 | - google_client_id: $wrapper.data('google-client-id') | |
| 789 | + post_id: $wrapper.data('post-id') || 0 | |
| 795 | 790 | }, |
| 796 | 791 | success: function(ajaxResponse) { |
| 797 | 792 | if (ajaxResponse.success) { |
| 798 | 793 | showMessage($messageContainer, ajaxResponse.data.message, 'success'); |
| @@ -830,10 +825,9 @@ | ||
| 830 | 825 | action: 'king_addons_facebook_login', |
| 831 | 826 | nonce: king_addons_login_register_vars.social_login_nonce, |
| 832 | 827 | facebook_token: authResponse.accessToken, |
| 833 | 828 | widget_id: widgetId, |
| 834 | - facebook_app_id: $wrapper.data('facebook-app-id'), | |
| 835 | - facebook_app_secret: $wrapper.data('facebook-app-secret') | |
| 829 | + post_id: $wrapper.data('post-id') || 0 | |
| 836 | 830 | }, |
| 837 | 831 | success: function(ajaxResponse) { |
| 838 | 832 | if (ajaxResponse.success) { |
| 839 | 833 | showMessage($messageContainer, ajaxResponse.data.message, 'success'); |