Plugin Directory

Changeset 2001693


Ignore:
Timestamp:
12/26/2018 01:11:11 PM (7 years ago)
Author:
heremobilitydemand
Message:

Fixed auth cache bug

Location:
here-mobility/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • here-mobility/trunk/heremobility.php

    r2001637 r2001693  
    6464        $options = get_option(HereMobility_Settings::HERE_OPTIONS);
    6565
     66        if (!isset($_POST['application_key'])) {
     67            wp_die();
     68        }
     69
     70        if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {
     71            $current_user = wp_get_current_user();
     72            $user = $current_user->user_email;
     73        } else {
     74            $user = $this->generateRandomUser();
     75        }
     76
    6677        if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION])
    6778            && $_POST['application_key'] == $options[HereMobility_Settings::APP_KEY_OPTION]) {
     
    7081            $appSecret = $options[HereMobility_Settings::APP_SECRET_OPTION];
    7182
    72             if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {
    73                 $current_user = wp_get_current_user();
    74                 $user = $current_user->user_email;
    75             } else {
    76                 $user = $this->generateRandomUser();
    77             }
    78 
    7983            $authData = $this->get_auth_data($appKey, $appSecret, $user);
    8084            echo json_encode($authData);
     85        } elseif (!empty($_POST['post_id'])  && !empty($_POST['application_key']) && $content_post = get_post($_POST['post_id'])){
     86            $content = htmlspecialchars_decode($content_post->post_content);
     87
     88            preg_match('/appSecret="([^"]+)"/i', $content, $matchesTinyMce);
     89            preg_match('/"appSecret":"([^"]+)"/i', $content, $matchesGutenBerg);
     90
     91            $appSecret = isset($matchesTinyMce[1]) ? $matchesTinyMce[1] : (isset($matchesGutenBerg[1]) ? $matchesGutenBerg[1] : null);
     92
     93            if ($appSecret) {
     94                $authData = $this->get_auth_data($_POST['application_key'], $appSecret, $user);
     95                echo json_encode($authData);
     96            }
    8197        }
    8298
     
    157173    {
    158174        // Attributes
    159         $attrs = shortcode_atts(
     175        $attrs = array_merge(
    160176            array(
    161177                'pickup' => '',
    162178                'destination' => '',
    163179                'id' => '',
    164                 'appKey' => '',
    165                 'appSecret' => ''
     180                'appkey' => '',
     181                'appsecret' => ''
    166182            ),
    167             $attrs
     183            array_change_key_case($attrs, CASE_LOWER)
    168184        );
    169185
     
    175191
    176192        if (($options[HereMobility_Settings::APP_KEY_OPTION] && $options[HereMobility_Settings::APP_SECRET_OPTION])
    177             || ($attrs['appKey'] && $attrs['appSecret'])) {
     193            || ($attrs['appkey'] && $attrs['appsecret'])) {
    178194            $options = get_option(HereMobility_Settings::HERE_OPTIONS);
    179             $appKey = $attrs['appKey'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];
    180             $appSecret = $attrs['appSecret'] ?: $options[HereMobility_Settings::APP_SECRET_OPTION];
     195            $appKey = $attrs['appkey'] ?: $options[HereMobility_Settings::APP_KEY_OPTION];
     196            $appSecret = $attrs['appsecret'] ?: $options[HereMobility_Settings::APP_SECRET_OPTION];
    181197
    182198            if ($options[HereMobility_Settings::USE_CURRENT_WP_USER] && is_user_logged_in()) {
     
    196212                'authData' => $this->get_auth_data($appKey, $appSecret, $user),
    197213                'auth_ajax_url' => admin_url('admin-ajax.php'),
    198                 'auth_ajax_action' => self::GET_AUTH_ACTION
     214                'auth_ajax_action' => self::GET_AUTH_ACTION,
     215                'post_id' => get_the_ID()
    199216            ]);
    200217            return "<div class='wordpress-hmw' id='" . $attrs['id'] . "'></div><div id='table-booking-date'></div>";
     
    211228    function get_auth_data($appKey, $appSecret, $user)
    212229    {
    213         $expiration = time() + 2 * 60 * 60;
     230        $expiration = time() + 60 * 60;
    214231
    215232        $hash = hash_hmac(
     
    359376
    360377new HereMobility();
    361 
  • here-mobility/trunk/js/loader.js

    r2001637 r2001693  
    2424});
    2525
    26 var d = new Date(Date.now() + 24 * 60 * 60 * 1000); // tomorrow
    27 hmw({
    28     eventTime: d.getTime(),
    29     pickup: hereLoaderData.pickup,
    30     destination: hereLoaderData.destination,
    31     // timezone: 'Europe/Paris',
    32     locale: hereLoaderData.locale || 'en-US',
    33   auth: hereLoaderData.authData,
    34 });
    35 
    3626setTimeout(function () {
    3727    jQuery(document).ready(function(_) {
    3828
    39         if ((Date.now()/1000 - hereLoaderData.authData.expiration) > 0) {
    40             var postData = {
    41                 'action': hereLoaderData.auth_ajax_action,
    42                 'application_key': hereLoaderData.authData.application_key
    43             };
     29        var postData = {
     30            'action': hereLoaderData.auth_ajax_action,
     31            'application_key': hereLoaderData.appKey,
     32            'post_id': hereLoaderData.post_id
     33        };
    4434
    45             jQuery.post(hereLoaderData.auth_ajax_url, postData, function(response) {
    46                 if (response) {
    47                     hmw({
    48                         auth: JSON.parse(response)
    49                     });
    50                 }
    51             });
    52         }
     35        jQuery.post(hereLoaderData.auth_ajax_url, postData, function(response) {
     36            if (response) {
    5337
     38                var d = new Date(Date.now() + 24 * 60 * 60 * 1000); // tomorrow
     39                hmw({
     40                    eventTime: d.getTime(),
     41                    pickup: hereLoaderData.pickup,
     42                    destination: hereLoaderData.destination,
     43                    locale: hereLoaderData.locale || 'en-US',
     44                    auth: JSON.parse(response)
     45                });
     46            }
     47        });
    5448    });
    5549}, 0);
  • here-mobility/trunk/readme.txt

    r2001109 r2001693  
    7474== Changelog ==
    7575
     76= 1.0.5 =
     77* Fixed cache bug
     78
    7679= 1.0.3 =
    7780* Added support of gutenberg text editor
Note: See TracChangeset for help on using the changeset viewer.