Advertisement
jamboljack

Login SIMPEL

Jan 26th, 2019
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.26 KB | None | 0 0
  1. public function login_post()
  2.     {
  3.         $username    = trim($this->post('username'));
  4.         $password    = trim($this->post('password'));
  5.         $tokenDevice = trim($this->post('tokenDevice'));
  6.  
  7.         if ($username == '') {
  8.             $response = [
  9.                 'resp_error' => true,
  10.                 'resp_msg'   => 'Username harap diisi.',
  11.             ];
  12.         } elseif ($password == '') {
  13.             $response = [
  14.                 'resp_error' => true,
  15.                 'resp_msg'   => 'Password harap diisi.',
  16.             ];
  17.         } elseif ($tokenDevice == '') {
  18.             $response = [
  19.                 'resp_error' => true,
  20.                 'resp_msg'   => 'Token Device kosong.',
  21.             ];
  22.         } else {
  23.             // Check Username
  24.             $this->db->select('*');
  25.             $this->db->from('lemlit_users');
  26.             $this->db->where('user_username', $username);
  27.             $this->db->where('user_active', 'Active');
  28.             $checkuser = $this->db->get()->row();
  29.             if (count($checkuser) == 0) {
  30.                 $response = [
  31.                     'resp_error' => true,
  32.                     'resp_msg'   => 'Username Tidak Terdaftar.',
  33.                 ];
  34.             } else {
  35.                 $this->db->select('u.*, l.lecture_id, l.position_id, l.lecture_review');
  36.                 $this->db->from('lemlit_users u');
  37.                 $this->db->join('lemlit_lecture l', 'u.user_username=l.user_username', 'left');
  38.                 $this->db->where('u.user_username', $username);
  39.                 $this->db->where('u.user_password', sha1($password));
  40.                 $this->db->where('u.user_active', 'Active');
  41.                 $checkaccount = $this->db->get()->row();
  42.  
  43.                 if (count($checkaccount) == 0) {
  44.                     $response = [
  45.                         'resp_error' => true,
  46.                         'resp_msg'   => 'Password Anda Salah.',
  47.                     ];
  48.                 } else {
  49.                     // Otomatis Update Device
  50.                     $data = array(
  51.                         'device_id' => $tokenDevice,
  52.                     );
  53.  
  54.                     $this->db->where('user_username', $username);
  55.                     $this->db->update('lemlit_users', $data);
  56.  
  57.                     if ($checkaccount->user_avatar != '') {
  58.                         $avatar = base_url('img/icon/' . $checkaccount->user_avatar);
  59.                     } else {
  60.                         $avatar = base_url('img/user.png');
  61.                     }
  62.  
  63.                     $response = [
  64.                         'resp_error' => false,
  65.                         'resp_msg'   => 'success',
  66.                         'username'   => trim($checkaccount->user_username),
  67.                         'nama'       => trim($checkaccount->user_name),
  68.                         'email'      => trim($checkaccount->user_email),
  69.                         'avatar'     => $avatar,
  70.                         'level'      => trim($checkaccount->user_level),
  71.                         'lecture_id' => trim($checkaccount->lecture_id),
  72.                         'reviewer'   => ($checkaccount->lecture_review == 0 ? 'Tidak' : 'Ya'),
  73.                     ];
  74.                 }
  75.             }
  76.         }
  77.  
  78.         $this->response($response, 200);
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement