/**
  * @param AuthenticationOptionsInterface $options
  */
 public function __construct(AuthenticationOptionsInterface $options)
 {
     $identityParams = array('name' => 'identity', 'required' => true, 'validators' => array());
     $identityFields = $options->getAuthIdentityFields();
     if ($identityFields == array('email')) {
         $validators = array('name' => 'EmailAddress');
         array_push($identityParams['validators'], $validators);
     }
     $this->add($identityParams);
     $this->add(array('name' => 'credential', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => '\\Application\\Validator\\NotEmptyValidator', 'options' => array('campo' => \Application\Constants\UsuarioConst::LBL_SENHA_ANTIGA)), array('break_chain_on_failure' => true, 'name' => 'Application\\Validator\\PasswordStrengthValidator'), array('break_chain_on_failure' => true, 'name' => 'StringLength', 'options' => array('min' => 5, 'max' => 12))), 'filters' => array(array('name' => 'StringTrim'))));
     $this->add(array('name' => 'newCredential', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => '\\Application\\Validator\\NotEmptyValidator', 'options' => array('campo' => \Application\Constants\UsuarioConst::LBL_NOVA_SENHA)), array('break_chain_on_failure' => true, 'name' => 'Application\\Validator\\PasswordStrengthValidator'), array('break_chain_on_failure' => true, 'name' => 'StringLength', 'options' => array('min' => 5, 'max' => 12))), 'filters' => array(array('name' => 'StringTrim'))));
     $this->add(array('name' => 'newCredentialVerify', 'required' => true, 'validators' => array(array('break_chain_on_failure' => true, 'name' => '\\Application\\Validator\\NotEmptyValidator', 'options' => array('campo' => \Application\Constants\UsuarioConst::LBL_CONFIRM_NOVA_SENHA), array('name' => 'Application\\Validator\\PasswordStrengthValidator')), array('break_chain_on_failure' => true, 'name' => 'StringLength', 'options' => array('min' => 5, 'max' => 12)), array('break_chain_on_failure' => true, 'name' => 'identical', 'options' => array('token' => 'newCredential', 'messages' => array(\Zend\Validator\Identical::NOT_SAME => Mensagens::getMensagem('M12'))))), 'filters' => array(array('name' => 'StringTrim'))));
 }
 /**
  * Valida chave de acesso na alteração da senha
  *
  * @return mixed|ViewModel
  */
 public function validarChaveAcessoAction()
 {
     /** @var Result $response */
     $response = null;
     if (!$this->getRequest()->isPost()) {
         if (!$this->flashMessenger()->hasMessages('loginAuth')) {
             // redirect to the login redirect route
             return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
         } else {
             $response = $this->flashMessenger()->getMessages('loginAuth');
             $response = $response[0];
         }
         $msg = $response->getMessages();
     }
     if (isset($msg[0])) {
         $status = array('type' => 'warning', 'message' => $msg[0]);
     } else {
         $status = null;
     }
     $view = new ViewModel();
     $view->setTemplate('validar-chave-acesso');
     $this->layout('layout/unauthorized');
     $form = $this->getValidaAcessoForm();
     if (!$this->getRequest()->isPost()) {
         $identify = $response->getIdentity();
         $id = $form->get(UsuarioConst::FLD_IDENTITY);
         $id->setValue($identify['i']);
         $pwd = $form->get(UsuarioConst::FLD_SENHA);
         $pwd->setValue($identify['p']);
         $view->setVariables(array('status' => $status, 'form' => $form));
         return $view;
     }
     $form->setData($this->getRequest()->getPost());
     if (!$form->isValid()) {
         $view->setVariables(array('status' => array(), 'form' => $form));
         return $view;
     }
     $valid = $this->getUserService()->validaAcesso($form->getData());
     if ($valid < Result::FAILURE) {
         $status = array();
         if ($valid == UsuarioConst::ERRO_CHAVE_ACESSO_INVALIDO) {
             $status = array('type' => 'error', 'message' => Mensagens::getMensagem('M16'));
         }
         if ($valid == UsuarioConst::ERRO_EXCEDIDO_LIMITE_CHAVE_ACESSO) {
             $status = array('type' => 'error', 'message' => Mensagens::getMensagem('M23'));
         }
         $view->setVariables(array('status' => $status, 'form' => $form));
         return $view;
     }
     // clear adapters
     $this->zfcUserAuthentication()->getAuthAdapter()->resetAdapters();
     $this->zfcUserAuthentication()->getAuthService()->clearIdentity();
     return $this->forward()->dispatch(static::CONTROLLER_NAME, array('action' => 'authenticate'));
 }
 /**
  * Retorna a mensagem de sistema para o identificador fornecido
  *
  * @param $identificador
  * @param array $valores
  *
  * @return mixed
  */
 public function getMensagem($identificador, array $valores = null)
 {
     return Mensagens::getMensagem($identificador, $valores);
 }
Example #4
0
 /**
  * Retorna o um array referente a uma consulta no padrão do datatables para o painel.
  *
  * @return array
  */
 public function getGridFiltro()
 {
     /** @var UsuarioDao $usuarioDao */
     $usuarioDao = $this->getFromServiceLocator(Usuario::DAO);
     $cId = $usuarioDao->createColumnName(Usuario::FLD_TBL_ID);
     $cNome = $usuarioDao->createColumnName(Usuario::FLD_NOME);
     $cCargo = $usuarioDao->createColumnName(Usuario::FLD_CARGO);
     $cOrgao = $usuarioDao->createColumnName(Usuario::FLD_ORGAO);
     $cUnidade = $usuarioDao->createColumnName(Usuario::FLD_UNIDADE);
     $cEmail = $usuarioDao->createColumnName(Usuario::FLD_EMAIL);
     $cTelefone = $usuarioDao->createColumnName(Usuario::FLD_TELEFONE);
     $cDataCad = $usuarioDao->createColumnName(Usuario::FLD_DTCADASTRO);
     $cAcoes = 'acoes';
     $qb = $usuarioDao->getCompleteQueryBuilder();
     $gridQuery = new DatatableQuery($this->getServiceLocator());
     $gridQuery->setQueryBuilder($qb);
     $paramsPost = $gridQuery->getParametrosFromPost();
     $filtrosPesquisa = array_keys($this->getFiltroPesquisa());
     $primeiroCampoFiltroPesquisa = array_shift($filtrosPesquisa);
     $campoPesquisaRapida = $gridQuery->getCampoPesquisa($paramsPost, $primeiroCampoFiltroPesquisa);
     if ($paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_CAMPO] == $cDataCad) {
         $data = $paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_VALOR];
         $paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_VALOR] = implode('-', array_reverse(explode('/', $data)));
     }
     if (!empty($paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_VALOR]) && strcmp($paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_CAMPO], $this->getTbAlias() . '.' . Usuario::FLD_CARGO) == 0) {
         $searches = Cargo::search($paramsPost[DatatableQuery::PARAM_SEARCH][DatatableQuery::PARAM_SEARCH_VALOR]);
         foreach ($searches as $k => $search) {
             $gridQuery->addOrWhere($this->getTbAlias() . '.' . Usuario::FLD_CARGO, DatatableQuery::OPERATOR_CONTAINS, strtolower($search));
         }
     } else {
         $gridQuery->setPesquisaRapidaCampoOperacao($campoPesquisaRapida);
         $gridQuery->setUnicoParametro($paramsPost);
     }
     $gridQuery->setOrdenacaoReplace(array($this->getTbAlias() . '.' . Usuario::FLD_UNIDADE => Usuario::FLD_UNIDADE_OBJ_NOME));
     $gridQuery->setOrdenacaoReplace(array($this->getTbAlias() . '.' . Usuario::FLD_ORGAO => Usuario::FLD_ORGAO_OBJ_NOME));
     $retorno = $gridQuery->getDatatableArray();
     $data = array();
     foreach ($retorno[DatatableQuery::PARAM_REGISTROS] as $row) {
         /** @var \Application\Entity\Usuario $usuario */
         $usuario = is_a($row, '\\Application\\Custom\\EntityAbstract') ? $row : reset($row);
         $temp[$cId] = $usuario->getSeqUsuario();
         $temp[$cNome] = $usuario->getNomUsuario();
         $temp[$cCargo] = Cargo::getLabel($usuario->getSigCargo());
         $temp[$cOrgao] = $usuario->getUnidade()->getOrgao()->getNomeOrgao();
         $temp[$cUnidade] = $usuario->getUnidade()->getNomeUnidade();
         $temp[$cEmail] = $usuario->getEmail();
         $temp[$cTelefone] = $usuario->getTelUsuario();
         $temp[$cDataCad] = date_format($usuario->getDataInclusao(), 'd/m/Y');
         $urlEditar = $this->url(Rotas::USUARIO, array('action' => 'editar', 'id' => $usuario->getLoginUsuario()));
         $botaoExpedir = new DatatableHtmlButton($urlEditar);
         $botaoExpedir->setTitle('Editar');
         $botaoExpedir->setTipoEditar();
         $urlExcluir = $this->url(Rotas::USUARIO, array('action' => 'excluir', 'id' => $usuario->getLoginUsuario()));
         $botaoExcluir = new DatatableHtmlButton($urlExcluir);
         $botaoExcluir->setTitle('Excluir');
         $botaoExcluir->setTipoExcluir();
         $botaoExcluir->setRequireConfirmation(true, Mensagens::getMensagem('M16'));
         $acoes = new DatatableHtmlContainer(DatatableHtmlContainer::TIPO_BUTTONS);
         $acoes->add($botaoExpedir);
         $acoes->add($botaoExcluir);
         $temp[$cAcoes] = $acoes->render();
         $data[] = $temp;
     }
     $retorno[DatatableQuery::PARAM_REGISTROS] = $data;
     return $retorno;
 }
 /**
  * Editar usuario
  *
  * @return ViewModel
  */
 public function editarAction()
 {
     $login = $this->params()->fromRoute('id', null);
     /** @var UsuarioService $service */
     $service = $this->getFromServiceLocator(Usuario::SERVICE);
     /** @var \Application\Entity\User $usuario */
     $usuario = $service->findByLogin($login);
     if (!$usuario) {
         return $this->redirect()->toRoute(Rotas::USUARIO);
     }
     /** @var \Application\Entity\User $usuarioLogado */
     $usuarioLogado = $this->getFromServiceLocator(Usuario::ZFCUSER_AUTH_SERVICE)->getIdentity();
     /** @var  UsuarioForm $form */
     $form = $this->getFromServiceLocator(self::USUARIO_FORM);
     $form->get(Usuario::FLD_ORGAO)->setValue($usuario->getUnidade()->getOrgao()->getSeqOrgao());
     $redirectUrl = $this->url()->fromRoute(Rotas::USUARIO) . "/editar/{$login}";
     $prg = $this->prg($redirectUrl, true);
     if ($prg instanceof Response) {
         return $prg;
     } elseif ($prg === false) {
         $form->bind($usuario);
         $form->setObject($usuario);
         $unidadeAtual = $form->get(Usuario::FLD_UNIDADE)->getValue()->getSeqUnidade();
         $unidades = $this->createSelectUnidades($form->get(Usuario::FLD_ORGAO)->getValue());
         $form->get(Usuario::FLD_UNIDADE)->setValueOptions($unidades);
         $form->get(Usuario::FLD_UNIDADE)->setValue($unidadeAtual);
         return array('form' => $form, 'isCorregedor' => $usuarioLogado->isCorregedorGeral());
     }
     $form->setData($prg);
     if (strcmp($usuario->getLoginUsuario(), $prg[Usuario::FLD_LOGIN]) === 0) {
         $form->getInputFilter()->remove(Usuario::FLD_LOGIN);
     }
     $isValid = true;
     if ($form->get(Usuario::FLD_SENHA)->getValue()) {
         $pwd = $form->get(Usuario::FLD_SENHA)->getValue();
         $bcrypt = new Bcrypt();
         $bcrypt->setCost($service->getOptions()->getPasswordCost());
         if ($bcrypt->verify($pwd, $usuario->getPassword())) {
             $form->setMessages(array(Usuario::FLD_SENHA => [Mensagens::getMensagem('M13')]));
             $isValid = false;
         }
     }
     if ($isValid && $form->isValid()) {
         try {
             if ($usuario = $service->editar($prg)) {
                 $this->flashMessenger()->addSuccessMessage(Mensagens::getMensagem('M09'));
                 return $this->redirect()->toRoute(Rotas::USUARIO);
             } else {
                 $this->flashMessenger()->addErrorMessage(Mensagens::getMensagem('MERRO'));
             }
         } catch (\Exception $e) {
             $escaper = new \Zend\Escaper\Escaper('utf-8');
             $msg = '<br/><br/>' . $escaper->escapeJs(nl2br($e->getMessage()));
             $this->flashMessenger()->addErrorMessage(Mensagens::getMensagem('MERRO') . $msg);
         }
     }
     if ($usuario) {
         $unidadeAtual = $usuario->getUnidade()->getSeqUnidade();
         $unidades = $this->createSelectUnidades($form->get(Usuario::FLD_ORGAO)->getValue());
         $form->get(Usuario::FLD_UNIDADE)->setValueOptions($unidades);
         $form->get(Usuario::FLD_UNIDADE)->setValue($unidadeAtual);
     }
     return array('form' => $form, 'isCorregedor' => $usuarioLogado->isCorregedorGeral());
 }