@@ -13,19 +13,19 @@ discard block |
||
13 | 13 | $this->CI = & get_instance(); |
14 | 14 | } |
15 | 15 | /** |
16 | - * Cek username dan password, jika password yang diinputkan sama dengan di database sama maka login sukses. |
|
17 | - * |
|
18 | - * @param string $username |
|
19 | - * @param string $password |
|
20 | - * @return boolean |
|
21 | - */ |
|
16 | + * Cek username dan password, jika password yang diinputkan sama dengan di database sama maka login sukses. |
|
17 | + * |
|
18 | + * @param string $username |
|
19 | + * @param string $password |
|
20 | + * @return boolean |
|
21 | + */ |
|
22 | 22 | public function verify($username,$password){ |
23 | 23 | $get = $this->CI->user->getBy(['username' => $username]); |
24 | 24 | if(password_verify($password, $get->password)) { |
25 | 25 | $user_datas = array( |
26 | - 'user_id' => $get->id, |
|
27 | - 'logged_in' => TRUE, |
|
28 | - 'login_token' => sha1($get->id.time().mt_rand(1000,9999)) |
|
26 | + 'user_id' => $get->id, |
|
27 | + 'logged_in' => TRUE, |
|
28 | + 'login_token' => sha1($get->id.time().mt_rand(1000,9999)) |
|
29 | 29 | ); |
30 | 30 | $this->CI->session->sess_regenerate(); |
31 | 31 | $this->CI->session->set_userdata($user_datas); |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | } |
37 | 37 | } |
38 | 38 | /** |
39 | - * Cek sudah login apa belum. |
|
40 | - * |
|
41 | - * @return boolean |
|
42 | - */ |
|
39 | + * Cek sudah login apa belum. |
|
40 | + * |
|
41 | + * @return boolean |
|
42 | + */ |
|
43 | 43 | public function check(){ |
44 | 44 | if($this->CI->session->logged_in) { |
45 | 45 | return true; |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * Cek hak akses. |
|
53 | - * |
|
54 | - * @return mixed |
|
55 | - */ |
|
52 | + * Cek hak akses. |
|
53 | + * |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | 56 | public function hakAkses($hakAksesId){ |
57 | 57 | if($this->user()->level != $hakAksesId) { |
58 | 58 | $this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.'); |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | - * Ambil data user sesuai dengan id yang login. |
|
65 | - * |
|
66 | - * @return mixed |
|
67 | - */ |
|
64 | + * Ambil data user sesuai dengan id yang login. |
|
65 | + * |
|
66 | + * @return mixed |
|
67 | + */ |
|
68 | 68 | public function user(){ |
69 | 69 | if($this->check()) { |
70 | 70 | $get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]); |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
78 | - * Keluar dari sesi. |
|
79 | - * |
|
80 | - * @return void |
|
81 | - */ |
|
78 | + * Keluar dari sesi. |
|
79 | + * |
|
80 | + * @return void |
|
81 | + */ |
|
82 | 82 | public function logout(){ |
83 | 83 | if(empty($this->CI->input->get('token'))){ |
84 | 84 | return redirect($_SERVER['HTTP_REFERER']); |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | return redirect(base_url('login')); |
98 | 98 | } |
99 | 99 | /** |
100 | - * Mencegah guest untuk mengakses halaman |
|
101 | - * @return void |
|
102 | - */ |
|
100 | + * Mencegah guest untuk mengakses halaman |
|
101 | + * @return void |
|
102 | + */ |
|
103 | 103 | public function protect(){ |
104 | 104 | if(!$this->check()){ |
105 | 105 | $this->destroy(); |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | * @link https://github.com/irfaardy/codeigniter3-auth |
6 | 6 | * @version 1.1.0 |
7 | 7 | */ |
8 | -class Auth{ |
|
8 | +class Auth { |
|
9 | 9 | |
10 | 10 | private $CI; |
11 | 11 | |
12 | - function __construct(){ |
|
12 | + function __construct() { |
|
13 | 13 | $this->CI = & get_instance(); |
14 | 14 | } |
15 | 15 | /** |
@@ -19,13 +19,13 @@ discard block |
||
19 | 19 | * @param string $password |
20 | 20 | * @return boolean |
21 | 21 | */ |
22 | - public function verify($username,$password){ |
|
22 | + public function verify($username, $password) { |
|
23 | 23 | $get = $this->CI->user->getBy(['username' => $username]); |
24 | - if(password_verify($password, $get->password)) { |
|
24 | + if (password_verify($password, $get->password)) { |
|
25 | 25 | $user_datas = array( |
26 | 26 | 'user_id' => $get->id, |
27 | 27 | 'logged_in' => TRUE, |
28 | - 'login_token' => sha1($get->id.time().mt_rand(1000,9999)) |
|
28 | + 'login_token' => sha1($get->id.time().mt_rand(1000, 9999)) |
|
29 | 29 | ); |
30 | 30 | $this->CI->session->sess_regenerate(); |
31 | 31 | $this->CI->session->set_userdata($user_datas); |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return boolean |
42 | 42 | */ |
43 | - public function check(){ |
|
44 | - if($this->CI->session->logged_in) { |
|
43 | + public function check() { |
|
44 | + if ($this->CI->session->logged_in) { |
|
45 | 45 | return true; |
46 | 46 | } |
47 | 47 | |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function hakAkses($hakAksesId){ |
|
57 | - if($this->user()->level != $hakAksesId) { |
|
58 | - $this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.'); |
|
56 | + public function hakAkses($hakAksesId) { |
|
57 | + if ($this->user()->level != $hakAksesId) { |
|
58 | + $this->CI->session->set_flashdata('warning', 'Anda tidak dapat mengakses halaman ini.'); |
|
59 | 59 | return redirect($_SERVER['HTTP_REFERER']); |
60 | 60 | } |
61 | 61 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @return mixed |
67 | 67 | */ |
68 | - public function user(){ |
|
69 | - if($this->check()) { |
|
68 | + public function user() { |
|
69 | + if ($this->check()) { |
|
70 | 70 | $get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]); |
71 | 71 | return $get; |
72 | 72 | } |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return void |
81 | 81 | */ |
82 | - public function logout(){ |
|
83 | - if(empty($this->CI->input->get('token'))){ |
|
82 | + public function logout() { |
|
83 | + if (empty($this->CI->input->get('token'))) { |
|
84 | 84 | return redirect($_SERVER['HTTP_REFERER']); |
85 | 85 | } |
86 | 86 | |
87 | - if($this->CI->session->login_token === $this->CI->input->get('token')){ |
|
87 | + if ($this->CI->session->login_token === $this->CI->input->get('token')) { |
|
88 | 88 | $this->destroy(); |
89 | - } else{ |
|
89 | + } else { |
|
90 | 90 | return redirect($_SERVER['HTTP_REFERER']); |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - private function destroy(){ |
|
94 | + private function destroy() { |
|
95 | 95 | $this->CI->session->sess_regenerate(TRUE); |
96 | 96 | $this->CI->session->sess_destroy(); |
97 | 97 | return redirect(base_url('login')); |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | * Mencegah guest untuk mengakses halaman |
101 | 101 | * @return void |
102 | 102 | */ |
103 | - public function protect(){ |
|
104 | - if(!$this->check()){ |
|
103 | + public function protect() { |
|
104 | + if (!$this->check()) { |
|
105 | 105 | $this->destroy(); |
106 | 106 | } |
107 | 107 | } |