Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Login extends MY_Controller {
- public function __construct(){
- parent::__construct();
- }
- public function index(){
- $data['module'] = 'Login';
- $this->load->view('login',$data);
- }
- public function getAccess(){
- if ($this->session->userdata('logged_in') == TRUE){
- redirect('home');
- }else{
- $username = $this->security->xss_clean($this->input->post('username'));
- $password = $this->security->xss_clean($this->input->post('password'));
- $array = $this->user->login($username,$password);
- if ($array[0] == 0) {
- $this->json(array('error' => 'invalid username or password'));
- }else{
- $data_session = array(
- 'id' => $array[0]['id'],
- 'name' => $array[0]['nombre'],
- 'last_name' => $array[0]['apellido'],
- 'type' => $array[0]['id_perfil'],
- 'logged_in' => TRUE
- );
- $this->session->set_userdata('log',$data_session);
- }
- }
- }
- public function logout(){
- $this->session->sess_destroy();
- redirect('login');
- }
- }
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class MY_Controller extends CI_Controller {
- function __construct(){
- parent::__construct();
- }
- protected function isLogged(){
- if(!$this->session->userdata('log'))
- redirect('login');
- }
- protected function json($array){
- $this->output->set_content_type('application/json')->set_output(json_encode($array));
- }
- protected function getModules(){
- if($this->session->userdata('log')){
- $data = $this->session->userdata('log');
- $menu = array();
- $seccions = $this->module->get_rows();
- foreach ($seccions as $index => $seccion){
- $modules = $this->module->query("SELECT CONCAT('".$seccion['id']."',storelte_modulo.id) AS id,CONCAT('".base_url('assets/img/sidebar')."','/',storelte_modulo.icon) as icon, storelte_modulo.modulo AS value,storelte_modulo.seccion_id,CONCAT('".base_url()."',storelte_modulo.url) AS url FROM storelte_modulo INNER JOIN storelte_modulo_perfil ON storelte_modulo_perfil.modulo_id = storelte_modulo.id WHERE seccion_id = $seccion[id] AND storelte_modulo_perfil.perfiles_id = $data[id] AND storelte_modulo_perfil.STATUS = 1");
- $seccions[$index]['data']= $modules;
- if (!count($seccions[$index]['data']))
- unset($seccions[$index]);
- }
- foreach ($seccions as $item)
- array_push($menu,$item);
- return $menu;
- }
- }
- }
- BASE_URL = "<?= base_url() ?>";
- $('#login-form').submit(function(){
- var username = $('#username').val();
- var password = $('#password').val();
- URL_GET_ACCESS = BASE_URL+"login/getAccess";
- $.ajax({
- url: URL_GET_ACCESS,
- type: 'POST',
- data: {username: username, password: password}
- }).done(function(data){
- console.log(data);
- if (data.error === 'invalid username or password') {
- $('#error').show().delay(2000).fadeOut();
- $('#username,#password').val('');
- }else if(data === '1'){
- window.location.href=BASE_URL+'home';
- }else{
- window.location.href=BASE_URL+'home';
- }
- });
- return false;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement