@@ -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 | - * Ambil data user sesuai dengan id yang login. |
|
53 | - * |
|
54 | - * @return mixed |
|
55 | - */ |
|
52 | + * Ambil data user sesuai dengan id yang login. |
|
53 | + * |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | 56 | public function user(){ |
57 | 57 | if($this->check()) { |
58 | 58 | $get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]); |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | - * Keluar dari sesi. |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
66 | + * Keluar dari sesi. |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | 70 | public function logout(){ |
71 | 71 | if(empty($this->CI->input->get('token'))){ |
72 | 72 | return redirect($_SERVER['HTTP_REFERER']); |
@@ -85,9 +85,9 @@ discard block |
||
85 | 85 | return redirect(base_url('login')); |
86 | 86 | } |
87 | 87 | /** |
88 | - * Mencegah guest untuk mengakses halaman |
|
89 | - * @return void |
|
90 | - */ |
|
88 | + * Mencegah guest untuk mengakses halaman |
|
89 | + * @return void |
|
90 | + */ |
|
91 | 91 | public function protect(){ |
92 | 92 | if(!$this->check()){ |
93 | 93 | $this->destroy(); |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | * @link https://github.com/irfaardy/ci3-login |
6 | 6 | * @version 1.0.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,8 +53,8 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function user(){ |
|
57 | - if($this->check()) { |
|
56 | + public function user() { |
|
57 | + if ($this->check()) { |
|
58 | 58 | $get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]); |
59 | 59 | return $get; |
60 | 60 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - public function logout(){ |
|
71 | - if(empty($this->CI->input->get('token'))){ |
|
70 | + public function logout() { |
|
71 | + if (empty($this->CI->input->get('token'))) { |
|
72 | 72 | return redirect($_SERVER['HTTP_REFERER']); |
73 | 73 | } |
74 | 74 | |
75 | - if($this->CI->session->login_token === $this->CI->input->get('token')){ |
|
75 | + if ($this->CI->session->login_token === $this->CI->input->get('token')) { |
|
76 | 76 | $this->destroy(); |
77 | - } else{ |
|
77 | + } else { |
|
78 | 78 | return redirect($_SERVER['HTTP_REFERER']); |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - private function destroy(){ |
|
82 | + private function destroy() { |
|
83 | 83 | $this->CI->session->sess_regenerate(TRUE); |
84 | 84 | $this->CI->session->sess_destroy(); |
85 | 85 | return redirect(base_url('login')); |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * Mencegah guest untuk mengakses halaman |
89 | 89 | * @return void |
90 | 90 | */ |
91 | - public function protect(){ |
|
92 | - if(!$this->check()){ |
|
91 | + public function protect() { |
|
92 | + if (!$this->check()) { |
|
93 | 93 | $this->destroy(); |
94 | 94 | } |
95 | 95 | } |