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()); } } }
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()); } } }