jamboljack

Login E-Health

Aug 29th, 2019
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.51 KB | None | 0 0
  1. public function login_post()
  2.     {
  3.         $username = trim($this->post('username'));
  4.         $password = trim($this->post('password'));
  5.  
  6.         if ($username == '') {
  7.             $response = [
  8.                 'resp_error' => true,
  9.                 'resp_msg'   => 'Username harus diisi.',
  10.             ];
  11.         } elseif ($password == '') {
  12.             $response = [
  13.                 'resp_error' => true,
  14.                 'resp_msg'   => 'Password harus diisi.',
  15.             ];
  16.         } else {
  17.             $checkUser = $this->db->get_where('ehealth_users', array('user_username' => $username))->row();
  18.             if (count($checkUser) == 0) {
  19.                 $response = [
  20.                     'resp_error' => true,
  21.                     'resp_msg'   => 'Username Tidak Terdaftar.',
  22.                 ];
  23.             } else {
  24.                 if ($checkUser->user_status == 'Non Active') {
  25.                     $response = [
  26.                         'resp_error' => true,
  27.                         'resp_msg'   => 'Akun Anda belum di Aktifkan.',
  28.                     ];
  29.                 } else {
  30.                     $checkLogin = $this->db->get_where('ehealth_users', array('user_username' => $username, 'user_password' => sha1($password), 'user_status' => 'Active'))->row();
  31.                     if (count($checkLogin) == 0) {
  32.                         $response = [
  33.                             'resp_error' => true,
  34.                             'resp_msg'   => 'Password Anda Salah.',
  35.                         ];
  36.                     } else {
  37.                         if ($checkLogin->user_image != '') {
  38.                             $avatar = base_url('icon/' . $checkLogin->user_image);
  39.                         } else {
  40.                             $avatar = base_url('img/no-avatar.png');
  41.                         }
  42.  
  43.                         $response = [
  44.                             'resp_error' => false,
  45.                             'resp_msg'   => 'success',
  46.                             'username'   => trim($checkLogin->user_username),
  47.                             'nama'       => trim($checkLogin->user_name),
  48.                             'no_telp'    => trim($checkLogin->user_phone),
  49.                             'email'      => trim($checkLogin->user_email),
  50.                             'avatar'     => $avatar,
  51.                             'level'      => trim($checkLogin->user_level),
  52.                         ];
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.  
  58.         $this->response($response, 200);
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment