Пример #1
0
 protected function _add()
 {
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $lists = MongoDoc::get($binfo, 'lists', array());
     $list_idx = $this->input->post('list');
     $new_list = $this->input->post('new_list');
     if ($list_idx !== null && isset($lists[$list_idx])) {
         if (in_array($id, $lists[$list_idx]['influencers'])) {
             Json::success('Influencer is already preset in the list');
         }
         $lists[$list_idx]['influencers'][] = $id;
     } else {
         if (!empty($new_list)) {
             foreach ($lists as $l) {
                 if ($l['name'] === $new_list) {
                     Json::error(sprintf('List with name "%s" already exists', $new_list));
                 }
             }
             $lists[] = array('name' => $new_list, 'influencers' => array($id));
         } else {
             Json::error('Invalid list');
         }
     }
     $brand->update(array('lists' => $lists));
     Json::success('Success');
 }
Пример #2
0
 protected function _404($error = '')
 {
     if ($this->input->is_ajax_request()) {
         Json::error('404 Not Found' . $error);
     }
     $this->_display->view('404.php', array('error' => $error), false, false);
 }
Пример #3
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     $user = new Influencer($this->input->post('id'));
     if (!($uinfo = $user->get())) {
         Json::error('Invalid user!');
     }
     try {
         $password = null;
         if ($this->input->post('password')) {
             $password = Secure::password($this->input->post('password'), $uinfo['username']);
         }
         $valid = new FormValidator();
         $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
         $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
         $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
         $valid->is('City', $this->input->post('city'))->required()->push('city');
         $valid->is('Genre', $this->input->post('genre'))->required()->transform(function ($d) {
             return explode(',', $d);
         })->push('genre');
         if ($password) {
             $valid->is('Password', $password)->length(5, 100)->push('password');
         }
         $valid->is('About', $this->input->post('about'))->optional()->length(20, 500)->push('about');
         $valid->is('Address', $this->input->post('address'))->optional()->length(10, 100)->push('address');
         $valid->is('Date of Birth', $this->input->post('date_of_birth'))->optional()->custom(function ($key, $value) {
             $d = \DateTime::createFromFormat('Y-m-d', $value);
             if (!($d && $d->format('Y-m-d') == $value)) {
                 throw new \Exception($key . ' must be a valid date of the format yyyy-mm-dd');
             }
         })->push('date_of_birth');
         $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
         $valid->is('Picture', $this->input->post('picture'))->optional()->length(5)->custom(function ($key, $value) {
             $d = get_headers($value, 1);
             if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                 throw new \Exception($key . ' returned a response of : ' . $d[0]);
             }
         })->push('picture');
         $valid->is('Interest', $this->input->post('interest'))->push('interest');
         $data = $valid->data();
         $user->update($data);
         if ($password) {
             (new NotifyInfluencerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
         }
         // Update Session
         UserSession::set('user', $user->get());
         Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #4
0
 public function post()
 {
     try {
         $campaign = new Campaign(null);
         $cinfo = $campaign->find_modify_one(array('_id' => new \MongoId($this->input->post('id')), 'brand' => UserSession::get('user._id'), 'state' => 'pending'), array('$set' => array('state' => 'rejected')));
         if (!$cinfo) {
             $this->_403();
         }
         Json::success('Campaign removed');
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #5
0
 protected function _activation()
 {
     $brand = new BrandModel($this->input->post('id'));
     if (!($binfo = $brand->get())) {
         Json::error('Invalid brand!');
     }
     try {
         $active = $this->input->post('active') ? true : false;
         $brand->update(array('active' => $active));
         (new NotifyBrandAccount())->activation($binfo['_id'], UserSession::get('user._id'));
         Json::success('Brand status updated!', null);
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #6
0
 public function post()
 {
     if (UserSession::get('user.type') !== 'brand') {
         $this->_403();
     }
     if (!($id = $this->input->post('id'))) {
         Json::error('Invalid influencer id');
     }
     $id = new \MongoId($id);
     $brand = new Brand(UserSession::get('user._id'));
     $binfo = $brand->get();
     $favorites = MongoDoc::get($binfo, 'favorites', array());
     if ($reset = in_array($id, $favorites)) {
         $favorites = array_values(array_diff($favorites, array($id)));
     } else {
         $favorites[] = $id;
     }
     $brand->update(array('favorites' => $favorites));
     Json::success('Success', null, array('set' => !$reset));
 }
Пример #7
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     $user = new Admin($this->input->post('id'));
     if (!($uinfo = $user->get())) {
         Json::error('Invalid user!');
     }
     try {
         $password = null;
         if ($this->input->post('password')) {
             $password = Secure::password($this->input->post('password'), $uinfo['username']);
         }
         $valid = new FormValidator();
         $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
         $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
         if ($password) {
             $valid->is('Password', $password)->length(5, 100)->push('password');
         }
         $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
         $data = $valid->data();
         if (UserSession::get('user.superadmin') && $this->input->post('superadmin') == 1) {
             $data['superadmin'] = true;
         }
         $user->update($data);
         if ($password) {
             (new NotifyAdminAccount())->update($uinfo['_id'], UserSession::get('user._id'));
         }
         // Update Session
         UserSession::set('user', $user->get());
         Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
     } catch (\Exception $e) {
         Json::error($e->getMessage());
     }
 }
Пример #8
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     if ($this->input->post('action') == 'update-manager') {
         $user = new ExtraUser($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->alnum('- \\.')->length(5, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->email()->length(5, 100)->push('email');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyPartnerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user.manager', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     } else {
         $user = new Partner($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->alnum('- \\.')->length(5, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->email()->length(5, 100)->push('email');
             $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
             $valid->is('Company Name', $this->input->post('company_name'))->required()->length(5, 100)->push('company_name');
             $valid->is('Company Address', $this->input->post('company_address'))->required()->length(10, 100)->push('company_address');
             $valid->is('Company Website', $this->input->post('company_url'))->required()->length(5, 100)->push('company_url');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyPartnerAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     }
 }
Пример #9
0
 public function post()
 {
     if (!$this->input->is_ajax_request()) {
         $this->_403();
     }
     if ($this->input->post('action') == 'update-manager') {
         $user = new ExtraUser($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $data = $valid->data();
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user.manager', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     } else {
         $user = new Brand($this->input->post('id'));
         if (!($uinfo = $user->get())) {
             Json::error('Invalid user!');
         }
         try {
             $password = null;
             if ($this->input->post('password')) {
                 $password = Secure::password($this->input->post('password'), $uinfo['username']);
             }
             $valid = new FormValidator();
             $valid->is('Name', $this->input->post('name'))->required()->length(3, 100)->push('name');
             $valid->is('Email', $this->input->post('email'))->required()->length(5, 100)->push('email');
             $valid->is('Contact', $this->input->post('phone'))->required()->length(3, 100)->push('phone');
             if (UserSession::get('main_user.type') == 'admin') {
                 $valid->is('Package', $this->input->post('package'))->required()->push('package');
             }
             if ($password) {
                 $valid->is('Password', $password)->length(5, 100)->push('password');
             }
             $valid->is('About', $this->input->post('about'))->optional()->length(20, 500)->push('about');
             $valid->is('Address', $this->input->post('address'))->optional()->length(10, 100)->push('address');
             $valid->is('Wesbite', $this->input->post('url'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('url');
             $valid->is('Timezone', $this->input->post('timezone'))->optional()->length(3, 50)->push('timezone');
             $valid->is('Logo', $this->input->post('logo'))->optional()->length(5)->custom(function ($key, $value) {
                 $d = get_headers($value, 1);
                 if (preg_match('@HTTP/1.1 (4|5)@', $d[0])) {
                     throw new \Exception($key . ' returned a response of : ' . $d[0]);
                 }
             })->push('logo');
             $data = $valid->data();
             if (in_array(UserSession::get('main_user.type'), array('admin', 'partner'))) {
                 $data['social_river.enabled'] = !!$this->input->post('social_river');
             }
             $user->update($data);
             if ($password) {
                 (new NotifyBrandAccount())->update($uinfo['_id'], UserSession::get('user._id'));
             }
             // Update Session
             UserSession::set('user', $user->get());
             Json::success('User details updated!', null, array('user' => (new User($uinfo['_id']))->get()));
         } catch (\Exception $e) {
             Json::error($e->getMessage());
         }
     }
 }
Пример #10
0
 protected function _login()
 {
     if ($this->input->is_ajax_request()) {
         $login_as = false;
         $u = null;
         if (UserSession::get('user.type') === 'admin') {
             $u = (new User($this->input->post('id')))->get();
             $this->_set_picture($u);
             $login_as = true;
         } else {
             if (UserSession::get('user.type') === 'partner') {
                 $partner = new Partner(UserSession::get('user._id'));
                 if ($partner->valid_brand($this->input->post('id'))) {
                     $u = (new User($this->input->post('id')))->get();
                     $this->_set_picture($u);
                     $login_as = true;
                 }
             } else {
                 try {
                     $data = $this->_get_login_data();
                     $user = new User(null);
                     if ($u = $user->authenticate($data['username'], Secure::password($data['password'], $data['username']))) {
                         $this->_set_picture($u);
                         if (isset($u['social'])) {
                             unset($u['social']);
                             // Unset unnecessary social data
                         }
                         if ($u['type'] === 'extra') {
                             $t = $u;
                             $u = (new User($t['account']))->get();
                             $u['manager'] = $t;
                         }
                     }
                 } catch (\Exception $e) {
                     Json::error($e->getMessage());
                 }
             }
         }
         if ($u) {
             $data = array('user' => $u);
             if ($login_as) {
                 // Set the main user, if an existing doesn't exist
                 // Only the first user set is main user
                 $data['main_user'] = UserSession::get('main_user') ?: UserSession::get('user');
             }
             UserSession::set(null, $data);
             Json::success('Login successful! Redirecting to home...', Url::base(''));
         }
         Json::error('Invalid credentials or user not active');
     }
 }