PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.3.5
MxChat – AI Chatbot & Content Generation for WordPress v2.3.5
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 +253 -53 2.0.32.3.5 View file →
@@ -1,61 +1,261 @@
1 -document.addEventListener('DOMContentLoaded', function() {
2 - var form = document.getElementById('mxchat-activation-form');
3 - var spinner = document.getElementById('mxchat-activation-spinner');
4 - var submitButton = document.getElementById('activate_license_button');
5 - var licenseStatus = document.getElementById('mxchat-license-status');
1 +/**
2 + * Enhanced MxChat License Activation JS
3 + * This handles BOTH local activation AND domain tracking
4 + * Plus deactivation functionality
5 + */
6 +jQuery(document).ready(function($) {
7 + // Get configuration from hidden fields
8 + const AJAX_URL = $('#mxchat-ajax-url').val() || ajaxurl;
9 + const NONCE = $('#mxchat-nonce').val();
10 + const API_URL = $('#mxchat-api-url').val() || 'https://mxchat.ai';
11 +
12 + // Elements
13 + const form = $('#mxchat-activation-form');
14 + const spinner = $('#mxchat-activation-spinner');
15 + const submitButton = $('#activate_license_button');
16 + const licenseStatus = $('#mxchat-license-status');
17 +
18 + // Activation handling
19 + if (form.length && licenseStatus.length && submitButton.length) {
20 + function handleActivationResponse(response) {
21 + if (response.success) {
22 + licenseStatus.text('Active');
23 + licenseStatus.removeClass('inactive').addClass('active');
24 + form.hide();
25 +
26 + // Track domain BEFORE showing success
27 + trackDomainActivation()
28 + .done(function(trackResponse) {
29 + console.log('Domain tracking successful:', trackResponse);
30 + spinner.hide();
31 + alert('License activated and domain linked successfully!');
32 +
33 + setTimeout(function() {
34 + location.reload();
35 + }, 1000);
36 + })
37 + .fail(function(jqXHR, textStatus, errorThrown) {
38 + console.error('Domain tracking failed:', textStatus, errorThrown);
39 + spinner.hide();
40 +
41 + // Still show success but warn about domain linking
42 + alert('License activated successfully!\n\nNote: Domain linking failed. You may need to use the "Link Domain" button after the page reloads.');
43 +
44 + setTimeout(function() {
45 + location.reload();
46 + }, 2000);
47 + });
48 + } else {
49 + spinner.hide();
50 + licenseStatus.text('Inactive');
51 + alert(response.data || 'Activation failed. Please check your input.');
52 + submitButton.prop('disabled', false);
53 + }
54 + }
6 55
7 - form.addEventListener('submit', function(e) {
8 - e.preventDefault();
56 + function checkActivationStatus() {
57 + const email = $('#mxchat_pro_email').val();
58 + const key = $('#mxchat_activation_key').val();
59 +
60 + $.ajax({
61 + type: 'POST',
62 + url: AJAX_URL,
63 + data: {
64 + action: 'mxchat_check_license_status',
65 + email: email,
66 + key: key,
67 + security: NONCE
68 + },
69 + success: function(response) {
70 + if (response.is_active) {
71 + licenseStatus.text('Active');
72 + licenseStatus.removeClass('inactive').addClass('active');
73 + form.hide();
74 +
75 + // Try to track domain for timeout scenario
76 + trackDomainActivation()
77 + .always(function() {
78 + alert('Your license has been activated successfully!');
79 + setTimeout(function() {
80 + location.reload();
81 + }, 1500);
82 + });
83 + } else {
84 + alert('License activation timed out. Please try again or contact support if the problem persists.');
85 + submitButton.prop('disabled', false);
86 + }
87 + },
88 + error: function() {
89 + alert('Unable to verify license status. Please refresh the page to check if activation was successful.');
90 + submitButton.prop('disabled', false);
91 + }
92 + });
93 + }
9 94
10 - // Show spinner and disable the button to prevent multiple submissions
11 - spinner.style.display = 'inline-block';
12 - submitButton.disabled = true;
95 + function trackDomainActivation() {
96 + const email = $('#mxchat_pro_email').val();
97 + const key = $('#mxchat_activation_key').val();
98 + const domain = $('#mxchat_domain').val();
99 +
100 + console.log('Attempting to track domain:', domain);
101 +
102 + return $.ajax({
103 + type: 'POST',
104 + url: API_URL + '/mxchat-api/activate-license',
105 + data: {
106 + mxchat_pro_email: email,
107 + mxchat_activation_key: key,
108 + domain: domain
109 + },
110 + timeout: 10000, // 10 second timeout
111 + xhrFields: {
112 + withCredentials: false // Ensure CORS compatibility
113 + },
114 + crossDomain: true
115 + });
116 + }
13 117
14 - // Gather form data
15 - var formData = new FormData(form);
16 - formData.append('action', 'mxchat_activate_license');
17 - formData.append('security', mxchatData.nonce);
18 -
19 - // Send the AJAX request
20 - var xhr = new XMLHttpRequest();
21 - xhr.open('POST', mxchatData.ajax_url, true);
22 - xhr.onload = function() {
23 - // Hide the spinner
24 - spinner.style.display = 'none';
25 -
26 - if (xhr.status >= 200 && xhr.status < 400) {
27 - var response = JSON.parse(xhr.responseText);
118 + form.on('submit', function(event) {
119 + event.preventDefault();
120 + spinner.show();
121 + submitButton.prop('disabled', true);
122 +
123 + var formData = {
124 + action: 'mxchat_handle_activate_license',
125 + mxchat_pro_email: $('#mxchat_pro_email').val(),
126 + mxchat_activation_key: $('#mxchat_activation_key').val(),
127 + security: NONCE
128 + };
129 +
130 + $.ajax({
131 + type: 'POST',
132 + url: AJAX_URL,
133 + data: formData,
134 + timeout: 70000,
135 + success: function(response) {
136 + handleActivationResponse(response);
137 + },
138 + error: function(jqXHR, textStatus) {
139 + if (textStatus === 'timeout') {
140 + spinner.hide();
141 + alert('Activation is taking longer than expected. Checking status...');
142 + checkActivationStatus();
143 + } else {
144 + alert('Activation failed due to a server error: ' + (jqXHR.responseText || textStatus));
145 + spinner.hide();
146 + submitButton.prop('disabled', false);
147 + }
148 + }
149 + });
150 + });
151 + }
152 +
153 + // Domain linking for existing activations
154 + $('#link-domain-button').on('click', function() {
155 + const button = $(this);
156 + const status = $('#domain-link-status');
157 + const originalText = button.text();
158 +
159 + // Get stored values from the page
160 + const email = $('input#mxchat_pro_email').val() ||
161 + $('p:contains("Email:")').text().split(':')[1]?.trim() ||
162 + '';
163 + const license_key = $('input#mxchat_activation_key').val() ||
164 + $('code:contains("-")').text().trim() ||
165 + '';
166 + const domain = $('#mxchat_domain').val();
167 +
168 + if (!email || !license_key) {
169 + status.html('<span style="color: red;">✗ Missing email or license key</span>');
170 + return;
171 + }
172 +
173 + button.prop('disabled', true).text('Linking...');
174 + status.html('<span style="color: #666;">Processing...</span>');
175 +
176 + $.ajax({
177 + type: 'POST',
178 + url: API_URL + '/mxchat-api/link-domain',
179 + data: {
180 + email: email,
181 + license_key: license_key,
182 + domain: domain
183 + },
184 + timeout: 10000,
185 + success: function(response) {
28 186 if (response.success) {
29 - // Update the license status to active
30 - licenseStatus.textContent = 'Active';
31 - licenseStatus.classList.remove('inactive');
32 - licenseStatus.classList.add('active');
33 -
34 - // Hide the activation form
35 - form.style.display = 'none';
187 + status.html('<span style="color: green;">✓ Domain linked successfully!</span>');
188 + button.hide();
189 +
190 + setTimeout(function() {
191 + location.reload();
192 + }, 2000);
36 193 } else {
37 - // Re-enable the button
38 - submitButton.disabled = false;
39 -
40 - // Handle the error case
41 - alert(response.data || 'There was an error activating the license.');
194 + status.html('<span style="color: red;">✗ ' + (response.data || 'Failed to link domain') + '</span>');
195 + button.prop('disabled', false).text(originalText);
42 196 }
43 - } else {
44 - // Re-enable the button
45 - submitButton.disabled = false;
46 -
47 - // Handle server error
48 - alert('Server error. Please try again.');
197 + },
198 + error: function(jqXHR, textStatus, errorThrown) {
199 + console.error('Domain linking error:', textStatus, errorThrown);
200 + status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
201 + button.prop('disabled', false).text(originalText);
49 202 }
50 - };
51 -
52 - xhr.onerror = function() {
53 - // Hide the spinner and re-enable the button on error
54 - spinner.style.display = 'none';
55 - submitButton.disabled = false;
56 - alert('Request failed. Please check your internet connection.');
57 - };
58 -
59 - xhr.send(formData); // Send the form data
203 + });
60 204 });
61 -});
205 +
206 + // License deactivation (unchanged)
207 + $('#deactivate-license-button').on('click', function() {
208 + const button = $(this);
209 + const status = $('#deactivate-status');
210 + const originalText = button.text();
211 +
212 + // Confirmation dialog
213 + const confirmMessage = 'Are you sure you want to deactivate this license?\n\n' +
214 + 'This will:\n' +
215 + '• Disable pro features on this site\n' +
216 + '• Unlink this domain from your account\n' +
217 + '• Allow you to activate on a different site\n\n' +
218 + 'You can reactivate anytime with the same license key.';
219 +
220 + if (!confirm(confirmMessage)) {
221 + return;
222 + }
223 +
224 + button.prop('disabled', true).text('Deactivating...');
225 + status.html('<span style="color: #666;">Processing...</span>');
226 +
227 + $.ajax({
228 + type: 'POST',
229 + url: AJAX_URL,
230 + data: {
231 + action: 'mxchat_deactivate_license',
232 + security: NONCE
233 + },
234 + timeout: 15000,
235 + success: function(response) {
236 + if (response.success) {
237 + status.html('<span style="color: green;">✓ ' + response.data.message + '</span>');
238 +
239 + // Show success message
240 + alert('License deactivated successfully!\n\nYou can now activate this license on another site.');
241 +
242 + // Reload page to show deactivated state
243 + setTimeout(function() {
244 + location.reload();
245 + }, 2000);
246 + } else {
247 + status.html('<span style="color: red;">✗ ' + (response.data || 'Deactivation failed') + '</span>');
248 + button.prop('disabled', false).text(originalText);
249 + }
250 + },
251 + error: function(jqXHR, textStatus) {
252 + if (textStatus === 'timeout') {
253 + status.html('<span style="color: orange;">⚠ Deactivation timed out. Please check your account dashboard.</span>');
254 + } else {
255 + status.html('<span style="color: red;">✗ Connection error. Please try again.</span>');
256 + }
257 + button.prop('disabled', false).text(originalText);
258 + }
259 + });
260 + });
261 +});