<commit_before><?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Centro\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Centro\Form\LoginForm;
use Centro\Form\InputFilter\LoginInputFilter;
use Centro\Util\UtilUsuario;
use Centro\Adapter\UsuarioAdapter;

/**
 * Description of UsuarioController
 *
 * @author nando
 */


class UsuarioController extends AbstractActionController
{
    protected $authAdapter;
    
    public function indexAction() {
        //return new ViewModel();
        return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
    }
    
    public function loginAction() {
        $loginInputFilter = new LoginInputFilter();
        $loginForm = new LoginForm($loginInputFilter->getInputFilter());
        
        $request = $this->getRequest();
        $authService = $this->getAuthService();
        
        if($authService->hasIdentity()) {
            $this->redirect()->toRoute('centro');
        }
        
        if($request->isPost()){
            $loginForm->setData($request->getPost());
            
            if($loginForm->isValid()){
                $dataUser = $request->getPost();
                
                $config = $this->getConfig('encrypt');
                $usrUtil = new UtilUsuario($config);
                
                //Password ingresado por el usuario
                $password = $dataUser['password'];
                $password_cifrado = $usrUtil->cifrar($password);
                //Nombre de usuario ingresado
                $usuario = $dataUser['usuario'];
                
                
                $authService->getAdapter()->setDatos($usuario, $password_cifrado);
                $authService->authenticate();
                
                if($authService->hasIdentity()){
                    
                            /*$no_almacenar = 'pin';



                            $usuario = $this->getAuthService()
                           ->getAdapter()
                           ->getResultRowObject(null, $no_almacenar);


                            $this->getAuthService()
                           ->getStorage()
                           ->write($usuario);

                            $usuario = $this->getAuthService()
                           ->getStorage()
                           ->read();*/
                    //var_dump($authService);
                     
                    
                    $this->flashMessenger()->addSuccessMessage('Bienvenido!!!!');
                    return $this->redirect()->toRoute('centro');
                } else {
                    $this->flashMessenger()->addErrorMessage('Usuario/Password incorrecto');
                    return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
                }
            }
        }
        
        //Cambio de layout para el controller
        $this->layout('layout/loginlayout');
        
        return array('form' => $loginForm);
    }
    
    public function logoutAction() {
        $this->getAuthService()->getStorage()->clear();
        return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
    }
    
    public function getAuthService() {<commit_msg>se ha mezclado el arhcivo del usuariocontroller<commit_after><?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace Centro\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Centro\Form\LoginForm;
use Centro\Form\InputFilter\LoginInputFilter;
use Centro\Util\UtilUsuario;
use Centro\Adapter\UsuarioAdapter;

/**
 * Description of UsuarioController
 *
 * @author nando
 */


class UsuarioController extends AbstractActionController
{
    protected $authAdapter;
    
    public function indexAction() {
        //return new ViewModel();
        return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
    }
    
    public function loginAction() {
        $loginInputFilter = new LoginInputFilter();
        $loginForm = new LoginForm($loginInputFilter->getInputFilter());
        
        $request = $this->getRequest();
        $authService = $this->getAuthService();
        
        if($authService->hasIdentity()) {
            $this->redirect()->toRoute('centro');
        }
        
        if($request->isPost()){
            $loginForm->setData($request->getPost());
            
            if($loginForm->isValid()){
                $dataUser = $request->getPost();
                
                $config = $this->getConfig('encrypt');
                $usrUtil = new UtilUsuario($config);
                
                //Password ingresado por el usuario
                $password = $dataUser['password'];
                $password_cifrado = $usrUtil->cifrar($password);
                //Nombre de usuario ingresado
                $usuario = $dataUser['usuario'];
                
                
                $authService->getAdapter()->setDatos($usuario, $password_cifrado);
                $authService->authenticate();
                
                if($authService->hasIdentity()){

                    //Datos a omitir 
                    $omitirColumna = array('password','<PASSWORD>');
                    
                    //Obtengo los datos que se almacenaran en la sesion
                    $usuario = $authService->getAdapter()->getResultRowObject(null, $omitirColumna);
                    
                    //Almaceno los datos de la sesion
                    $authService->getStorage()->write($usuario);
                    
                    $this->flashMessenger()->addSuccessMessage('Bienvenido');

                    return $this->redirect()->toRoute('centro');
                } else {
                    $this->flashMessenger()->addErrorMessage('Usuario/Password incorrecto');
                    return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
                }
            }
        }
        
        //Cambio de layout para el controller
        $this->layout('layout/loginlayout');
        
        return array('form' => $loginForm);
    }
    
    public function logoutAction() {
        $this->getAuthService()->getStorage()->clear();
        return $this->redirect()->toRoute('usuario/default', array('action' => 'login'));
    }
    
    public function getAuthService() {
{'fraction_non_alphanumeric': 0.1271564544913742, 'fraction_numerical': 0.0, 'mean_word_length': 1.7561475409836065, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4150761', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1678, 'n_words': 319}