session->userdata("logged_in") == FALSE){
redirect("user/login", "location");
}else{
redirect("beranda", "location");
}
}
public function login(){
$this->login_validation();
if($this->form_validation->run() == false){
$data['title'] = 'Login UNLASYS';
$this->load->view('user/v_userlogin.php',$data);
}else{
$userid = $this->input->post("user_id");
$userdata = $this->m_login->user_data($userid);
foreach ($userdata->result() as $row){
$uia = $row->id_akun;
$uid = $row->userid;
$level_id = $row->id_otoritas;
$level_name = $row->nama_otoritas;
}
$sessdata = array("uia" => $uia, "uid" => $uid, "level_id" => $level_id, "level_name" => $level_name, "logged_in" => TRUE);
$this->session->set_userdata($sessdata);
$this->_last_login($userid);
redirect("beranda", "location");
}
}
function login_validation(){
$this->form_validation->set_rules("passwd", "Password", "callback_check_akun");
$this->form_validation->set_message("check_akun", "User ID atau Password salah !");
$this->form_validation->set_error_delimiters("
", "
");
}
function check_akun(){
$userid = $this->input->post("user_id");
$passwd = $this->input->post("passwd");
$pass_md5 = md5($passwd);
if ($this->m_login->valid_password($userid, $pass_md5) == FALSE){
return FALSE;
}else{
return TRUE;
}
}
function _last_login($no){
$datestring = "%Y-%m-%d %h:%i:%s";
$now = time();
$logindata = array("lastlogin" => mdate($datestring,$now));
$this->m_login->last_login($no, $logindata);
}
public function logout(){
$this->session->sess_destroy(); // hapus cache lama
redirect("user/login", "location");
}
public function detail(){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$menu["id_menu"] = $menu_id;
$id_akun = $this->session->userdata("uia");
$data["title"] = "Detail Akun UNLASYS";
$data["action_form"] = base_url().'user/ubah_password/'.$id_akun;
$detail_akun = $this->m_login->detail_akun($id_akun);
foreach($detail_akun->result() as $row_akun) {
$data["user_id"] = $row_akun->userid;
//$data["nm_user"] = $row_akun->nama_user;
$data["nm_otoritas"] = $row_akun->nama_otoritas;
}
$data["ubahpass"] = "isi jika mengubah password";
$data["pass"] = "";
$data["konf_pass"] = "";
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('user/v_detail.php');
$this->load->view('v_footer.php');
}
public function ubah_password(){
// Otoritas //
$menu_id = '14';
is_akses($menu_id);
$this->_validation_ubah_akun();
if($this->form_validation->run()==false){
$id_akun = $this->session->userdata("uia");
$data["title"] = "Detail Akun UNLASYS";
$data["action_form"] = base_url().'user/ubah_password/'.$id_akun;
$detail_akun = $this->m_login->detail_akun($id_akun);
foreach($detail_akun->result() as $row_akun) {
$data["user_id"] = $row_akun->userid;
$data["nm_otoritas"]= $row_akun->nama_otoritas;
}
$data["ubahpass"] = "isi jika mengubah password";
$data["pass"] = "";
$data["konf_pass"] = "";
$this->load->view('v_header.php',$data);
$this->load->view('v_menu.php',$menu);
$this->load->view('user/v_detail.php');
$this->load->view('v_footer.php');
}else{
$id_akun = $this->session->userdata("uia");
$pass_new = $this->input->post('pass');
if(empty($pass_new)){
$detail_akun = $this->m_login->detail_akun($id_akun);
foreach($detail_akun->result() as $row_akun) {
$post_pass = $row_akun->passwd;
}
}else{
$post_pass = md5($pass_new);
}
$data = array('passwd' => $post_pass);
$this->m_login->update_akun($id_akun, $data);
$this->session->set_flashdata('success', 'Password Akun berhasil diubah');
redirect('user/detail');
}
}
function _validation_ubah_akun(){
$this->form_validation->set_rules("pass", "Password", "min_length[4]|max_length[20]");
$this->form_validation->set_rules("konf_pass", "Konfirmasi Password", "min_length[4]|max_length[20]|matches[pass]");
$this->form_validation->set_message("max_length", "%s tidak boleh lebih dari %s karakter");
$this->form_validation->set_message("min_length", "%s Minimal %s karakter");
$this->form_validation->set_message("matches", "%s Tidak sama");
$this->form_validation->set_error_delimiters("", "
");
}
}