Ver Mensaje Individual
  #3 (permalink)  
Antiguo 07/07/2011, 05:22
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 8 meses
Puntos: 292
Respuesta: User controller (loggeo)

Hola MIKTRV !

Se que tengo que re-organizar el codigo.....pero... los $this->session->set_userdata('loggin',TRUE); estan ahi... amigo

Código PHP:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* Controller */
class extends CI_Controller {    
  
    private 
$data=array();
  
    function 
__construct()
    {        
        
parent::__construct();                                          
        
$this->config->set_item('language''spanish');        
        
        
$this->load->library('Blog_lib');
        
$this->data['post_list'] = $this->blog_lib->get_last_entries(3);            
    }
    
    public function 
index(){
    
        
$this->load->library('form_validation');
      
      
$this->form_validation->set_error_delimiters('<div class="error">''</div>');
      
      switch (
$this->input->post('funcion')){ // o 'submit'
      
        
case 'login':
         
$this->form_validation->set_rules('username''Username''trim|required|xss_clean');
         
$this->form_validation->set_rules('password''Password''trim|required');
                         
          if (
$this->form_validation->run() == FALSE){    
            
$this->login();
          }else{           
            
$this->load->model('user_m','',TRUE);
                   
            
$udata $this->user_m->get_user($this->input->post('username'),$this->input->post('password'));         
         
            if ( (isset(
$udata[0]->id)) AND ($udata[0]->id 0) ){
              
$this->session->set_userdata('user_id',$udata[0]->id);     
              
$this->session->set_userdata('loggin',TRUE);

              
$this->data['content']= heading('Ingreso exitoso',2); 
            }else{
              
$this->data['content']= heading('Errado!',2); 
            }            
            
$this->view();                 
          } 
        break;
        
        case 
'logout':                          
        break;
        
        default:
          
$this->form_validation->set_rules('email''Email''trim|required|valid_email');    
          
$this->form_validation->set_rules('password''Password''trim|required|matches[passconf]'); // |md5
          
$this->form_validation->set_rules('passconf''Password confirmacion''trim|required');
          
$this->form_validation->set_rules('username''Username''trim|required|min_length[5]|max_length[12]|xss_clean');
        
            if (
$this->form_validation->run() == FALSE){        
            
$this->signup();                
          }else{        
            
$this->success();        
          }          
          break;
      }    
      
    }
    
    function 
success(){
      
$this->load->model('user_m','',TRUE);
    
      
$this->data['content'] = heading("Bienvenido ".$this->input->post('username').'!',2);             
      
      
// Insert into DB
      
$insert $this->input->post();
      unset (
$insert['submit']);
      unset (
$insert['passconf']);      
      
$this->user_m->insert_user($insert);
       
      
/* podria evitarme los unset() si agrego cada campo en la DB
      excepto aquellos que comiencen con i_ por ejemplo */
      
      // Log in
      
$this->session->set_userdata('logged',TRUE);
      
      
$this->view();  
    }
    
    function 
logout(){
      
// o deberia hacer un ->unset_userdata() ?
      // $this->session->sess_destroy(); ???
      
$this->session->set_userdata('logged',FALSE);
      
      
$this->data['content']= heading('Ud ha salido',2); 
      
$this->view();
    }
    
    function 
signup(){      
      
$this->data['form_file'] = 'application/rentabilizaweb/modules/u/views/signup_form.php';  
      
$this->view();     
    }    
            
    function 
login(){    
      
$this->data['form_file'] = 'application/rentabilizaweb/modules/u/views/login_form.php';
      
$this->view();     
    }        
    
   
/* carga vistas de mi template */    
    
function view($data=null){
      if (
$data==null){
        
$data $this->data;
      }
      
      
$this->load->view('tpl/corp/cuts/tpl_begin.php',$data);    $this->load->view('tpl/corp/cuts/tpl_header.php');
      
//$this->load->view('tpl/corp/cuts/tpl_feature.php');
      
$this->load->view('tpl/corp/cuts/tpl_content.php',$data);
      
$this->load->view('tpl/corp/cuts/tpl_sidebar.php',$data);
      
$this->load->view('tpl/corp/cuts/tpl_footer.php');
    }    

}
Que podra ser ? o sea... el controller 'u' SI me cambia el registro del usuario en la base de datos!
__________________
Salu2!