Changeset 2186087
- Timestamp:
- 11/05/2019 11:34:47 AM (5 years ago)
- Location:
- tidio-live-chat/trunk
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
tidio-live-chat/trunk/media/js/options.js
r2179244 r2186087 3 3 var TidioChatWP = { 4 4 apiUrl: 'https://api-v2.tidio.co', 5 chatUrl: 'https://www.tidio chat.com',5 chatUrl: 'https://www.tidio.com', 6 6 token: null, 7 email: '', 7 8 init: function () { 9 // check if page is already integrated; if so show after install screen 10 if ($('a[href="admin.php?page=tidio-chat"]').length === 0) { 11 $.post(ajaxurl, { 12 'action': 'get_private_key', 13 '_wpnonce': nonce, 14 }, 15 function (response) { 16 if (response === 'error') { 17 // load through ajax url 18 TidioChatWP.accessThroughXHR(redirect); 19 return false; 20 } 21 $('#after-install-text').show(); 22 TidioChatWP.setRedirectLink(response); 23 }); 24 return; 25 } 8 26 this.error = $('.error'); 9 10 27 this.form = $('#tidio-start'); 11 28 this.form.show(); … … 26 43 } 27 44 this.hideError(); 28 45 this.email = emailField.val(); 29 46 submitButton.prop('disabled', true).text('Loading...'); 30 47 … … 35 52 data.value.registered === true) { 36 53 this.form.hide(); 37 submitButton.prop('disabled', false). 38 text('Start using Tidio'); 54 submitButton.prop('disabled', false).text('Start using Tidio'); 39 55 this.showLoginForm(emailField.val()); 40 56 } else { 41 57 this.redirectToPanel(); 42 58 } 43 }.bind(this)).fail((function( ) {59 }.bind(this)).fail((function(error) { 44 60 submitButton.prop('disabled', false).text('Start using Tidio'); 45 this.showError('Something went wrong.'); 61 if (error && error.status === 429) { 62 this.showError('You have been blocked for too many failed attempts. Please try again in an hour.'); 63 } else { 64 this.showError('Something went wrong.'); 65 } 66 46 67 }).bind(this)); 47 68 return false; … … 100 121 return false; 101 122 }, 123 addEmailToRedirectLink: function(url) { 124 return url + '&tour_default_email=' + encodeURIComponent(this.email); 125 }, 102 126 redirectToPanel: function () { 103 var form = this.form;104 127 var redirect = function (response) { 105 window.open(response, '_blank'); 106 TidioChatWP.setRedirectLink(response); 107 form.fadeOut('fast', function () { 128 var url = this.addEmailToRedirectLink(response); 129 window.open(url, '_blank'); 130 TidioChatWP.setRedirectLink(url); 131 this.form.fadeOut('fast', function () { 108 132 $('#after-install-text').fadeIn('fast'); 109 133 }); 110 }; 111 112 $.post(ajaxurl, { 'action': 'get_private_key' }, 134 }.bind(this); 135 136 $.post(ajaxurl, { 137 'action': 'get_private_key', 138 '_wpnonce': nonce, 139 }, 113 140 function (response) { 114 141 if (response === 'error') { 115 // load t roughtajax url116 TidioChatWP.accessT roughtXHR(redirect);142 // load through ajax url 143 TidioChatWP.accessThroughXHR(redirect); 117 144 return false; 118 145 } … … 171 198 }, 172 199 onProjectSubmit: function () { 173 var details = $('#select-tidio-project option:selected'). 174 data('value'); 175 $.extend(details, { 'action': 'set_project_keys', 'api_token': TidioChatWP.token }); 200 var details = $('#select-tidio-project option:selected').data('value'); 201 $.extend(details, { 202 'action': 'set_project_keys', 203 'api_token': TidioChatWP.token, 204 '_wpnonce': nonce, 205 }); 206 176 207 $.post(ajaxurl, details, (function (response) { 177 window.open(response, '_blank'); 178 TidioChatWP.setRedirectLink(response); 208 var url = this.addEmailToRedirectLink(response); 209 window.open(url, '_blank'); 210 TidioChatWP.setRedirectLink(url); 179 211 this.form.fadeOut('fast', function () { 180 212 $('#after-install-text').fadeIn('fast'); … … 281 313 document.addEventListener('click', closeAllSelect); 282 314 }, 283 accessT roughtXHR: function (_func) {315 accessThroughXHR: function (_func) { 284 316 285 317 var xhr_url = TidioChatWP.apiUrl + '/access/external/create?url=' + … … 294 326 r.value.private_key + 295 327 '&app=chat&utm_source=platform&utm_medium=wordpress'); 328 296 329 // save this in wordpress database 297 330 $.post(ajaxurl, { … … 299 332 'public_key': r.value.public_key, 300 333 'private_key': r.value.private_key, 301 }, function (response) { 302 303 }); 304 334 '_wpnonce': nonce, 335 }); 305 336 }).fail(function () { 306 337 alert('Error occured while creating, please try again!'); -
tidio-live-chat/trunk/options.php
r2179244 r2186087 1 <script> 2 var nonce = '<?php echo wp_create_nonce(TidioLiveChat::TIDIO_XHR_NONCE_NAME); ?>'; 3 </script> 1 4 <div id="tidio-wrapper"> 2 5 <div class="tidio-box-wrapper"> -
tidio-live-chat/trunk/readme.txt
r2179244 r2186087 4 4 Requires at least: 3.0 5 5 Tested up to: 5.2 6 Stable tag: 4. 1.06 Stable tag: 4.2.0 7 7 License: GPLv2 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 122 122 == Changelog == 123 123 124 = 4.2.0 = 125 * Update menu icon 126 * Use email from plugin form as default email for a Tidio account 127 * Improve error handling 128 * Use nonce system 129 124 130 = 4.1.0 = 125 131 * Simplify login flow for users with only one project -
tidio-live-chat/trunk/tidio-elements.php
r2179244 r2186087 3 3 /** 4 4 * Plugin Name: Tidio Chat 5 * Plugin URI: http://www.tidio chat.com6 * Description: Tidio Live Chat - Live chat for your website. No logging in, no signing up - integrates with your website in less than 20 seconds.7 * Version: 4. 1.05 * Plugin URI: http://www.tidio.com 6 * Description: Tidio Live Chat - live chat boosted with chatbots for your online business. Integrates with your website in less than 20 seconds. 7 * Version: 4.2.0 8 8 * Author: Tidio Ltd. 9 * Author URI: http://www.tidio chat.com9 * Author URI: http://www.tidio.com 10 10 * License: GPL2 11 11 */ 12 define('TIDIOCHAT_VERSION', '4. 1.0');12 define('TIDIOCHAT_VERSION', '4.2.0'); 13 13 define('AFFILIATE_CONFIG_FILE_PATH', get_template_directory().'/tidio_affiliate_ref_id.txt'); 14 14 … … 24 24 const TIDIO_PLUGIN_NAME = 'tidio-live-chat'; 25 25 const TOGGLE_ASYNC_ACTION = 'tidio-chat-toggle-async'; 26 const TIDIO_ICON_BASE64 = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIzLjEuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IldhcnN0d2FfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiCgkgdmlld0JveD0iMCAwIDIwIDIwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyMCAyMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNBMEE1QUE7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMiwxOHYtNS45YzAtMi43LDEuNy01LDQuMy01LjdDNy4xLDMuNyw5LjQsMiwxMi4xLDJDMTUuNCwyLDE4LDQuNiwxOCw3Ljl2NS45aC00LjVsMCwwLjEKCWMtMC44LDIuNS0zLDQuMS01LjYsNC4xSDJ6IE02LjEsOC4xTDYuMSw4LjFjLTEuNiwwLjctMi42LDIuMy0yLjYsNC4xdjQuNGg0LjRjMS44LDAsMy4zLTEsNC4xLTIuNmwwLTAuMWwtMC4xLDAKCWMtMy4xLTAuMi01LjYtMi43LTUuNy01LjZsMC0wLjFMNi4xLDguMXogTTEyLjEsMy41Yy0xLjgsMC0zLjMsMS00LjEsMi42bDAsMC4xbDAuMSwwYzMuMiwwLjEsNS43LDIuNyw1LjcsNS45djAuMWwwLjEsMC4xaDIuN1Y3LjkKCUMxNi41LDUuNSwxNC41LDMuNSwxMi4xLDMuNXogTTcuNiw3LjhMNy42LDcuOGMwLDIuNSwyLDQuNSw0LjQsNC41aDAuMWwwLjEtMC4xYzAtMi41LTItNC41LTQuNC00LjVINy43TDcuNiw3Ljh6Ii8+Cjwvc3ZnPgo='; 27 const TIDIO_XHR_NONCE_NAME = 'tidio-xhr-nonce'; 26 28 27 29 public function __construct() … … 70 72 public static function ajaxGetPrivateKey() 71 73 { 74 check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME); 75 72 76 $privateKey = TidioLiveChat::getPrivateKey(); 73 77 if (!$privateKey || $privateKey == 'false') { … … 183 187 'privateKey' => $privateKey, 184 188 'utm_source' => 'platform', 185 'utm_medium' => 'wordpress', 186 'tour_default_email' => get_option('admin_email'), 189 'utm_medium' => 'wordpress' 187 190 ) 188 191 ); … … 193 196 if (strpos($file, basename(__FILE__)) !== false) { 194 197 if (get_option(TidioLiveChat::PRIVATE_KEY_OPTION)) { 195 $links[] = '<a href="' . admin_url('admin-post.php') . '?action=' . TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION . '">' . esc_html__('Clear Account Data', 198 $queryString = http_build_query( 199 array( 200 'action' => TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION, 201 '_wpnonce' => wp_create_nonce(TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION), 202 ) 203 ); 204 $links[] = '<a href="' . admin_url('admin-post.php') . '?' . $queryString . '">' . esc_html__('Clear Account Data', 196 205 TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>'; 206 197 207 if (get_option(TidioLiveChat::ASYNC_LOAD_OPTION)) { 198 208 $toggleAsyncLabel = '✓'; … … 202 212 $onclickPart = ''; 203 213 } 204 $links[] = '<a href="' . admin_url('admin-post.php') . '?action=' . TidioLiveChat::TOGGLE_ASYNC_ACTION . '" ' . $onclickPart . '>' . esc_html__($toggleAsyncLabel . ' Asynchronous loading', 214 $queryString = http_build_query( 215 array( 216 'action' => TidioLiveChat::TOGGLE_ASYNC_ACTION, 217 '_wpnonce' => wp_create_nonce(TidioLiveChat::TOGGLE_ASYNC_ACTION), 218 ) 219 ); 220 $links[] = '<a href="' . admin_url('admin-post.php') . '?' . $queryString . '" ' . $onclickPart . '>' . esc_html__($toggleAsyncLabel . ' Asynchronous loading', 205 221 TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>'; 206 222 } … … 212 228 public function toggleAsync() 213 229 { 230 if (wp_verify_nonce($_GET['_wpnonce'], TidioLiveChat::TOGGLE_ASYNC_ACTION) === false) { 231 wp_die('', 403); 232 } 233 214 234 update_option(TidioLiveChat::ASYNC_LOAD_OPTION, !get_option(TidioLiveChat::ASYNC_LOAD_OPTION)); 215 235 wp_redirect(admin_url('plugins.php')); … … 219 239 public function ajaxSetProjectKeys() 220 240 { 241 check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME); 242 221 243 update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $_POST['public_key']); 222 244 update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $_POST['private_key']); … … 241 263 exit; 242 264 } 265 266 check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME); 243 267 244 268 if (empty($_POST['private_key']) || empty($_POST['public_key'])) { … … 326 350 { 327 351 add_menu_page( 328 'Tidio Chat', 'Tidio Chat', 'manage_options', 'tidio-chat', array($this, 'addAdminPage'), 329 content_url() . '/plugins/' . TidioLiveChat::TIDIO_PLUGIN_NAME . '/media/img/icon.png' 352 'Tidio Chat', 353 'Tidio Chat', 354 'manage_options', 355 'tidio-chat', 356 array($this, 'addAdminPage'), 357 'data:image/svg+xml;base64,' . self::TIDIO_ICON_BASE64 330 358 ); 331 359 } … … 340 368 public function uninstall() 341 369 { 370 if (wp_verify_nonce($_GET['_wpnonce'], TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION) === false) { 371 wp_die('', 403); 372 } 373 342 374 delete_option(TidioLiveChat::PUBLIC_KEY_OPTION); 343 375 delete_option(TidioLiveChat::PRIVATE_KEY_OPTION);
Note: See TracChangeset
for help on using the changeset viewer.