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)); } }
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))))); }
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; }
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()); } }
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')); }
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')); }
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'])); } } }
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)))); }
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)))); }
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)))); }
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()); } }
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')); }
public function post() { Url::redirect(Url::base('influencer/river/' . $this->input->post('id') ?: '')); }