Advertisement
tripsdoc

Login_Model.php

Dec 12th, 2016
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php if (!defined('BASEPATH'))
  2. {
  3.     exit('No direct script access allowed');
  4. }  
  5. class Login_model extends MY_Model
  6. {
  7.     public $table = 'user';
  8.    
  9.     public function getValidationRules()
  10.     {
  11.         $validationRules = [
  12.             [
  13.                 'field' => 'username',
  14.                 'label' => 'Username',
  15.                 'rules' => 'trim|required'
  16.             ],
  17.             [
  18.                 'field' => 'password',
  19.                 'label' => 'Password',
  20.                 'rules' => 'trim|required'
  21.             ]
  22.         ];
  23.        
  24.         return $validationRules;
  25.     }
  26.    
  27.     public function getDefaultValues()
  28.     {
  29.         return [
  30.             'username' => '',
  31.             'password' => ''
  32.         ];
  33.     }
  34.    
  35.     public function login($input)
  36.     {
  37.         $input->password = md5($input->password);
  38.        
  39.         $user = $this->db->where('username', $input->username)
  40.                          ->where('password', $input->password)
  41.                          ->where('is_blokir', 'n')
  42.                          ->limit(1)
  43.                          ->get($this->table)
  44.                          ->row();
  45.         if (count($user))
  46.         {
  47.             $data = [
  48.                 'username'  => $user->username,
  49.                 'level'     => $user->level,
  50.                 'is_login'  => true
  51.             ];
  52.            
  53.             $this->session->set_userdata($data);
  54.             return true;
  55.         }
  56.        
  57.         return false;
  58.     }
  59.     public function logout()
  60.     {
  61.         $data = [
  62.             'username'  => null,
  63.             'level'     => null,
  64.             'is_login'  => null
  65.         ];
  66.         $this->session->unset_userdata($data);
  67.         $this->session->sess_destroy();
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement