my_usession->logged_in) { redirect(''); //$data['title'] = 'Owner Area'; //$this->load->view('index-siak', $data); } else { //redirect('auth/login'); $this->my_usession->set_userdata('login_resunlaprivate', 0); redirect('auth/login'); } } function anti_xss($source) { $f=stripslashes(strip_tags(htmlspecialchars ($source,ENT_QUOTES))); return $f; } function autoNumber($column,$tbl){ $q = "SELECT max(".$column.")+1 as max FROM ".$tbl."" ; $query = $this->db->query($q); $max = ''; if ($query->num_rows() != 0) { $row = $query->row(); $max=$row->max; } if ($max == null){ $max=0; } return $max; } function nm_field($column,$tbl,$whereb, $wherea){ $q = "SELECT ".$column." as nm FROM ".$tbl." where ".$whereb." = '".$wherea."' " ; $query = $this->db->query($q); $nm= ''; if ($query->num_rows() != 0) { $row = $query->row(); $nm=$row->nm; } return $nm; } public function login_ORI() { if ($this->my_usession->logged_in) { if($this->my_usession->userdata('level_memberunlaprivate') == 1){ redirect('auth/index'); } // else if($this->my_usession->userdata('level_member') === 'Admin'){ // redirect('main/index_owner'); // } } else { $data['title'] = 'User Login'; $this->load->view('auth/login', $data); } } public function ext_is_unique_username() { $cond = array('username' => $_POST['username']); $query = $this->db->get_where('tbl_admin', $cond); if ($query->num_rows() != 0) { echo 0; } else { echo 1; } } public function ext_is_unique_email() { $cond = array('email' => $_POST['email']); $query = $this->db->get_where('tbl_admin', $cond); if ($query->num_rows() != 0) { echo 0; } else { echo 1; } } public function ext_logout() { if($this->my_usession->userdata('level_memberunlaprivate') != '1'){ $this->updatelog(); } $this->my_usession->unset_userdata("user_idunlaprivate"); echo "{success:true}"; } public function ext_login() { $cond = array( 'userid' => $_POST['username'], 'password' => $_POST['password'] ); $query = $this->db->get_where('pengguna', $cond); if ($query->num_rows() != 0) { $row = $query->row(); $this->my_usession->set_userdata('status_aktifasiunlaprivate', $row->idstatus); if($this->my_usession->userdata('status_aktifasiunlaprivate') == 1){ $this->my_usession->set_userdata('user_idunlaprivate', $row->userid); $this->my_usession->set_userdata('usernameunlaprivate', $row->nmlengkap); $this->my_usession->set_userdata('level_memberunlaprivate', $row->idklppengguna); echo "{success:true}"; }else{ echo "{success:false, errors: { reason: 'User tidak aktif!' }}"; } } else { echo "{success:false, errors: { reason: 'User not found !' }}"; } } /* * RH Redefine Login Function * */ public function login() { if ($this->my_usession->logged_in) { if($this->my_usession->userdata('level_memberunlaprivate') == 1){ redirect('auth/index'); } } else { $data['title'] = 'User Login'; if($this->my_usession->userdata('login_resunlaprivate') == 0){ $data['msg'] = 'Masukkan User ID dan Password'; } if($this->my_usession->userdata('login_resunlaprivate') == 1){ $data['msg'] = 'User tidak aktif!'; } if($this->my_usession->userdata('login_resunlaprivate') == 2){ $data['msg'] = 'User atau password salah!'; } $this->load->view('auth/login', $data); } } public function rh_ext_login(){ if($this->input->post('username')=="" || $this->input->post('password')==""){ $this->my_usession->set_userdata('login_resunlaprivate', 0); redirect('auth/login'); } $cond = array( 'userid' => $this->anti_xss($this->input->post('username',TRUE)), //'userid' => $this->input->post('username'), 'password' => $this->anti_xss(base64_encode($this->input->post('password')),TRUE) ); $query = $this->db->get_where('pengguna', $cond); if ($query->num_rows() != 0) { $row = $query->row(); $this->my_usession->set_userdata('status_aktifasiunlaprivate', $row->idstatus); if($this->my_usession->userdata('status_aktifasiunlaprivate') == 1){ $this->my_usession->set_userdata('user_idunlaprivate', $row->userid); $this->my_usession->set_userdata('usernameunlaprivate', $row->nmlengkap); $this->my_usession->set_userdata('level_memberunlaprivate', $row->idklppengguna); $this->my_usession->set_userdata('nm_klpunlaprivate', $this->nm_field('nmklppengguna','klppengguna','idklppengguna',$row->idklppengguna)); $this->my_usession->set_userdata('login_resunlaprivate', 0); if ($row->idklppengguna != '1'){ $this->savelog(); } redirect(''); }else{ $this->my_usession->set_userdata('login_resunlaprivate', 1); redirect('auth/login'); //echo "{success:false, errors: { reason: 'User tidak aktif!' }}"; } } else { $this->my_usession->set_userdata('login_resunlaprivate', 2); redirect('auth/login'); //echo "{success:false, errors: { reason: 'User not found !' }}"; } } function savelog(){ // ISTRA $ipaddress = $_SERVER['REMOTE_ADDR']; $idlog = $this->autoNumber('idlog','logpengguna'); $data = array( 'idlog'=> $idlog, 'userid'=> $_POST['username'], 'ipaddress'=> $ipaddress, ); $this->db->query("CALL SP_insertlog (?,?,?)", $data); $this->my_usession->set_userdata('idlogunlaprivate', $idlog); if($this->db->trans_status()=== FALSE) { $this->db->trans_rollback(); $ret["success"]=false; $ret["message"]="Simpan Data gagal"; } else { $this->db->trans_commit(); $ret["success"]=true; $ret["message"]="Simpan Data Berhasil"; } return $ret; } function updatelog(){ // ISTRA $data = array( 'idlog'=> $this->my_usession->userdata('idlogunlaprivate'), ); $this->db->query("CALL SP_updatelog (?)", $data); if($this->db->trans_status()=== FALSE) { $this->db->trans_rollback(); $ret["success"]=false; $ret["message"]="Simpan Data gagal"; } else { $this->db->trans_commit(); $ret["success"]=true; $ret["message"]="Simpan Data Berhasil"; } return $ret; } }