예제 #1
0
 /**
  * Validates the model.
  *
  * @return boolean True if passed validators otherwise false
  */
 private function _validate()
 {
     $validator = new Validations($this);
     $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update');
     foreach (array('before_validation', "before_{$validation_on}") as $callback) {
         if (method_exists($this, $callback) && !call_user_func(array($this, $callback))) {
             return false;
         }
     }
     // need to store reference b4 validating so that custom validators have access to add errors
     $this->errors = $validator->get_record();
     $validator->validate();
     foreach (array('after_validation', "after_{$validation_on}") as $callback) {
         if (method_exists($this, $callback)) {
             call_user_func(array($this, $callback));
         }
     }
     if (!$this->errors->is_empty()) {
         return false;
     }
     return true;
 }
예제 #2
0
파일: Model.php 프로젝트: neoff/mywork
 /**
  * Validates the model.
  *
  * @return boolean True if passed validators otherwise false
  */
 private function _validate()
 {
     require_once 'Validations.php';
     $validator = new Validations($this);
     $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update');
     foreach (array('before_validation', "before_{$validation_on}") as $callback) {
         if (!$this->invoke_callback($callback, false)) {
             return false;
         }
     }
     $this->errors = $validator->validate();
     foreach (array('after_validation', "after_{$validation_on}") as $callback) {
         $this->invoke_callback($callback, false);
     }
     if (!$this->errors->is_empty()) {
         return false;
     }
     return true;
 }
예제 #3
0
 /**
  * Validates the model.
  *
  * @return boolean True if passed validators otherwise false
  */
 private function _validate()
 {
     require_once 'Validations.php';
     $validator = new Validations($this);
     $validation_on = 'validation_on_' . ($this->is_new_record() ? 'create' : 'update');
     foreach (array('before_validation', "before_{$validation_on}") as $callback) {
         if (!$this->invoke_callback($callback, false)) {
             return false;
         }
     }
     // need to store reference b4 validating so that custom validators have access to add errors
     $this->errors = $validator->get_record();
     $validator->validate();
     foreach (array('after_validation', "after_{$validation_on}") as $callback) {
         $this->invoke_callback($callback, false);
     }
     if (!$this->errors->is_empty()) {
         return false;
     }
     return true;
 }
 public function actionPassRequest()
 {
     if (!isset($_POST['PassRequestForm'])) {
         //new request
         $requestForm = new PassRequestForm();
         $this->render('passrequest', array('model' => $requestForm));
     } else {
         //requst form has been filled
         $requestForm = new PassRequestForm();
         $requestForm->attributes = $_POST['PassRequestForm'];
         if (!$requestForm->validate()) {
             yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Restore form validation failed'));
             $this->render('passrequest', array('model' => $requestForm));
             return;
         }
         //for is correct so, prepare and send request email
         $email = $_POST['PassRequestForm']['email'];
         //create new guid and sent it to user
         $guid = AuthCommon::getGUID();
         $userModel = new Users();
         $user = $userModel->getByEmail($email);
         if ($user == null) {
             yii::app()->user->setFlash('warning', sprintf(Yii::t('AuthModule.main', 'Email address was not found'), $email));
             $this->redirect(array('user/passrequest'));
             return;
         }
         $user_id = $user->id;
         $validations = new Validations();
         $validations->guid = $guid;
         $validations->user_id = $user_id;
         $validations->email = $email;
         $validations->type = self::VALIDATOR_RESTORE;
         $date = new DateTime();
         $date->modify("+24 hours");
         $exp_time = $date->format(AuthCommon::getParam('dateFormat'));
         $validations->exp_datetime = $exp_time;
         $validations->comments = 'Restore user password';
         if (!$validations->validate()) {
             yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Password restore not complited'));
             $this->render('passrequest', array('model' => $requestForm));
             return;
         }
         if (!$validations->save()) {
             yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Password restore not complited'));
             $this->render('passrequest', array('model' => $requestForm));
             return;
         }
         //send email with restore link
         if (!$requestForm->validate()) {
             yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Restore form validation failed'));
             $this->render('passrequest', array('model' => $requestForm));
             return;
         }
         $result = AuthCommon::sendPassRequestEmail($email, $guid, $user->username);
         if ($result) {
             Yii::app()->user->setFlash('success', sprintf(Yii::t('AuthModule.main', 'Password restore link has been sent'), $email));
             $this->redirect(array('user/passchange'));
         } else {
             Yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Error sending email message'));
             $this->redirect(array('user/passrequest'));
         }
     }
 }
예제 #5
0
 /**
  * Validates the model.
  *
  * @return boolean True if passed validators otherwise false
  */
 private function _validate()
 {
     require_once 'Validations.php';
     $validator = new Validations($this);
     $validationOn = 'ValidationOn' . ($this->isNewRecord() ? 'Create' : 'Update');
     foreach (array('beforeValidation', "before{$validationOn}") as $callback) {
         if (!$this->invokeCallback($callback, false)) {
             return false;
         }
     }
     // need to store reference b4 validating so that custom validators have access to add errors
     $this->errors = $validator->getRecord();
     $validator->validate();
     foreach (array('afterValidation', "after{$validationOn}") as $callback) {
         $this->invokeCallback($callback, false);
     }
     if (!$this->errors->isEmpty()) {
         return false;
     }
     return true;
 }