示例#1
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());
     }
 }
示例#2
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));
     }
 }
示例#3
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());
     }
 }
示例#4
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());
     }
 }
示例#5
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());
     }
 }
示例#6
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'));
 }
示例#7
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'));
 }
示例#8
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());
     }
 }
示例#9
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());
     }
 }
示例#10
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());
     }
 }
示例#11
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());
     }
 }
 /**
  * check if the user has data in the user provider table.  If not add it.  Then log them in
  */
 public function callback($provider_name)
 {
     $auth_user = Auth::user();
     $redir = session('oauth_redir');
     session()->forget('oauth_redir');
     try {
         $provider = Provider::where('provider_safe_name', '=', $provider_name)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         echo 'Caught exception: ', $e->getMessage(), "\n";
         exit;
     }
     $user = Socialite::driver($provider_name)->user();
     $local_user = UserProvider::where('provider_key', $user['id'])->first();
     if (count($local_user)) {
         $local_user = $local_user->user()->first();
     } else {
         if (empty($auth_user)) {
             $local_user = User::where('email', $user['email'])->first();
         } else {
             $local_user = $auth_user;
         }
         //not found by email either
         if (!count($local_user)) {
             //create user
             $local_user = User::create(['first_name' => $user['name'], 'email' => $user['email']]);
             UserProvider::create(['provider_id' => $provider->id, 'user_id' => $local_user['id'], 'provider_key' => $user['id']]);
         } else {
             //update user with
             UserProvider::create(['provider_id' => $provider->id, 'user_id' => $local_user['id'], 'provider_key' => $user['id']]);
         }
     }
     Auth::login($local_user, true);
     switch ($redir) {
         case "profile":
             Alert::add("Social network has been added to your profile", ["alert_type" => "success"]);
             break;
     }
     return redirect()->route($redir);
 }
示例#13
0
 protected function _logout()
 {
     $this->_check_login();
     // If login as feature is used
     if ($u = UserSession::get('main_user')) {
         UserSession::set('user', $u);
         UserSession::erase('main_user');
         Alert::once('warning', 'Logged in as ' . $u['username'], Url::base(''));
     }
     UserSession::destroy();
     Alert::once('warning', 'You have been logged out!', Url::base('auth/login'));
 }