Ejemplo n.º 1
0
 public function indexAction()
 {
     $form = new LoginForm('login');
     $error = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost()->toArray();
             // Criando Storage para gravar sessão da authtenticação
             $sessionStorage = new SessionStorage("geframa_admin");
             $auth = new AuthenticationService();
             $auth->setStorage($sessionStorage);
             // Definindo o SessionStorage para a auth
             $authAdapter = $this->getServiceLocator()->get("Admin\\Auth\\Adapter");
             $authAdapter->setUsername($data['email']);
             $authAdapter->setPassword($data['password']);
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 /*
                                     $user = $auth->getIdentity();
                                     $user = $user['user'];
                                     $sessionStorage->write($user,null);
                 */
                 $sessionStorage->write($auth->getIdentity()['user'], null);
                 return $this->redirect()->toRoute('geframa_admin', array('controller' => 'users'));
             } else {
                 $error = true;
             }
         }
     }
     $view = new ViewModel(array('form' => $form, 'error' => $error));
     $view->setTerminal(true);
     return $view;
 }
Ejemplo n.º 2
0
 /**
  * Faz login do usuário
  *
  * @return \Zend\Http\Response|ViewModel
  */
 public function indexAction()
 {
     $form = new Login();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $service = $this->getServiceLocator()->get('Admin\\Service\\Auth');
             try {
                 $auth = $service->authenticate(array('username' => $data['username'], 'password' => $data['password']));
                 return $this->redirect()->toUrl('/admin');
             } catch (\Exception $e) {
                 $message = "";
                 if ($e->getCode() == 0) {
                     $message = $e->getMessage();
                 } else {
                     $message = "Erro do sistema. Favor contactar o administrador.";
                 }
                 $this->flashMessenger()->addErrorMessage($message);
             }
         }
     }
     return new ViewModel(array('form' => $form));
 }
Ejemplo n.º 3
0
 /**
  * @param array $loginData
  * @return boolean
  */
 public function processLoginForm($loginData = array(), ViewModel $viewModel)
 {
     $result = null;
     $form = new LoginForm();
     if (!empty($loginData)) {
         $form->setData($loginData);
         if ($form->isValid()) {
             $validData = $form->getData();
             $result = $this->doLogin($validData['username'], $validData['password']);
         }
     }
     $viewModel->setVariables(['loginResult' => $result, 'loginForm' => $form]);
 }
Ejemplo n.º 4
0
 public function autenticarAction()
 {
     if (!$this->request->isPost()) {
         $this->redirect()->toRoute('admin', array('controller' => 'login'));
     }
     $form = new Login("login");
     $form->setInputFilter(new LoginValidator());
     // Obtenemos los datos desde el Formulario con POST data:
     $datos = $this->request->getPost();
     $bcrypt = new Bcrypt(array('salt' => 'aleatorio_salt_pruebas_victor', 'cost' => 5));
     $securePass = $bcrypt->create($datos['password']);
     $password = $securePass;
     $nome = $datos['nome'];
     $data = array('nome' => $nome, 'password' => $password);
     $form->setData($data);
     // Validando el form
     if (!$form->isValid()) {
         $this->layout('content/nuevolayout');
         $modelView = new ViewModel(array('form' => $form));
         $modelView->setTemplate('admin/login/index');
         return $modelView;
     }
     $values = $form->getData();
     $email = $values['nome'];
     $clave = $values['password'];
     try {
         $this->login->setMessage('Il nome utente e password non coincidono.', LoginService::NOT_IDENTITY);
         $this->login->setMessage('La password inserita è errata, riprova ', LoginService::INVALID_CREDENTIAL);
         $this->login->setMessage('I campi nome e password non possono essere lasciati vuoti.', LoginService::INVALID_LOGIN);
         $this->layout('content/nuevolayout');
         $this->login->login($email, $clave);
         $this->layout('content/layout');
         //return $this->forward()->dispatch('Admin\Controller\Posterlabs', array('action' => 'index'));
         return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/admin/relatori');
     } catch (\Exception $e) {
         $this->layout()->mensaje = $e->getMessage();
         $mensaje = $this->layout()->mensaje;
         $viewModel = new ViewModel(array('form' => $form, 'mensaje' => $this->layout()->mensaje));
         $viewModel->setTemplate("admin/login/index");
         return $viewModel;
     }
 }