Ejemplo n.º 1
0
 public function addAction()
 {
     $this->accessRights(13);
     //Accept Parent Module, Return Main Menu Lists with Active Menu Indicator
     $this->childModuleAccessRights(24, 'add');
     //Accept Child Module ID & it's Actions: add, edit, view, disable
     //Declarer view model
     $msgs = '';
     //Generate Adapter
     $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     //Generate Add Form
     $form = new UserAddForm($this->adapter);
     //Get Post Data
     $request = $this->getRequest();
     //Get form object
     if ($request->isPost()) {
         $form->setData($request->getPost());
         //Set Form Data
         //Check that the username is not present in the database
         $validator = new NoRecordExists(array('table' => 'app_user_credentials', 'field' => 'username', 'adapter' => $this->adapter));
         //If username isn't found save record
         if ($validator->isValid($request->getPost('username'))) {
             $user = new User();
             $form->setInputFilter($user->getInputFilter());
             $form->setData($request->getPost());
             $form->isValid();
             $user->exchangeArray($form->getData());
             //Set null if empty
             //Save Data to Audit Trail
             $from = $this->getRequest()->getPost()->toArray();
             //Convert Post To ID
             //Get role Name
             $role_name = (array) $this->getRoleTable()->getRole($this->adapter, $from['role_id']);
             //Get Role Data;
             $from['role_name'] = $role_name['role_name'];
             //Get company name
             $company_name = (array) $this->getCompanyTable()->getCompany($from['company_id']);
             //Get Role Data;
             $from['company_name'] = $company_name['company_name'];
             unset($from['submit'], $from['app_user_credentials_id'], $from['user_detail_id'], $from['role_id'], $from['company_id'], $from['password'], $from['confirm_password']);
             //Remove IDs
             $added = $this->prepare_added_data($from);
             //Make array to string
             $this->save_to_audit_trail($request->getPost('username'), $added, '--', 'add', 24);
             //Save Audit Trail
             $this->getUserTable()->saveUser($request->getPost());
             //Redirect to index
             $this->flashMessenger()->addMessage(['content' => $request->getPost('username') . ' has been save!', 'type' => 'success']);
             $this->redirect()->toRoute('user');
         } else {
             //Username already exist
             $msgs = 'Username already exists!';
         }
     }
     $view = new ViewModel(array('form' => $form, 'msgs' => $msgs, 'users' => $this->getUserTable()->fetchAll($this->adapter), 'companies' => $this->getUserTable()->getAllCompany($this->adapter), 'action' => 'add', 'tab_menus' => $this->getTabMenu('User & Role'), 'access_rights' => $this->getSubModuleAccessRights(24)));
     $view->setTemplate('user/index');
     return $view;
 }
Ejemplo n.º 2
0
 public function isValid($context = null)
 {
     $clause[] = 'lang_id = ' . $context['langId'];
     if (isset($context['id']) && !empty($context['id'])) {
         $clause[] = 'id <> ' . $context['id'];
     }
     $this->dbNoRecordExistsValidator->setExclude(implode(' AND ', $clause));
     return parent::isValid($context);
 }
Ejemplo n.º 3
0
 public function index02Action()
 {
     $adapter = $this->getServiceLocator()->get("db_books");
     $validate = new NoRecordExists(array("table" => "user", "field" => "email", "adapter" => $adapter));
     $email = "*****@*****.**";
     if (!$validate->isValid($email)) {
         echo "<pre style='font-weight:bold'>";
         print_r($validate->getMessages());
         echo "</pre>";
     }
     return false;
 }
Ejemplo n.º 4
0
 private function nameUniqueValidator()
 {
     $uniqueValidator = new NoRecordExists(array('table' => 'user', 'field' => 'username', 'adapter' => $this->dbAdapter, 'messages' => array(\Zend\Validator\Db\NoRecordExists::ERROR_RECORD_FOUND => 'user with this username already exists')));
     $select = new Select();
     $select->from('user');
     $select->where(array('username= ?' => $this->data->username));
     $uniqueValidator->setSelect($select);
     return $uniqueValidator;
 }
Ejemplo n.º 5
0
 /**
  * Delete a category
  *
  * @return ViewModel
  */
 public function deleteAction()
 {
     // Check Login
     if (!$this->zfcUserAuthentication()->hasIdentity()) {
         return $this->redirect()->toRoute('zfcuser');
     }
     $categoryID = (int) $this->params()->fromRoute('id', 0);
     if (!$categoryID) {
         return $this->redirect()->toRoute('category');
     }
     $form = new DeleteForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $yes = $request->getPost('yes');
         $no = $request->getPost('no');
         if ($no == 'no') {
             // Redirect to list of categories
             return $this->redirect()->toRoute('category');
         }
         if ($yes == 'yes') {
             $categoryID = (int) $request->getPost('id');
             $form->setData($request->getPost());
             $validator = new NoRecordExists(array('table' => 'files', 'field' => 'categoryID', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter')));
             $validator->setMessage("Please delete all files in this category", \Zend\Validator\Db\AbstractDb::ERROR_RECORD_FOUND);
             $form->getInputFilter()->get('id')->getValidatorChain()->addValidator($validator);
             if ($form->isValid()) {
                 $this->getCategoryTable()->deleteCategory($categoryID);
                 // Redirect to list of categories
                 return $this->redirect()->toRoute('category');
             }
         }
     }
     return array('form' => $form, 'id' => $categoryID, 'category' => $this->getCategoryTable()->getCategory($categoryID));
 }
Ejemplo n.º 6
0
 /**
  * Test that schemas are supported and run without error
  *
  * @return void
  */
 public function testWithSchemaNoResult()
 {
     $validator = new NoRecordExists(array('table' => 'users', 'schema' => 'my'), 'field1', null, $this->getMockNoResult());
     $this->assertTrue($validator->isValid('value1'));
 }
Ejemplo n.º 7
0
 /**
  * Test when adapter is provided
  *
  * @return void
  */
 public function testAdapterProvidedNoResult()
 {
     //clear the default adapter to ensure provided one is used
     AbstractTable::setDefaultAdapter(null);
     $validator = new NoRecordExistsValidator('users', 'field1', null, $this->_adapterNoResult);
     $this->assertTrue($validator->isValid('value1'));
 }
Ejemplo n.º 8
0
 /**
  * Test when adapter is provided
  *
  * @return void
  */
 public function testAdapterProvidedNoResult()
 {
     //clear the default adapter to ensure provided one is used
     AbstractTable::setDefaultAdapter(null);
     try {
         $validator = new NoRecordExistsValidator('users', 'field1', null, $this->_adapterNoResult);
         $this->assertTrue($validator->isValid('value1'));
     } catch (\Exception $e) {
         $this->markTestSkipped('No database available');
     }
 }
 public function noRecordExists($table, $field, $post_name = null)
 {
     $this->adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $validator = new NoRecordExists(array('table' => $table, 'field' => $field, 'adapter' => $this->adapter));
     $post_name = is_null($post_name) ? $field : $post_name;
     $request = $this->getRequest();
     if ($validator->isValid($request->getPost($post_name))) {
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 10
0
 public function getNoRecordExistsValidator()
 {
     if ($this->noRecordExistsValidator === NULL) {
         $validator = new NoRecordExists($this->getNoRecordExistsConfig());
         $validator->setMessages(array(NoRecordExists::ERROR_NO_RECORD_FOUND => $this->getErrorMessage('RECORD_EXISTS::ERROR_NO_RECORD_FOUND'), NoRecordExists::ERROR_RECORD_FOUND => $this->getErrorMessage('NO_RECORD_EXISTS::ERROR_RECORD_FOUND')));
         $this->setNoRecordExistsValidator($validator);
     }
     return $this->noRecordExistsValidator;
 }
Ejemplo n.º 11
0
 public function checkAliasUniquenessAction()
 {
     $result = ['status' => 'success'];
     $request = $this->getRequest();
     if ($request->isPost() && $request->isXmlHttpRequest()) {
         $aliasId = $request->getPost('id', 0);
         $aliasName = $request->getPost('name', '');
         if ($aliasName) {
             $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
             $uniqueValidator = new NoRecordExists(array('adapter' => $dbAdapter, 'table' => DbTables::TBL_ASSET_CATEGORY_ALIASES, 'field' => 'name', 'exclude' => array('field' => 'id', 'value' => $aliasId)));
             if (!$uniqueValidator->isValid($aliasName)) {
                 $result = ['status' => 'error', 'msg' => 'Alias with name ' . $aliasName . ' already exists'];
             }
         }
     }
     return new JsonModel($result);
 }
Ejemplo n.º 12
0
 public function checkRowExist($table, $field, $value)
 {
     if ($table === null) {
         $table = $this->getTable();
     }
     $params = ['adapter' => $this->adapter, 'table' => $table, 'field' => $field];
     $validator = new NoRecordExists($params);
     if ($validator->isValid($value)) {
         return false;
     }
     return true;
 }
 /**
  * Add a new subscription
  *
  * @return JsonModel
  */
 public function create($data)
 {
     $username = $this->params()->fromRoute('username');
     $usersTable = $this->getTable('UsersTable');
     $user = $usersTable->getByUsername($username);
     $userFeedsTable = $this->getTable('UserFeedsTable');
     $rssLinkXpath = '//link[@type="application/rss+xml"]';
     $faviconXpath = '//link[@rel="shortcut icon"]';
     $client = new Client($data['url']);
     $client->setEncType(Client::ENC_URLENCODED);
     $client->setMethod(\Zend\Http\Request::METHOD_GET);
     $response = $client->send();
     if ($response->isSuccess()) {
         $html = $response->getBody();
         $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8");
         $dom = new Query($html);
         $rssUrl = $dom->execute($rssLinkXpath);
         if (!count($rssUrl)) {
             return new JsonModel(array('result' => false, 'message' => 'Rss link not found in the url provided'));
         }
         $rssUrl = $rssUrl->current()->getAttribute('href');
         $faviconUrl = $dom->execute($faviconXpath);
         if (count($faviconUrl)) {
             $faviconUrl = $faviconUrl->current()->getAttribute('href');
         } else {
             $faviconUrl = null;
         }
     } else {
         return new JsonModel(array('result' => false, 'message' => 'Website not found'));
     }
     $validator = new NoRecordExists(array('table' => 'user_feeds', 'field' => 'url', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter')));
     if (!$validator->isValid($rssUrl)) {
         return new JsonModel(array('result' => false, 'message' => 'You already have a subscription to this url'));
     }
     $rss = Reader::import($rssUrl);
     return new JsonModel(array('result' => $userFeedsTable->create($user->id, $rssUrl, $rss->getTitle(), $faviconUrl)));
 }
Ejemplo n.º 14
0
 public function validateForgotPasswordAction()
 {
     $forgotPasswordHomeForm = $this->serviceLocator->get('FormElementManager')->get('forgotPasswordHomeForm');
     if ($this->getRequest()->isPost()) {
         $data = $this->getRequest()->getPost();
         $forgotPasswordHomeForm->setData($data);
         if ($forgotPasswordHomeForm->isValid()) {
             $validator = new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'email', 'adapter' => $this->adapter));
             if ($validator->isValid($this->_arrPost['my-email'])) {
                 $result['status'] = 'error';
                 $result['messages']['email'] = 'Email không tồn tại trong hệ thống';
             } else {
                 $restorePassCode = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
                 //Kích hoạt qua email cẩn phải có mã kích hoạt
                 $arrParam = array('email' => $this->_arrPost['my-email'], 'fpass_code' => $restorePassCode);
                 $this->getTable()->saveItem($arrParam, array('task' => 'forgot-password-code'));
                 $LinkRestorePass = \ZendVN\Url\CurrentDomain::get() . $this->url()->fromRoute('MVC_HomeRouter/restorepass', array('module' => 'home', 'controller' => 'user', 'action' => 'restore-pass', 'code' => $restorePassCode));
                 $this->sendMailForgotPassword($this->_arrPost['my-email'], $LinkRestorePass);
                 $result['messages']['success'] = 'Gửi thành công, vui lòng kiểm tra lại Email để biết thông tin.<br>
                                                             Email của bạn: ' . $this->_arrPost['my-email'];
                 $result['status'] = 'success';
             }
         } else {
             $result['status'] = 'error';
             $result['messages']['email'] = '';
             if (current($forgotPasswordHomeForm->getMessages('my-email')) != '') {
                 $result['messages']['email'] = 'Email : Bạn phải nhập đúng định dạng Email ';
             }
         }
     }
     echo \Zend\Json\Json::encode($result);
     return $this->getResponse();
 }