SHARE
TWEET

Untitled

a guest Jan 26th, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Login extends CI_Controller
  3. {
  4.  
  5. function __construct()
  6. {
  7.     parent::__construct();
  8. }
  9.  
  10. public function index()
  11. {
  12.     if($this->session->is_logued_in)
  13.     {
  14.         redirect(base_url().'dashboard');
  15.     }
  16.     else
  17.     {
  18.         $login = array(
  19.             'title' => 'Powerby - Conviertete en un Aspirante',
  20.             'name' => $this->security->get_csrf_token_name(),
  21.             'hash' => $this->security->get_csrf_hash(),
  22.             'script' => 'login.js'
  23.         );
  24.  
  25.         $this->load->view('includes/header', $login);
  26.         $this->load->view('login', $login);
  27.         $this->load->view('includes/footer', $login);
  28.     }
  29. }
  30.  
  31. public function validate()
  32. {
  33.     $this->load->model('people_model', 'People', TRUE);
  34.  
  35.     $user = $this->input->post('_email');
  36.     $password = $this->input->post('_password');
  37.  
  38.     $profile = $this->People->login($user);
  39.  
  40.     if($profile)
  41.     {
  42.         if (crypt($password, $this->session->_password) === $this->session->_password)
  43.         {
  44.             $this->session->set_userdata('is_logued_in', TRUE);
  45.             $this->index();
  46.         }
  47.         else
  48.         {
  49.             $this->session->unset_userdata('is_logued_in');
  50.             $this->session->set_flashdata('error_login', 'Verifique su contraseña.');
  51.             redirect(base_url().'login', 'refresh');
  52.         }
  53.     }
  54. }
  55.  
  56. public function salir()
  57. {
  58.     $this->session->sess_destroy();
  59.     redirect(base_url().'login', 'refresh');
  60. }
  61. }
  62.    
  63. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  64. class People_model extends CI_Model
  65. {
  66.  
  67. /*protected $id = NULL;
  68. protected $name = NULL;
  69. protected $last_name = NULL;
  70. protected $user = NULL;
  71. protected $password = NULL;*/
  72.  
  73. function __construct()
  74. {
  75.     parent::__construct();
  76. }
  77.  
  78. /*public function __get($property)
  79. {
  80.     if (property_exists($this, $property))
  81.     {
  82.         return $this->$property;
  83.     }
  84. }
  85.  
  86. public function __set($property, $value)
  87. {
  88.     if (property_exists($this, $property))
  89.     {
  90.         $this->$property = $value;
  91.     }
  92.     return $this;
  93. }*/
  94.  
  95. public function login($user)
  96. {
  97.     $this->db->select('*')
  98.              ->from('people p')
  99.              ->join('user u', 'u._id_PPL = p._id')
  100.              ->where('u._user', $user);
  101.  
  102.     $query = $this->db->get();
  103.  
  104.     if($query->num_rows() == 1)
  105.     {
  106.         $this->session->set_userdata($query->row_array());
  107.         return $query->row();
  108.     }
  109.     else
  110.     {
  111.         $this->session->set_flashdata('error_login', 'Verifique su usuario.');
  112.         redirect(base_url().'login', 'refresh');
  113.     }
  114. }
  115.  
  116. public function create($params)
  117. {
  118.     $this->db->set($params);
  119.     return $this->db->insert('people');
  120. }
  121. }
  122.    
  123. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  124. class Dashboard extends CI_Controller
  125. {
  126.  
  127. function __construct()
  128. {
  129.     parent::__construct();
  130. }
  131.  
  132. public function index()
  133. {
  134.     if($this->session->is_logued_in)
  135.     {
  136.         $header = array(
  137.             'title' => 'Powerby - Panel de control '.$this->session->_name.' '.$this->session->_last_name
  138.         );
  139.  
  140.         $this->load->view('includes/header', $header);
  141.  
  142.         $this->load->helper('form');
  143.  
  144.         $dashboard = array(
  145.             'name' => $this->security->get_csrf_token_name(),
  146.             'hash' => $this->security->get_csrf_hash()
  147.         );
  148.         $this->load->view('dashboard', $dashboard);
  149.  
  150.         $modal = array(
  151.             'icon' => 'sign out',
  152.             'modal_title' => 'Cerrando Sesión!',
  153.             'modal_description' => 'Estas a punto de cerrar tu sesión de usuario, estas seguro de querer salir ahora?'
  154.         );
  155.         $this->load->view('includes/modal', $modal);
  156.  
  157.         $footer = array(
  158.             'script' => 'dashboard.js|people.js'
  159.         );
  160.         $this->load->view('includes/footer', $footer);
  161.     }
  162.     else
  163.     {
  164.         $this->session->set_flashdata('sesion_cerrada', 'La sesión fue cerrada, ingrese de nuevo.');
  165.         redirect(base_url().'login', 'refresh');
  166.     }
  167. }
  168. }
  169.    
  170. $config['csrf_protection'] = TRUE;
  171. $config['csrf_token_name'] = 'pbytoken';
  172. $config['csrf_cookie_name'] = 'pbycookie';
  173. $config['csrf_expire'] = 7200;
  174. $config['csrf_regenerate'] = TRUE;
  175. $config['csrf_exclude_uris'] = array();
  176.  
  177. $config['sess_driver'] = 'database';
  178. $config['sess_cookie_name'] = 'pbysession';
  179. $config['sess_expiration'] = 7200;
  180. $config['sess_save_path'] = 'session';
  181. $config['sess_match_ip'] = TRUE;
  182. $config['sess_time_to_update'] = 300;
  183. $config['sess_regenerate_destroy'] = FALSE;
  184.  
  185. $config['cookie_prefix']    = '';
  186. $config['cookie_domain']    = '';
  187. $config['cookie_path']      = '/';
  188. $config['cookie_secure']    = FALSE;
  189. $config['cookie_httponly']  = FALSE;
  190.    
  191. $this->session->set_userdata('is_logued_in', TRUE);
  192. por esto:
  193. $this->session->set_userdata('isloguedin', TRUE);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top