PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.3.4
MxChat – AI Chatbot & Content Generation for WordPress v2.3.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 +46 -121 3.2.122.3.4 View file →
@@ -1,9 +1,8 @@
1 1 /**
2 2 * Enhanced MxChat License Activation JS
3 3 * This handles BOTH local activation AND domain tracking
4 4 * Plus deactivation functionality
5 - * VERSION: Increased timeouts for better user experience
6 5 */
7 6 jQuery(document).ready(function($) {
8 7 // Get configuration from hidden fields
9 8 const AJAX_URL = $('#mxchat-ajax-url').val() || ajaxurl;
@@ -15,73 +14,28 @@
15 14 const spinner = $('#mxchat-activation-spinner');
16 15 const submitButton = $('#activate_license_button');
17 16 const licenseStatus = $('#mxchat-license-status');
18 17
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 18 // Activation handling
47 19 if (form.length && licenseStatus.length && submitButton.length) {
48 20 function handleActivationResponse(response) {
21 + spinner.hide();
49 22 if (response.success) {
50 23 licenseStatus.text('Active');
51 24 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 - });
25 + form.hide();
26 +
27 + alert('License activated successfully!');
28 +
29 + // Track domain on your website
30 + trackDomainActivation();
31 +
32 + setTimeout(function() {
33 + location.reload();
34 + }, 1500);
80 35 } else {
81 - spinner.hide();
82 36 licenseStatus.text('Inactive');
83 - showStatus(response.data || 'Activation failed. Please check your input.', 'error');
37 + alert(response.data || 'Activation failed. Please check your input.');
84 38 submitButton.prop('disabled', false);
85 39 }
86 40 }
87 41
@@ -97,31 +51,20 @@
97 51 email: email,
98 52 key: key,
99 53 security: NONCE
100 54 },
101 - timeout: 45000, // Increased from default to 45 seconds
102 55 success: function(response) {
103 56 if (response.is_active) {
104 57 licenseStatus.text('Active');
105 58 licenseStatus.removeClass('inactive').addClass('active');
106 59 form.hide();
60 + alert('Your license has been activated successfully!');
107 61
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 - });
62 + trackDomainActivation();
63 +
64 + setTimeout(function() {
65 + location.reload();
66 + }, 1500);
124 67 } else {
125 68 alert('License activation timed out. Please try again or contact support if the problem persists.');
126 69 submitButton.prop('disabled', false);
127 70 }
@@ -133,27 +76,22 @@
133 76 });
134 77 }
135 78
136 79 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({
80 + $.ajax({
144 81 type: 'POST',
145 - url: API_URL + '/mxchat-api/link-domain', // Changed to use same endpoint as manual linking
82 + url: API_URL + '/mxchat-api/activate-license',
146 83 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
84 + mxchat_pro_email: $('#mxchat_pro_email').val(),
85 + mxchat_activation_key: $('#mxchat_activation_key').val(),
86 + domain: $('#mxchat_domain').val()
150 87 },
151 - timeout: 30000, // Increased from 10 seconds to 30 seconds
152 - xhrFields: {
153 - withCredentials: false // Ensure CORS compatibility
88 + success: function(response) {
89 + //console.log('Domain tracking:', response.success ? 'Success' : 'Failed');
154 90 },
155 - crossDomain: true
91 + error: function() {
92 + //console.log('Domain tracking: Connection error');
93 + }
156 94 });
157 95 }
158 96
159 97 form.on('submit', function(event) {
@@ -159,10 +97,9 @@
159 97 form.on('submit', function(event) {
160 98 event.preventDefault();
161 99 spinner.show();
162 100 submitButton.prop('disabled', true);
163 - showStatus('Validating license key...', 'loading');
164 -
101 +
165 102 var formData = {
166 103 action: 'mxchat_handle_activate_license',
167 104 mxchat_pro_email: $('#mxchat_pro_email').val(),
168 105 mxchat_activation_key: $('#mxchat_activation_key').val(),
@@ -167,23 +104,27 @@
167 104 mxchat_pro_email: $('#mxchat_pro_email').val(),
168 105 mxchat_activation_key: $('#mxchat_activation_key').val(),
169 106 security: NONCE
170 107 };
171 -
108 +
172 109 $.ajax({
173 110 type: 'POST',
174 111 url: AJAX_URL,
175 112 data: formData,
176 - timeout: 120000, // Increased from 70 seconds to 2 minutes (120 seconds)
113 + timeout: 70000,
177 114 success: function(response) {
178 115 handleActivationResponse(response);
179 116 },
180 117 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();
118 + if (textStatus === 'timeout') {
119 + spinner.hide();
120 + alert('Activation is taking longer than expected. Checking status...');
121 + checkActivationStatus();
122 + } else {
123 + alert('Activation failed due to a server error: ' + (jqXHR.responseText || textStatus));
124 + spinner.hide();
125 + submitButton.prop('disabled', false);
126 + }
186 127 }
187 128 });
188 129 });
189 130 }
@@ -193,22 +134,8 @@
193 134 const button = $(this);
194 135 const status = $('#domain-link-status');
195 136 const originalText = button.text();
196 137
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 138 button.prop('disabled', true).text('Linking...');
212 139 status.html('<span style="color: #666;">Processing...</span>');
213 140
214 141 $.ajax({
@@ -214,13 +141,12 @@
214 141 $.ajax({
215 142 type: 'POST',
216 143 url: API_URL + '/mxchat-api/link-domain',
217 144 data: {
218 - email: email,
219 - license_key: license_key,
220 - domain: domain
145 + email: $('#mxchat_pro_email').val(),
146 + license_key: $('#mxchat_activation_key').val(),
147 + domain: $('#mxchat_domain').val()
221 148 },
222 - timeout: 30000, // Increased from 10 seconds to 30 seconds
223 149 success: function(response) {
224 150 if (response.success) {
225 151 status.html('<span style="color: green;">✓ Domain linked successfully!</span>');
226 152 button.hide();
@@ -226,16 +152,15 @@
226 152 button.hide();
227 153
228 154 setTimeout(function() {
229 155 location.reload();
230 - }, 2000);
156 + }, 3000);
231 157 } else {
232 158 status.html('<span style="color: red;">✗ ' + (response.data || 'Failed to link domain') + '</span>');
233 159 button.prop('disabled', false).text(originalText);
234 160 }
235 161 },
236 - error: function(jqXHR, textStatus, errorThrown) {
237 - console.error('Domain linking error:', textStatus, errorThrown);
162 + error: function(jqXHR, textStatus) {
238 163 status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
239 164 button.prop('disabled', false).text(originalText);
240 165 }
241 166 });
@@ -268,9 +193,9 @@
268 193 data: {
269 194 action: 'mxchat_deactivate_license',
270 195 security: NONCE
271 196 },
272 - timeout: 45000, // Increased from 15 seconds to 45 seconds
197 + timeout: 15000,
273 198 success: function(response) {
274 199 if (response.success) {
275 200 status.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
276 201