Advertisement
jamboljack

API Login

Nov 26th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. function login_post() {
  2.         $username = trim($this->post('username'));
  3.         $password = trim($this->post('password'));
  4.  
  5.         $this->db->select('*');
  6.         $this->db->from('rtlh_users');
  7.         $this->db->where('user_username', $username);
  8.         $hasiluser = $this->db->get()->row(); // Hasil Cek Username
  9.  
  10.         if ($hasiluser == 0) {
  11.             $response[] = array(    
  12.                                 'resp_error' => TRUE,
  13.                                 'resp_msg'   => 'Username Tidak Terdaftar.'
  14.                             );
  15.         } else {
  16.             $this->db->select('u.*, p.penduduk_nama');
  17.             $this->db->from('rtlh_users u');
  18.             $this->db->join('rtlh_penduduk_dukcapil p', 'u.user_username = p.penduduk_nik');
  19.             $this->db->where('u.user_username', $username);
  20.             $this->db->where('u.user_password', $password);
  21.             $this->db->where('u.user_status', 'Aktif');
  22.             $hasilakun = $this->db->get()->row(); // Hasil Cek Username dan Password
  23.  
  24.             if ($hasiluser == 0) {
  25.                 $response[] = array(  
  26.                                     'resp_error' => TRUE,
  27.                                     'resp_msg'   => 'Username atau Password Salah.'
  28.                                 );
  29.             } else {
  30.                 $response[] = array(
  31.                                     'resp_error' => FALSE,
  32.                                     'resp_msg'   => 'Success',
  33.                                     'username'   => trim($hasilakun->user_username),
  34.                                     'nama'       => trim($hasilakun->penduduk_nama),
  35.                                     'avatar'     => $hasilakun->user_image,
  36.                                     'level'      => $hasilakun->user_level
  37.                                 );
  38.             }
  39.         }
  40.  
  41.         $this->response($response, 200);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement