Ejemplo n.º 1
0
 /**
  * validate
  *
  * @param  DataInterface $data
  *
  * @return  void
  *
  * @throws ValidateFailException
  */
 protected function validate(DataInterface $data)
 {
     $validator = new EmailValidator();
     if (!$validator->validate($data->email)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.email.invalid'));
     }
     parent::validate($data);
     $loginName = WarderHelper::getLoginName();
     if ($loginName != 'email') {
         $user = User::get(array($loginName => $data->{$loginName}));
         if ($user->notNull() && $user->id != $data->id) {
             throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.account.exists'));
         }
     }
     $user = User::get(array('email' => $data->email));
     if ($user->notNull() && $user->id != $data->id) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.user.email.exists'));
     }
     if ('' !== (string) $data->password) {
         if ($data->password != $data->password2) {
             throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match'));
         }
         unset($data->password2);
     } else {
         unset($data->password);
     }
 }
Ejemplo n.º 2
0
 /**
  * validate
  *
  * @param  DataInterface $data
  *
  * @return  void
  *
  * @throws ValidateFailException
  */
 protected function validate(DataInterface $data)
 {
     $validator = new EmailValidator();
     if (!$validator->validate($data->email)) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.email.invalid'));
     }
     $form = $this->model->getForm('registration', 'user');
     $this->model->validate($data->dump(), $form);
     if (!$data->password) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.entered'));
     }
     if ($data->password != $data->password2) {
         throw new ValidateFailException(Translator::translate($this->langPrefix . 'message.password.not.match'));
     }
     unset($data->password2);
 }