Example #1
0
 public function obtainToken($callback)
 {
     $r = null;
     if ($this->input->get('oauth_verifier') === null) {
         $c = $this->_lib->request('POST', $this->_lib->url('oauth/request_token', ''), array('oauth_callback' => $callback, 'x_auth_access_type' => 'write'));
         if ($c == 200) {
             $r = $this->_lib->extract_params($this->_lib->response['response']);
             if ($r['oauth_callback_confirmed'] == true) {
                 $this->input->set_session('request_token', $r);
                 Url::redirect($this->_lib->url('oauth/authenticate', '') . '?oauth_token=' . $r['oauth_token']);
             }
         } else {
             throw new \Exception($this->_lib->response['response'], $c);
         }
     } else {
         if (!($r = $this->input->session('request_token'))) {
             return null;
         }
         $this->input->unset_session('request_token');
         $this->_lib->reconfigure(array('token' => $r['oauth_token'], 'secret' => $r['oauth_token_secret']));
         $c = $this->_lib->request('POST', $this->_lib->url('oauth/access_token', ''), array('oauth_verifier' => $this->input->get('oauth_verifier')));
         if ($c == 200) {
             $r = $this->_lib->extract_params($this->_lib->response['response']);
         }
     }
     return $r;
 }
Example #2
0
 public static function once($type, $message, $redirect = null)
 {
     Controller::instance()->input->set_session('alert_once', array('type' => $type, 'message' => htmlspecialchars($message)));
     if ($redirect) {
         Url::redirect($redirect);
     }
 }
Example #3
0
 protected function _channel_influencer()
 {
     try {
         $id = $this->input->post('id');
         $campaign = new Campaign($id);
         $cinfo = $campaign->get();
         if (!$cinfo) {
             throw new \Exception('Invalid campaign');
         }
         if (!($influencer = $this->input->post('influencer'))) {
             throw new \Exception('Invalid influencer');
         }
         $comment = $this->input->post('comment');
         if (empty($comment)) {
             throw new \Exception('Comment must not be empty');
         }
         $comments = MongoDoc::get($cinfo, 'comments.brand_influencer', array());
         if (!isset($comments[$influencer])) {
             $comments[$influencer] = array();
         }
         $comments[$influencer][] = array('from' => UserSession::get('user._id'), 'from_username' => UserSession::get('user.username'), 'user' => 'brand', 'created_at' => time(), 'text' => $comment);
         $comments[$influencer] = array_slice($comments[$influencer], -20);
         $campaign->update(array('comments.brand_influencer' => $comments));
         Alert::once('success', 'Comment added', Url::referrer());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Example #4
0
 protected function _finish()
 {
     $id = $this->input->post('id');
     try {
         $selected = array();
         if ($s = $this->input->post('selected_influencers')) {
             $selected = explode(',', $s);
         }
         if (!$selected) {
             throw new \Exception('At least one influencer must be selected');
         }
         foreach ($selected as &$s) {
             $s = new \MongoId($s);
         }
         $campaign = new Campaign($id);
         $cinfo = $campaign->filter_one(array('_id' => $campaign->id, 'state' => array('$in' => array('pending', 'rejected'))));
         if (!$cinfo) {
             throw new \Exception('Invalid Campaign');
         }
         $campaign->update(array('state' => 'active', 'influencers_select' => $selected, 'points' => (int) $this->input->post('points'), 'global' => (bool) $this->input->post('global')));
         Alert::once('success', 'Campaign is now active', Url::base('admin/campaign/view/' . $id));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::base('admin/campaign/view/' . $id));
     }
 }
Example #5
0
 public function obtainToken($callback)
 {
     $helper = new FacebookRedirectLoginHelper($callback);
     if ($this->input->get('code') === null) {
         /**
          * Required permissions
          * public_profile
          * email
          * read_insights		Show analytics data of page in dashboard
          * read_page_mailboxes	Manage page conversations
          * read_mailbox			Manage page mailbox
          * manage_pages			Manage brand pages
          * publish_pages		Take actions on behalf of page
          */
         $loginUrl = $helper->getLoginUrl(array('public_profile', 'user_friends', 'email', 'read_mailbox', 'read_page_mailboxes', 'manage_pages', 'publish_actions', 'publish_pages', 'read_insights'));
         Url::redirect($loginUrl);
         return null;
     } else {
         $session = null;
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
         if ($session) {
             // Logged in
         }
         return $session;
     }
 }
Example #6
0
 public function post()
 {
     try {
         (new NotifyBrandCampaign())->create($id);
         Alert::once('success', 'Campaign queued for admin approval', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
 public function invalidate($id, $account)
 {
     $user = new User($id);
     $uinfo = $user->get();
     $user->modify(array('_id' => $user->id), array('$addToSet' => array('social_invalidated' => $account)));
     $recipients = array($id);
     $this->add(array('sender' => $id, 'recipients' => $recipients, 'text' => $this->_body($this->_prefix . __FUNCTION__ . '.php', array('social' => $this->_social_account($account))), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('influencer/social')));
     $this->mail_enqueue(array('to' => $uinfo['email'], 'from' => $this->_from_email, 'subject' => 'Social Account Invalidated', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'social' => $this->_social_account($account)))));
 }
 /**
  * @return string
  */
 public function actionLogin($username)
 {
     /* @var $user User */
     $user = User::findByUsername($username);
     Yii::$app->user->login($user, 0);
     if (Yii::$app->user->can('AdmRoot') || Yii::$app->user->can('AdmAdmin')) {
         return $this->redirect(['/adm/user/update']);
     }
     return $this->redirect(Url::getLangUrl());
 }
Example #9
0
 protected function _check_login()
 {
     if (!UserSession::get('user')) {
         if ($this->input->is_ajax_request()) {
             Json::success('Session has been invalidated. Redirecting to login page...', Url::base('auth/login'));
         } else {
             Url::redirect('auth/login');
         }
     }
     return true;
 }
Example #10
0
 protected function _remove()
 {
     try {
         if (!($id = $this->input->post('id'))) {
             Alert::once('success', 'Invalid ID!', Url::current());
         }
         $user = new PartnerModel($id);
         $user->remove();
         Alert::once('success', 'Account removed successfully!', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Example #11
0
 public function post()
 {
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->find_modify_one(array('_id' => new \MongoId($this->input->post('id')), 'state' => array('$in' => array('pending', 'active'))), array('$set' => array('state' => 'rejected')));
         if (!$cinfo) {
             $this->_403();
         }
         Alert::once('success', 'Campaign has been removed', Url::base('admin/campaign/pending'));
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::referrer());
     }
 }
Example #12
0
 public function post()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $binfo = $brand->get();
         $data = $this->_get_data($binfo);
         $campaign = new Campaign(null);
         $id = $campaign->create($data);
         (new NotifyBrandCampaign())->create($id);
         Alert::once('success', 'Campaign queued for admin approval', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Example #13
0
 protected function _remove()
 {
     try {
         $influencer = new Influencer(UserSession::get('user._id'));
         $iinfo = $influencer->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['instagram']);
             $influencer->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('influencer/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('influencer/social'));
 }
Example #14
0
 protected function _remove()
 {
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $iinfo = $brand->get();
         if ($social = MongoDoc::get($iinfo, 'social')) {
             unset($social['twitter']);
             $brand->update(array('social' => $social));
         }
     } catch (\Exception $e) {
         Alert::once('error', 'Failed to remove account: ' . $e->getMessage(), Url::base('brand/social'));
     }
     Alert::once('success', 'Account remove successfully', Url::base('brand/social'));
 }
Example #15
0
 public function obtainToken($callback)
 {
     $this->_lib->setApiCallback($callback);
     $r = null;
     if ($this->input->get('code') === null) {
         Url::redirect($this->_lib->getLoginUrl());
     } else {
         $r = json_decode(json_encode($this->_lib->getOAuthToken($this->input->get('code'))), true);
         if (isset($r['code']) && $r['code'] !== 200) {
             throw new InstagramAccessTokenException($r['error_type'] . ' - ' . $r['error_message']);
         }
         return $r;
     }
     return null;
 }
Example #16
0
 public function obtainToken($callback, $scope = array())
 {
     if ($scope) {
         $this->_client->setScopes($scope);
     }
     $this->_client->setRedirectUri($callback);
     $r = null;
     if ($this->input->get('code') === null) {
         Url::redirect($this->_client->createAuthUrl());
     } else {
         $this->_client->authenticate($this->input->get('code'));
         return json_decode($this->_client->getAccessToken(), true);
     }
     return null;
 }
Example #17
0
 protected function _remove()
 {
     try {
         if (!($id = $this->input->post('id'))) {
             Alert::once('success', 'Invalid ID!', Url::current());
         }
         $user = new BrandModel($id);
         $user->remove();
         $partner = new Partner(UserSession::get('user._id'));
         $partner->remove_brand($id);
         Alert::once('success', 'Brand removed successfully!', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
Example #18
0
 protected function _notify()
 {
     // Fix URLs b/w migrations & remove deleted users
     $notify = new Notify();
     foreach ($notify->all() as $n) {
         $u = null;
         $uinfo = (new \app\models\simple\User($n['sender']))->get();
         $u = $uinfo['type'];
         if ($u) {
             $notify->modify(array('_id' => $n['_id']), array('$set' => array('url' => Url::base($u))));
         } else {
             $notify->purge(array('_id' => $n['_id']));
         }
     }
 }
Example #19
0
 protected function _remove()
 {
     if (!UserSession::get('user.superadmin')) {
         $this->_403();
     }
     try {
         if (!($id = $this->input->post('id'))) {
             Alert::once('success', 'Invalid ID!', Url::current());
         }
         $user = new AdminModel($id);
         $user->remove();
         Alert::once('success', 'Account removed successfully!', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
 public function register($id, $password, $by = null)
 {
     $user = new User($id);
     $uinfo = $user->get();
     $uinfo['password'] = $password;
     $binfo = null;
     if ($by !== null) {
         $buser = new User($by);
         $binfo = $buser->get();
     } else {
         $by = $id;
         $binfo = $uinfo;
     }
     $recipients = array($id);
     $this->add(array('sender' => $by, 'recipients' => $recipients, 'text' => $this->_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo)), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('partner')));
     $this->mail_enqueue(array('to' => $uinfo['email'], 'from' => $this->_from_email, 'subject' => 'User Registered', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo))));
 }
Example #21
0
 public function get($state = null)
 {
     if (!$state) {
         Url::redirect('admin/campaign/pending');
     }
     $filter = array();
     if ($state != 'all') {
         $filter = array('state' => $state);
     }
     $campaigns = $this->_get_campaigns($filter)->sort(array('_id' => 1));
     $r = array();
     foreach ($campaigns as $c) {
         $brand = new Brand($c['brand']);
         $c['brand'] = $brand->filter_one(array('_id' => $c['brand']), array('_id' => true, 'username' => true));
         $r[] = $c;
     }
     $this->_display->view(array('main/app/admin/campaign/index.php'), array('campaigns' => $r));
 }
 public function create($id)
 {
     $campaign = new Campaign($id);
     $cinfo = $campaign->get();
     $buser = new User($cinfo['brand']);
     $binfo = $buser->get();
     $this->mail_enqueue(array('to' => $binfo['email'], 'from' => $this->_from_email, 'subject' => 'Campaign Created', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $binfo, 'campaign' => $cinfo))));
     // Send notification to admins
     $admin = new Admin(null);
     $emails = array();
     $recipients = array();
     foreach ($admin->filter(array()) as $doc) {
         $emails[$doc['email']] = true;
         $recipients[] = $doc['_id'];
     }
     $this->add(array('sender' => $binfo['_id'], 'recipients' => $recipients, 'text' => $this->_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('brand' => $binfo)), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('admin/campaign/view/' . $id)));
     $this->mail_enqueue(array('to' => array_keys($emails), 'from' => $this->_from_email, 'subject' => 'New Campaign Approval', 'message' => $this->_mail_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('brand' => $binfo, 'campaign' => $cinfo))));
 }
Example #23
0
 protected function _save_river($key)
 {
     try {
         $user = new Brand(UserSession::get('user._id'));
         $uinfo = $user->get();
         $auto = !!$this->input->post('auto');
         if ($auto) {
             if (($r = MongoDoc::get($uinfo, 'social_river.data_custom')) && isset($r[$key])) {
                 unset($r[$key]);
                 $user->update(array('social_river.data_custom' => (object) $r));
             }
         } else {
             if (($u = $this->input->post('url')) && !empty($u)) {
                 $user->update(array('social_river.data_custom.' . $key => trim($u)));
             }
         }
         Alert::once('success', 'URL updated successfully', Url::current());
     } catch (\Exception $e) {
         Alert::once('error', $e->getMessage(), Url::current());
     }
 }
 public function register($id, $password, $by = null)
 {
     $user = new User($id);
     $uinfo = $user->get();
     $uinfo['password'] = $password;
     $binfo = null;
     if ($by !== null) {
         $buser = new User($by);
         $binfo = $buser->get();
     } else {
         $by = $id;
         $binfo = $uinfo;
     }
     $recipients = array($id);
     $this->add(array('sender' => $by, 'recipients' => $recipients, 'text' => $this->_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo)), 'type' => $this->_prefix . __FUNCTION__, 'url' => Url::base('influencer')));
     $this->mail_enqueue(array('to' => $uinfo['email'], 'from' => $this->_from_email, 'subject' => 'User Registered', 'message' => $this->_mail_body($this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo))));
     // Send notification to admins
     $admin = new Admin(null);
     $emails = array();
     foreach ($admin->filter(array()) as $doc) {
         $emails[$doc['email']] = true;
     }
     $this->mail_enqueue(array('to' => array_keys($emails), 'from' => $this->_from_email, 'subject' => 'New Influencer Registration', 'message' => $this->_mail_body('admin.' . $this->_prefix . __FUNCTION__ . '.php', array('user' => $uinfo, 'by' => $binfo))));
 }
Example #25
0
 protected function _list_remove()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     try {
         $brand = new Brand(UserSession::get('user._id'));
         $binfo = $brand->get();
         $list_idx = $this->input->post('list');
         if (!($list = MongoDoc::get($binfo, 'lists.' . $list_idx))) {
             Json::error('Invalid list');
         }
         $list['influencers'] = array_values(array_diff($list['influencers'], array(new \MongoId($this->input->post('id')))));
         $redirect = null;
         if (count($list['influencers'])) {
             $binfo['lists'][$list_idx] = $list;
         } else {
             // Redirect if list is empty, cause we've removed it
             $redirect = Url::base(Url::current());
             unset($binfo['lists'][$list_idx]);
             $binfo['lists'] = array_values($binfo['lists']);
         }
         $brand->update(array('lists' => $binfo['lists']));
         $influencers = (new Influencer(null))->filter(array('_id' => array('$in' => $list['influencers'])), array('_id' => true, 'name' => true, 'username' => true));
         $body = $this->_display->view(array('main/app/brand/influencer.list.php'), array('influencers' => $influencers), true, false);
         Json::success('Success', $redirect, array('body' => $body));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Example #26
0
use app\helpers\Url;
?>
<!DOCTYPE HTML>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title><?php 
echo Html::encode($this->title);
?>
</title>
    <link href="/css/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div id="logo"><a href="<?php 
echo Html::encode(Url::to(['site/index']));
?>
">Мой сайт</a></div>

<?php 
echo $this->render('layouts/_topMenu');
?>

<div id="middle">

<?php 
echo $this->render('layouts/_subMenu');
?>

<div id="content">
<h1><?php 
Example #27
0
use yii\helpers\Html;
use app\helpers\Url;
use yii\widgets\Breadcrumbs;
/* @var $this \yii\web\View */
/* @var $content string */
$appAsset = AppAsset::register($this);
/* @var $i18n \pavlinter\translation\I18N */
$i18n = Yii::$app->getI18n();
\app\modules\admunderconst\Module::loadUnderConstruction($this);
$menus = Page::find()->with(['translations', 'childs' => function ($q) {
    $q->andWhere(['active' => 1, 'visible' => 1]);
}])->where(['id_parent' => [1, 2, 3], 'active' => 1, 'visible' => 1])->orderBy(['weight' => SORT_ASC])->all();
$Menu1 = [];
$Menu2 = [];
$Menu3 = [];
$baseUrl = Url::getLangUrl();
foreach ($menus as $menu) {
    $item = [];
    $item['label'] = $menu->name;
    if ($menu->type === 'main') {
        $item['url'] = $baseUrl;
    } else {
        $item['url'] = $menu->url();
    }
    if ($menu->childs) {
        foreach ($menu->childs as $child) {
            $item['items'][] = ['label' => $child->name, 'url' => $child->url()];
        }
    }
    if ($menu->id_parent == 1) {
        $Menu1[] = $item;
Example #28
0
<?php

/** @var $this \app\View */
use app\helpers\Html;
use app\helpers\Url;
?>
<ul id="subMenu">
    <?php 
foreach ($this->subMenu as $menuItem) {
    ?>
        <?php 
    $href = Url::to($menuItem['route']);
    if (strpos($_SERVER['REQUEST_URI'], $href) !== 0) {
        ?>
            <li><a href="<?php 
        echo Html::encode($href);
        ?>
"><?php 
        echo Html::encode($menuItem['name']);
        ?>
</a></li><?php 
    } else {
        if ($_SERVER['REQUEST_URI'] !== $href) {
            ?>
                <li class="current"><a href="<?php 
            echo Html::encode($href);
            ?>
"><?php 
            echo Html::encode($menuItem['name']);
            ?>
</a></li><?php 
Example #29
0
 public function index()
 {
     Url::redirect(UserSession::get('user.type') . '/home');
 }
Example #30
0
 protected function _view($id)
 {
     $notify = new Notify();
     $n = $notify->get(new \MongoId($id), true, UserSession::get('user._id'));
     Url::redirect(empty($n['url']) ? Url::referrer() : $n['url']);
 }