Plugin Directory

Changeset 2765186


Ignore:
Timestamp:
08/02/2022 12:35:15 PM (4 years ago)
Author:
vinema
Message:

Avoid multiple organizations accounts to login

Location:
vine-ma/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • vine-ma/trunk/readme.txt

    r2745809 r2765186  
    2121
    2222== Changelog ==
     23
     24= 1.1.6 =
     25* Avoid multiple organizations accounts to login.
    2326
    2427= 1.1.5 =
  • vine-ma/trunk/vine_ma_plugin.php

    r2745809 r2765186  
    33/**
    44 * Plugin Name: Vine MA - Email Marketing, Forms, Interactive Bot Forms, Chatbot, Analytics
    5  * Version: 1.1.5
     5 * Version: 1.1.6
    66 * Description: Vine is a Marketing automation tool to generate more leads from your web site. Vine includes web forms, interactive bot forms, landing pages, AI chatbot, visitor tracking, and other functionality to help you to make your site more interesting and to know better what your visitors do there.
    77 * Author: Vine Oy
     
    7272        echo "<p>You need Vine account to use this plugin. If you do not have one, you can register trial account in <a target='_blank' href='https://vine.eu/en/try-for-free'>https://vine.eu/en/try-for-free</a></p>";
    7373        echo "<p><a id='vinemaloginbtn' href='javascript:openMaLoginWindow();'>Login to MA</a></p>";
     74        echo "<p><b>Please do not use partner account which can be moved between different customers.</b></p>";
    7475    }
    7576}
     
    248249}
    249250
     251function vine_ma_admin_notice_multiorg_status()
     252{
     253    $vineLogo = <<<EOD
     254        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="9" viewBox='0 0 134 34' style="margin-right: 10px">
     255            <path fill='white' d='M 0.00 0.00 L 134.00 0.00 L 134.00 34.00 L 0.00 34.00 L 0.00 0.00 Z'/>
     256                <path fill='rgb(213,40,60)' d='M 42.07 0.99 C 46.17 2.04 50.16 3.47 54.14 4.88 C 54.13 13.39 54.19 21.90 54.10 30.40 C 51.01 30.52 47.91 30.61 44.82 30.64 C 44.64 23.83 44.84 17.02 44.66 10.22 C 43.13 9.76 41.60 9.29 40.08 8.79 C 40.68 6.17 41.33 3.57 42.07 0.99 Z'/>
     257                <path fill='rgb(213,40,60)' d='M 65.58 3.73 C 68.38 2.67 71.23 1.71 74.15 0.97 C 74.16 3.70 74.14 6.42 74.11 9.14 C 77.06 5.39 80.50 0.41 85.97 1.10 C 90.27 0.65 93.94 4.82 93.79 8.95 C 93.85 16.18 93.81 23.41 93.77 30.64 C 90.88 30.65 87.99 30.66 85.10 30.67 C 84.85 23.81 86.35 16.75 84.14 10.08 C 82.51 11.08 80.77 12.10 79.84 13.84 C 76.78 18.93 75.53 24.83 74.30 30.57 C 71.38 30.67 68.45 30.66 65.52 30.60 C 65.49 21.64 65.39 12.69 65.58 3.73 Z'/>
     258                <path fill='rgb(213,40,60)' d='M 107.37 6.40 C 112.93 -1.95 127.19 -0.22 131.70 8.36 C 133.11 10.69 133.02 13.49 133.28 16.11 C 127.17 18.05 120.86 19.33 114.77 21.37 C 116.45 22.64 118.11 24.22 120.29 24.48 C 123.20 24.86 125.96 23.67 128.73 23.01 C 128.77 25.78 128.76 28.56 128.64 31.33 C 123.48 32.33 117.89 33.23 112.88 31.10 C 108.20 29.06 105.38 24.01 105.22 19.02 C 105.04 14.77 104.78 10.05 107.37 6.40 Z'/>
     259                <path fill='rgb(213,40,60)' d='M 23.37 2.15 C 26.50 1.67 29.67 1.62 32.82 1.77 C 28.11 12.02 23.80 22.46 19.44 32.87 C 18.13 32.84 16.70 33.47 15.47 32.82 C 13.14 29.91 11.67 26.45 9.69 23.31 C 6.84 18.21 3.24 13.54 0.79 8.21 C 3.13 6.36 5.58 4.64 8.15 3.12 C 11.98 7.42 14.30 12.75 17.39 17.56 C 19.90 12.64 21.44 7.30 23.37 2.15 Z'/>
     260                <path fill='white' d='M 113.50 12.98 C 114.55 11.46 115.41 9.58 117.22 8.81 C 119.50 7.95 121.51 9.73 123.36 10.80 C 120.15 11.83 116.86 12.64 113.50 12.98 Z'/>
     261        </svg>
     262EOD;
     263   
     264    $ismultiorg = vine_ma_get_multiorg_status();
     265   
     266    if( $ismultiorg == true)
     267    {
     268        ?>
     269        <div class="notice notice-warning is-dismissible">
     270            <p>
     271                <?php echo $vineLogo ?>
     272                <?php _e('Warning! The account used should be account which cannot access multiple organizations. Please relogin with proper account.', 'textdomain') ?>
     273            </p>
     274        </div>
     275        <?php
     276    }
     277}
     278
    250279//subscribe to admin notices event
    251280add_action( 'admin_notices', 'vine_ma_admin_notice' );
     281add_action( 'admin_notices', 'vine_ma_admin_notice_multiorg_status' );
    252282
    253283//register vine web form block hook
     
    350380    }
    351381}
     382
     383//check account multiorg status
     384function vine_ma_get_multiorg_status() {
     385    $cache = get_option( 'vine-plugin-account-multiorgstatus-cache' );
     386    if(is_array( $cache ) && $cache['timestamp'] != null && (time() - $cache['timestamp']) < 120)
     387    {
     388        return $cache['multiorgstatus'];
     389    }
     390    $errorMessage = 'An error occurred while communicating with Vine MA. Please try to refresh page.';
     391    $apikey = vine_ma_get_option('apikey');
     392    if( $apikey != null) {
     393      $tokendata = vine_ma_get_authtoken($apikey);
     394      $token = $tokendata['token'];
     395      $error = $tokendata['error'];
     396      if( $token == null )
     397          return false;
     398    } else {
     399        return false;
     400    }
     401    $url=VINEHOST."/api/rest/2.0/VY_USERGROUP([STATUS]='B' and [GROUPROLE] in ('SWITCHORGANIZATION','SWITCHTOANYORG'))?\$authtoken={$token}";
     402    $args = array(
     403      'timeout' => 20,
     404      'user-agent'  =>  ''
     405    );
     406    $html = wp_remote_get($url,$args);
     407    $returncode = wp_remote_retrieve_response_code($html);
     408    if ( $returncode === 200 || $returncode === 304 ) {
     409        $body = wp_remote_retrieve_body($html);
     410        $xml = new SimpleXMLElement($body);
     411        $status = $xml->xpath('//m:count')[0] == 0 ? false : true;
     412        $timestamp = time();
     413        update_option( 'vine-plugin-account-multiorgstatus-cache', array(
     414            'multiorgstatus' => $status,
     415            'timestamp' => $timestamp
     416        ));
     417        return $status;
     418    }
     419    else {
     420        return false;
     421    }
     422}
Note: See TracChangeset for help on using the changeset viewer.