You've already forked codeigniter_test
first commit
This commit is contained in:
60
application/libraries/auth.php
Normal file
60
application/libraries/auth.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Auth library
|
||||
*
|
||||
* @author Anggy Trisnawan
|
||||
*/
|
||||
class Auth{
|
||||
var $CI = NULL;
|
||||
function __construct()
|
||||
{
|
||||
// get CI's object
|
||||
$this->CI =& get_instance();
|
||||
}
|
||||
// untuk validasi login
|
||||
function do_login($username,$password)
|
||||
{
|
||||
// cek di database, ada ga?
|
||||
$this->CI->db->from('user');
|
||||
$this->CI->db->where('username',$username);
|
||||
$this->CI->db->where('password=("'.$password.'")','',false);
|
||||
$result = $this->CI->db->get();
|
||||
if($result->num_rows() == 0)
|
||||
{
|
||||
// username dan password tsb tidak ada
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ada, maka ambil informasi dari database
|
||||
$userdata = $result->row();
|
||||
$session_data = array(
|
||||
'user_id' => $userdata->user_id,
|
||||
'nama' => $userdata->username,
|
||||
'is_log_in' => TRUE
|
||||
//'level' => $userdata->user_level
|
||||
);
|
||||
// buat session
|
||||
$this->CI->session->set_userdata($session_data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// untuk mengecek apakah user sudah login/belum
|
||||
function is_logged_in()
|
||||
{
|
||||
if($this->CI->session->userdata('user_id') == '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// untuk validasi di setiap halaman yang mengharuskan authentikasi
|
||||
function restrict()
|
||||
{
|
||||
if($this->is_logged_in() == false)
|
||||
{
|
||||
redirect('home/login');
|
||||
}
|
||||
}
|
||||
}
|
10
application/libraries/index.html
Normal file
10
application/libraries/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user