/** * autentica o usuário */ public function autenticaAction() { if ($this->getRequest()->isPost()) { $this->adapter->setOptions(array('object_manager' => Conn::getConn(), 'identity_class' => 'MyClasses\\Entities\\AclUsuario', 'identity_property' => 'login', 'credential_property' => 'senha')); $this->adapter->setIdentityValue($this->getRequest()->getPost('login')); $this->adapter->setCredentialValue(sha1($this->getRequest()->getPost('senha'))); $result = $this->auth->authenticate($this->adapter); if ($result->isValid()) { $equipes = $result->getIdentity()->getEquipes(); $acl = new Acl(); $acl->addRole(new Role($equipes[0]->getPerfil())); $recursos = $equipes[0]->getRecursos(); foreach ($recursos as $recurso) { if (!$acl->hasResource($recurso->getRecurso())) { /* echo "add recurso: ". $perfil->getPerfil().", ". $recurso->getRecurso()->getRecurso().", ". $recurso->getPermissao(); */ $acl->addResource(new Resource($recurso->getRecurso())); $acl->allow($equipes[0]->getPerfil(), $recurso->getRecurso()); } } $this->auth->getStorage()->write(array($result->getIdentity(), $equipes[0]->getPerfil(), $acl)); $this->layout()->id = $result->getIdentity()->getId(); $this->layout()->nome = $result->getIdentity()->getNome(); return new ViewModel(array('nome' => $result->getIdentity()->getNome())); } else { return new ViewModel(array('erro' => array_pop($result->getMessages()))); } } }
/** * * @return Doctrine\ORM\EntityManager */ public function getEm() { if (null === $this->em) { $this->em = Conn::getConn(); } return $this->em; }
/** * authenticate user */ public function loginAction() { if ($this->getRequest()->isPost()) { $this->adapter->setOptions(array('object_manager' => Conn::getConn(), 'identity_class' => 'MyClasses\\Entities\\Locador', 'identity_property' => 'login', 'credential_property' => 'senha')); $this->adapter->setIdentityValue($this->getRequest()->getPost('login')); $this->adapter->setCredentialValue(sha1($this->getRequest()->getPost('senha'))); $resultado = $this->auth->authenticate($this->adapter); if ($resultado->isValid()) { if ($resultado->getIdentity()->getStatus() == "ativo") { $acl = new Acl(); $this->auth->getStorage()->write(array($resultado->getIdentity(), $resultado->getIdentity()->getNome(), $acl)); $this->layout()->id = $resultado->getIdentity()->getId(); $this->layout()->nome = $resultado->getIdentity()->getNome(); $view = new ViewModel(array('nome' => $resultado->getIdentity()->getNome())); } else { $view = new ViewModel(array('erro' => "Cadastro inativo.<br>Acesse seu e-mail para ativar seu cadastro!")); } } else { $view = new ViewModel(array('erro' => "usuario ou senha invalidos")); } $view->setTerminal(true); return $view; } else { return new ViewModel(); } }
public function pesquisaAction() { if ($this->getRequest()->isPost()) { $pesquisa = $this->getRequest()->getPost("pesquisa"); $query = Conn::getConn()->createQueryBuilder(); $query->select("i")->from("MyClasses\\Entities\\Imovel", "i")->where($query->expr()->orX($query->expr()->like("i.descricao", "'%{$pesquisa}%'"), $query->expr()->like("i.endereco", "'%{$pesquisa}%'"), $query->expr()->like("i.bairro", "'%{$pesquisa}%'"), $query->expr()->like("i.cidade", "'%{$pesquisa}%'"))); $imoveis = $query->getQuery()->getResult(); return new ViewModel(array('imoveis' => $imoveis)); } }
/** * returns all locator visits paged 5 by 5 * @param int $inicio * @param int $limite * @return Paginator */ public function getVisitasPaginadas($inicio = 0, $limite = 5) { $qb = Conn::getConn()->createQueryBuilder(); $qb->select('v')->from('MyClasses\\Entities\\Visita', 'v')->orderBy('v.data')->setMaxResults($limite)->setFirstResult($inicio); $paginador = new Paginator($qb->getQuery()); return $paginador; }