Plugin Directory

Changeset 2186087


Ignore:
Timestamp:
11/05/2019 11:34:47 AM (5 years ago)
Author:
lucastidio
Message:

Update menu icon; Use email from plugin form as default email for a Tidio account; Improve error handling; Use nonce system

Location:
tidio-live-chat/trunk
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • tidio-live-chat/trunk/media/js/options.js

    r2179244 r2186087  
    33    var TidioChatWP = {
    44        apiUrl: 'https://api-v2.tidio.co',
    5         chatUrl: 'https://www.tidiochat.com',
     5        chatUrl: 'https://www.tidio.com',
    66        token: null,
     7        email: '',
    78        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            }
    826            this.error = $('.error');
    9 
    1027            this.form = $('#tidio-start');
    1128            this.form.show();
     
    2643            }
    2744            this.hideError();
    28 
     45            this.email = emailField.val();
    2946            submitButton.prop('disabled', true).text('Loading...');
    3047
     
    3552                    data.value.registered === true) {
    3653                    this.form.hide();
    37                     submitButton.prop('disabled', false).
    38                         text('Start using Tidio');
     54                    submitButton.prop('disabled', false).text('Start using Tidio');
    3955                    this.showLoginForm(emailField.val());
    4056                } else {
    4157                    this.redirectToPanel();
    4258                }
    43             }.bind(this)).fail((function() {
     59            }.bind(this)).fail((function(error) {
    4460                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
    4667            }).bind(this));
    4768            return false;
     
    100121            return false;
    101122        },
     123        addEmailToRedirectLink: function(url) {
     124            return url + '&tour_default_email=' + encodeURIComponent(this.email);
     125        },
    102126        redirectToPanel: function () {
    103             var form = this.form;
    104127            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 () {
    108132                    $('#after-install-text').fadeIn('fast');
    109133                });
    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                },
    113140                function (response) {
    114141                    if (response === 'error') {
    115                         // load trought ajax url
    116                         TidioChatWP.accessTroughtXHR(redirect);
     142                        // load through ajax url
     143                        TidioChatWP.accessThroughXHR(redirect);
    117144                        return false;
    118145                    }
     
    171198        },
    172199        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
    176207            $.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);
    179211                this.form.fadeOut('fast', function () {
    180212                    $('#after-install-text').fadeIn('fast');
     
    281313            document.addEventListener('click', closeAllSelect);
    282314        },
    283         accessTroughtXHR: function (_func) {
     315        accessThroughXHR: function (_func) {
    284316
    285317            var xhr_url = TidioChatWP.apiUrl + '/access/external/create?url=' +
     
    294326                    r.value.private_key +
    295327                    '&app=chat&utm_source=platform&utm_medium=wordpress');
     328
    296329                // save this in wordpress database
    297330                $.post(ajaxurl, {
     
    299332                    'public_key': r.value.public_key,
    300333                    'private_key': r.value.private_key,
    301                 }, function (response) {
    302 
    303                 });
    304 
     334                    '_wpnonce': nonce,
     335                });
    305336            }).fail(function () {
    306337                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>
    14<div id="tidio-wrapper">
    25    <div class="tidio-box-wrapper">
  • tidio-live-chat/trunk/readme.txt

    r2179244 r2186087  
    44Requires at least: 3.0
    55Tested up to: 5.2
    6 Stable tag: 4.1.0
     6Stable tag: 4.2.0
    77License: GPLv2
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    122122== Changelog ==
    123123
     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
    124130= 4.1.0 =
    125131* Simplify login flow for users with only one project
  • tidio-live-chat/trunk/tidio-elements.php

    r2179244 r2186087  
    33/**
    44 * Plugin Name: Tidio Chat
    5  * Plugin URI: http://www.tidiochat.com
    6  * 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.0
     5 * 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
    88 * Author: Tidio Ltd.
    9  * Author URI: http://www.tidiochat.com
     9 * Author URI: http://www.tidio.com
    1010 * License: GPL2
    1111 */
    12 define('TIDIOCHAT_VERSION', '4.1.0');
     12define('TIDIOCHAT_VERSION', '4.2.0');
    1313define('AFFILIATE_CONFIG_FILE_PATH', get_template_directory().'/tidio_affiliate_ref_id.txt');
    1414
     
    2424    const TIDIO_PLUGIN_NAME = 'tidio-live-chat';
    2525    const TOGGLE_ASYNC_ACTION = 'tidio-chat-toggle-async';
     26    const TIDIO_ICON_BASE64 = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIzLjEuMSwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IldhcnN0d2FfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiCgkgdmlld0JveD0iMCAwIDIwIDIwIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAyMCAyMDsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8c3R5bGUgdHlwZT0idGV4dC9jc3MiPgoJLnN0MHtmaWxsOiNBMEE1QUE7fQo8L3N0eWxlPgo8cGF0aCBjbGFzcz0ic3QwIiBkPSJNMiwxOHYtNS45YzAtMi43LDEuNy01LDQuMy01LjdDNy4xLDMuNyw5LjQsMiwxMi4xLDJDMTUuNCwyLDE4LDQuNiwxOCw3Ljl2NS45aC00LjVsMCwwLjEKCWMtMC44LDIuNS0zLDQuMS01LjYsNC4xSDJ6IE02LjEsOC4xTDYuMSw4LjFjLTEuNiwwLjctMi42LDIuMy0yLjYsNC4xdjQuNGg0LjRjMS44LDAsMy4zLTEsNC4xLTIuNmwwLTAuMWwtMC4xLDAKCWMtMy4xLTAuMi01LjYtMi43LTUuNy01LjZsMC0wLjFMNi4xLDguMXogTTEyLjEsMy41Yy0xLjgsMC0zLjMsMS00LjEsMi42bDAsMC4xbDAuMSwwYzMuMiwwLjEsNS43LDIuNyw1LjcsNS45djAuMWwwLjEsMC4xaDIuN1Y3LjkKCUMxNi41LDUuNSwxNC41LDMuNSwxMi4xLDMuNXogTTcuNiw3LjhMNy42LDcuOGMwLDIuNSwyLDQuNSw0LjQsNC41aDAuMWwwLjEtMC4xYzAtMi41LTItNC41LTQuNC00LjVINy43TDcuNiw3Ljh6Ii8+Cjwvc3ZnPgo=';
     27    const TIDIO_XHR_NONCE_NAME = 'tidio-xhr-nonce';
    2628
    2729    public function __construct()
     
    7072    public static function ajaxGetPrivateKey()
    7173    {
     74        check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME);
     75
    7276        $privateKey = TidioLiveChat::getPrivateKey();
    7377        if (!$privateKey || $privateKey == 'false') {
     
    183187                    'privateKey' => $privateKey,
    184188                    'utm_source' => 'platform',
    185                     'utm_medium' => 'wordpress',
    186                     'tour_default_email' => get_option('admin_email'),
     189                    'utm_medium' => 'wordpress'
    187190                )
    188191            );
     
    193196        if (strpos($file, basename(__FILE__)) !== false) {
    194197            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',
    196205                        TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>';
     206
    197207                if (get_option(TidioLiveChat::ASYNC_LOAD_OPTION)) {
    198208                    $toggleAsyncLabel = '✓';
     
    202212                    $onclickPart = '';
    203213                }
    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',
    205221                        TidioLiveChat::TIDIO_PLUGIN_NAME) . '</a>';
    206222            }
     
    212228    public function toggleAsync()
    213229    {
     230        if (wp_verify_nonce($_GET['_wpnonce'], TidioLiveChat::TOGGLE_ASYNC_ACTION) === false) {
     231            wp_die('', 403);
     232        }
     233
    214234        update_option(TidioLiveChat::ASYNC_LOAD_OPTION, !get_option(TidioLiveChat::ASYNC_LOAD_OPTION));
    215235        wp_redirect(admin_url('plugins.php'));
     
    219239    public function ajaxSetProjectKeys()
    220240    {
     241        check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME);
     242
    221243        update_option(TidioLiveChat::PUBLIC_KEY_OPTION, $_POST['public_key']);
    222244        update_option(TidioLiveChat::PRIVATE_KEY_OPTION, $_POST['private_key']);
     
    241263            exit;
    242264        }
     265
     266        check_ajax_referer(TidioLiveChat::TIDIO_XHR_NONCE_NAME);
    243267
    244268        if (empty($_POST['private_key']) || empty($_POST['public_key'])) {
     
    326350    {
    327351        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
    330358        );
    331359    }
     
    340368    public function uninstall()
    341369    {
     370        if (wp_verify_nonce($_GET['_wpnonce'], TidioLiveChat::CLEAR_ACCOUNT_DATA_ACTION) === false) {
     371            wp_die('', 403);
     372        }
     373
    342374        delete_option(TidioLiveChat::PUBLIC_KEY_OPTION);
    343375        delete_option(TidioLiveChat::PRIVATE_KEY_OPTION);
Note: See TracChangeset for help on using the changeset viewer.