Untitled

From Ivory Rhinoceros, 8 Months ago, written in Plain Text, viewed 1 times. This paste will go to its last resting place in 1 Second.
URL https://paste.ovh/view/a198e0c4 Embed
Download Paste or View Raw
  1. public function login($username = NULL, $password = NULL)
  2.         {
  3.         if($username === NULL)
  4.         {
  5.             $username = $this->input->post('username');
  6.             $password = $this->input->post('password');
  7.         }
  8.        
  9.         if(empty($username) || empty($password))
  10.             return FALSE;
  11.  
  12.                 $user = $this->get_by(array(
  13.             'username' => $username,
  14.             'password' => $this->hash($password),
  15.         ), TRUE);
  16.        
  17.         // Additional check to login with email
  18.         if(sw_count($user) == 0)
  19.         {
  20.                 $user = $this->get_by(array(
  21.                 'mail' => $username,
  22.                 'password' => $this->hash($password),
  23.             ), TRUE);
  24.         }
  25.        
  26.         if(sw_count($user))
  27.         {  
  28.             if($user->activated == FALSE && ($user->type == 'USER' || $user->type == 'AGENT'))
  29.             {
  30.                 // User and not activated
  31.             }
  32.             else
  33.             {
  34.                 // Update last login data
  35.                 $this->db->where('id', $user->id);
  36.                 $this->db->update($this->_table_name, array('last_login' => date('Y-m-d H:i:s')));
  37.                
  38.                 $profile_image = '';
  39.                 if(!empty($user->repository_id))
  40.                 {
  41.                     $this->_table_name = 'file';
  42.                     $this->_order_by = 'id';
  43.                     // Get profile image from repository
  44.                         $image = $this->get_by(array(
  45.                         'repository_id' => $user->repository_id
  46.                     ), TRUE);
  47.                     $this->_table_name = 'user';
  48.                     $this->_order_by = 'name_surname ';
  49.                     if(sw_count($image))
  50.                     {
  51.                         $profile_image = 'files/thumbnail/'.$image->filename;
  52.                     }
  53.                 }
  54.  
  55.                 // Log in user
  56.                 $data = array(
  57.                     'name_surname'=>$user->name_surname,
  58.                     'username'=>$user->username,
  59.                     'remember'=>(bool)$this->input->post('remember'),
  60.                     'id'=>$user->id,
  61.                     'lang'=>$user->language,
  62.                     'user_namesurname'=>$user->username,
  63.                     'idcode'=>$user->user_idcode,
  64.                     'last_login'=>$user->last_login,
  65.                     'loggedin'=>TRUE,
  66.                     'type'=>$user->type,
  67.                     'profile_image'=>$profile_image,
  68.                     'last_activity'=>time()
  69.                 );
  70.                 $this->session->set_userdata($data);
  71.                
  72.                 $this->user_session_data = $data;
  73.                
  74.                 return TRUE;                
  75.             }
  76.         }
  77.        
  78.         return FALSE;
  79.         }

Reply to "Untitled"

Here you can reply to the paste above

captcha