PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.2.4
MxChat – AI Chatbot & Content Generation for WordPress v2.2.4
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | js/activation-script.js +29 -233 3.2.112.2.4 View file →
@@ -1,87 +1,25 @@
1 1 /**
2 - * Enhanced MxChat License Activation JS
3 - * This handles BOTH local activation AND domain tracking
4 - * Plus deactivation functionality
5 - * VERSION: Increased timeouts for better user experience
2 + * MxChat License Activation JS
3 + * Handles the license activation form submission with timeout handling
6 4 */
7 5 jQuery(document).ready(function($) {
8 - // Get configuration from hidden fields
9 - const AJAX_URL = $('#mxchat-ajax-url').val() || ajaxurl;
10 - const NONCE = $('#mxchat-nonce').val();
11 - const API_URL = $('#mxchat-api-url').val() || 'https://mxchat.ai';
12 -
13 - // Elements
6 + // Activation handling
14 7 const form = $('#mxchat-activation-form');
15 8 const spinner = $('#mxchat-activation-spinner');
16 9 const submitButton = $('#activate_license_button');
17 10 const licenseStatus = $('#mxchat-license-status');
18 11
19 - // Create or get status message element
20 - var $statusMessage = $('<div id="mxchat-activation-status" style="margin-top: 12px; padding: 12px 16px; border-radius: 8px; font-size: 14px; display: none;"></div>');
21 - if ($('#mxchat-activation-status').length === 0) {
22 - spinner.after($statusMessage);
23 - } else {
24 - $statusMessage = $('#mxchat-activation-status');
25 - }
26 -
27 - function showStatus(message, type) {
28 - var bgColor = type === 'success' ? 'rgba(16, 185, 129, 0.1)' :
29 - type === 'error' ? 'rgba(239, 68, 68, 0.1)' :
30 - 'rgba(120, 115, 245, 0.1)';
31 - var textColor = type === 'success' ? '#059669' :
32 - type === 'error' ? '#dc2626' :
33 - '#7873f5';
34 - var icon = type === 'success' ? '✓' :
35 - type === 'error' ? '✗' :
36 - '<span class="dashicons dashicons-update spin" style="font-size: 14px; width: 14px; height: 14px; margin-right: 4px;"></span>';
37 -
38 - $statusMessage.html(icon + ' ' + message)
39 - .css({
40 - 'background': bgColor,
41 - 'color': textColor,
42 - 'display': 'block'
43 - });
44 - }
45 -
46 - // Activation handling
47 12 if (form.length && licenseStatus.length && submitButton.length) {
48 13 function handleActivationResponse(response) {
14 + spinner.hide();
49 15 if (response.success) {
50 16 licenseStatus.text('Active');
51 17 licenseStatus.removeClass('inactive').addClass('active');
52 -
53 - // Show linking status - keep spinner visible
54 - showStatus('License verified! Linking domain...', 'loading');
55 -
56 - // Track domain BEFORE showing success
57 - trackDomainActivation()
58 - .done(function(trackResponse) {
59 - console.log('Domain tracking successful:', trackResponse);
60 - spinner.hide();
61 - showStatus('License activated and domain linked successfully!', 'success');
62 -
63 - // Wait before reload
64 - setTimeout(function() {
65 - location.reload();
66 - }, 2000);
67 - })
68 - .fail(function(jqXHR, textStatus, errorThrown) {
69 - console.error('Domain tracking failed:', textStatus, errorThrown);
70 - spinner.hide();
71 -
72 - // Still show success but warn about domain linking
73 - showStatus('License activated! Domain linking failed - you can link it manually after reload.', 'success');
74 -
75 - // Wait before reload
76 - setTimeout(function() {
77 - location.reload();
78 - }, 3000);
79 - });
18 + form.hide();
80 19 } else {
81 - spinner.hide();
82 20 licenseStatus.text('Inactive');
83 - showStatus(response.data || 'Activation failed. Please check your input.', 'error');
21 + alert(response.data || 'Activation failed. Please check your input.');
84 22 submitButton.prop('disabled', false);
85 23 }
86 24 }
87 25
@@ -90,39 +28,24 @@
90 28 const key = $('#mxchat_activation_key').val();
91 29
92 30 $.ajax({
93 31 type: 'POST',
94 - url: AJAX_URL,
32 + url: mxchatAdmin.ajax_url,
95 33 data: {
96 34 action: 'mxchat_check_license_status',
97 35 email: email,
98 36 key: key,
99 - security: NONCE
37 + security: mxchatAdmin.license_nonce
100 38 },
101 - timeout: 45000, // Increased from default to 45 seconds
102 39 success: function(response) {
103 40 if (response.is_active) {
41 + // License is actually active, update UI
104 42 licenseStatus.text('Active');
105 43 licenseStatus.removeClass('inactive').addClass('active');
106 44 form.hide();
107 -
108 - // Try to track domain for timeout scenario
109 - trackDomainActivation()
110 - .done(function(trackResponse) {
111 - console.log('Domain tracking completed after timeout check:', trackResponse);
112 - alert('Your license has been activated and domain linked successfully!');
113 - setTimeout(function() {
114 - location.reload();
115 - }, 3000);
116 - })
117 - .fail(function() {
118 - console.log('Domain tracking failed after timeout check');
119 - alert('Your license has been activated successfully!\n\nNote: Domain linking may have failed. Check the "Link Domain" button after reload if needed.');
120 - setTimeout(function() {
121 - location.reload();
122 - }, 3000);
123 - });
45 + alert('Your license has been activated successfully!');
124 46 } else {
47 + // Truly not activated
125 48 alert('License activation timed out. Please try again or contact support if the problem persists.');
126 49 submitButton.prop('disabled', false);
127 50 }
128 51 },
@@ -131,169 +54,42 @@
131 54 submitButton.prop('disabled', false);
132 55 }
133 56 });
134 57 }
135 -
136 - function trackDomainActivation() {
137 - const email = $('#mxchat_pro_email').val();
138 - const key = $('#mxchat_activation_key').val();
139 - const domain = $('#mxchat_domain').val();
140 -
141 - console.log('Attempting to track domain:', domain);
142 -
143 - return $.ajax({
144 - type: 'POST',
145 - url: API_URL + '/mxchat-api/link-domain', // Changed to use same endpoint as manual linking
146 - data: {
147 - email: email, // Changed parameter name to match manual linking
148 - license_key: key, // Changed parameter name to match manual linking
149 - domain: domain
150 - },
151 - timeout: 30000, // Increased from 10 seconds to 30 seconds
152 - xhrFields: {
153 - withCredentials: false // Ensure CORS compatibility
154 - },
155 - crossDomain: true
156 - });
157 - }
158 -
58 +
159 59 form.on('submit', function(event) {
160 60 event.preventDefault();
161 61 spinner.show();
162 62 submitButton.prop('disabled', true);
163 - showStatus('Validating license key...', 'loading');
164 -
63 +
165 64 var formData = {
166 - action: 'mxchat_handle_activate_license',
65 + action: 'mxchat_activate_license',
167 66 mxchat_pro_email: $('#mxchat_pro_email').val(),
168 67 mxchat_activation_key: $('#mxchat_activation_key').val(),
169 - security: NONCE
68 + security: mxchatAdmin.license_nonce
170 69 };
171 -
70 +
71 + // Use $.ajax instead of $.post to have more control
172 72 $.ajax({
173 73 type: 'POST',
174 - url: AJAX_URL,
74 + url: mxchatAdmin.ajax_url,
175 75 data: formData,
176 - timeout: 120000, // Increased from 70 seconds to 2 minutes (120 seconds)
76 + timeout: 70000, // 70 seconds (slightly longer than server timeout)
177 77 success: function(response) {
178 78 handleActivationResponse(response);
179 79 },
180 80 error: function(jqXHR, textStatus) {
181 - // On any error, check if the license was actually saved successfully
182 - // This handles cases where the response format caused a parse error
183 - // but the activation actually worked
184 - showStatus('Verifying activation status...', 'loading');
185 - checkActivationStatus();
81 + if (textStatus === 'timeout') {
82 + spinner.hide();
83 + alert('Activation is taking longer than expected. Checking status...');
84 + checkActivationStatus();
85 + } else {
86 + //console.log('AJAX Error:', textStatus, jqXHR.responseText);
87 + alert('Activation failed due to a server error: ' + (jqXHR.responseText || textStatus));
88 + spinner.hide();
89 + submitButton.prop('disabled', false);
90 + }
186 91 }
187 92 });
188 93 });
189 94 }
190 -
191 - // Domain linking for existing activations
192 - $('#link-domain-button').on('click', function() {
193 - const button = $(this);
194 - const status = $('#domain-link-status');
195 - const originalText = button.text();
196 -
197 - // Get stored values from the page
198 - const email = $('input#mxchat_pro_email').val() ||
199 - $('p:contains("Email:")').text().split(':')[1]?.trim() ||
200 - '';
201 - const license_key = $('input#mxchat_activation_key').val() ||
202 - $('code:contains("-")').text().trim() ||
203 - '';
204 - const domain = $('#mxchat_domain').val();
205 -
206 - if (!email || !license_key) {
207 - status.html('<span style="color: red;">✗ Missing email or license key</span>');
208 - return;
209 - }
210 -
211 - button.prop('disabled', true).text('Linking...');
212 - status.html('<span style="color: #666;">Processing...</span>');
213 -
214 - $.ajax({
215 - type: 'POST',
216 - url: API_URL + '/mxchat-api/link-domain',
217 - data: {
218 - email: email,
219 - license_key: license_key,
220 - domain: domain
221 - },
222 - timeout: 30000, // Increased from 10 seconds to 30 seconds
223 - success: function(response) {
224 - if (response.success) {
225 - status.html('<span style="color: green;">✓ Domain linked successfully!</span>');
226 - button.hide();
227 -
228 - setTimeout(function() {
229 - location.reload();
230 - }, 2000);
231 - } else {
232 - status.html('<span style="color: red;">✗ ' + (response.data || 'Failed to link domain') + '</span>');
233 - button.prop('disabled', false).text(originalText);
234 - }
235 - },
236 - error: function(jqXHR, textStatus, errorThrown) {
237 - console.error('Domain linking error:', textStatus, errorThrown);
238 - status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
239 - button.prop('disabled', false).text(originalText);
240 - }
241 - });
242 - });
243 -
244 - // License deactivation
245 - $('#deactivate-license-button').on('click', function() {
246 - const button = $(this);
247 - const status = $('#deactivate-status');
248 - const originalText = button.text();
249 -
250 - // Confirmation dialog
251 - const confirmMessage = 'Are you sure you want to deactivate this license?\n\n' +
252 - 'This will:\n' +
253 - '• Disable pro features on this site\n' +
254 - '• Unlink this domain from your account\n' +
255 - '• Allow you to activate on a different site\n\n' +
256 - 'You can reactivate anytime with the same license key.';
257 -
258 - if (!confirm(confirmMessage)) {
259 - return;
260 - }
261 -
262 - button.prop('disabled', true).text('Deactivating...');
263 - status.html('<span style="color: #666;">Processing...</span>');
264 -
265 - $.ajax({
266 - type: 'POST',
267 - url: AJAX_URL,
268 - data: {
269 - action: 'mxchat_deactivate_license',
270 - security: NONCE
271 - },
272 - timeout: 45000, // Increased from 15 seconds to 45 seconds
273 - success: function(response) {
274 - if (response.success) {
275 - status.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
276 -
277 - // Show success message
278 - alert('License deactivated successfully!\n\nYou can now activate this license on another site.');
279 -
280 - // Reload page to show deactivated state
281 - setTimeout(function() {
282 - location.reload();
283 - }, 2000);
284 - } else {
285 - status.html('<span style="color: red;">✗ ' + (response.data || 'Deactivation failed') + '</span>');
286 - button.prop('disabled', false).text(originalText);
287 - }
288 - },
289 - error: function(jqXHR, textStatus) {
290 - if (textStatus === 'timeout') {
291 - status.html('<span style="color: orange;">⚠ Deactivation timed out. Please check your account dashboard.</span>');
292 - } else {
293 - status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
294 - }
295 - button.prop('disabled', false).text(originalText);
296 - }
297 - });
298 - });
299 95 });