Passed
Push — master ( 9999b7...ae0d11 )
by IRFA
01:17
created
libraries/Auth.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -5,11 +5,11 @@  discard block
 block discarded – undo
5 5
  * @link	https://github.com/irfaardy/codeigniter3-auth
6 6
  * @version	1.2.1
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,17 +19,17 @@  discard block
 block discarded – undo
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(empty($get)){
24
+		if (empty($get)) {
25 25
 			return false;
26 26
 		}
27 27
 		
28
-		if(password_verify($password, $get->password)) {
28
+		if (password_verify($password, $get->password)) {
29 29
 			$user_datas = array(
30 30
 			        'user_id'  => $get->id,
31 31
 			        'logged_in' => TRUE,
32
-			        'login_token' => sha1($get->id.time().mt_rand(1000,9999))
32
+			        'login_token' => sha1($get->id.time().mt_rand(1000, 9999))
33 33
 			);
34 34
 			$this->CI->session->sess_regenerate();
35 35
 			$this->CI->session->set_userdata($user_datas);
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @return boolean
46 46
      */
47
-	public function check(){
48
-		if($this->CI->session->logged_in) {
47
+	public function check() {
48
+		if ($this->CI->session->logged_in) {
49 49
 			return true;
50 50
 		} 
51 51
 
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return mixed
59 59
      */
60
-	public function hakAkses($hakAksesId){
61
-		if($this->user()->level != $hakAksesId) {
62
-			$this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.');
63
-			return redirect(array_key_exists('HTTP_REFERER',$_SERVER)?$_SERVER['HTTP_REFERER']:base_url('/'));
60
+	public function hakAkses($hakAksesId) {
61
+		if ($this->user()->level != $hakAksesId) {
62
+			$this->CI->session->set_flashdata('warning', 'Anda tidak dapat mengakses halaman ini.');
63
+			return redirect(array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : base_url('/'));
64 64
 		} 
65 65
 	}
66 66
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @return mixed
71 71
      */
72
-	public function user(){
73
-		if($this->check()) {
72
+	public function user() {
73
+		if ($this->check()) {
74 74
 			$get = $this->CI->user->getBy(['id' => $this->CI->session->user_id]);
75 75
 			return $get;
76 76
 		}
@@ -83,19 +83,19 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return void
85 85
      */
86
-	public function logout(){
87
-		if(empty($this->CI->input->get('token'))){
86
+	public function logout() {
87
+		if (empty($this->CI->input->get('token'))) {
88 88
 			return redirect($_SERVER['HTTP_REFERER']);
89 89
 		}
90 90
 
91
-		if($this->CI->session->login_token === $this->CI->input->get('token')){
91
+		if ($this->CI->session->login_token === $this->CI->input->get('token')) {
92 92
 			$this->destroy();
93
-		} else{
93
+		} else {
94 94
 			return redirect($_SERVER['HTTP_REFERER']);
95 95
 		}
96 96
 	}
97 97
 
98
-	private function destroy(){
98
+	private function destroy() {
99 99
 		$this->CI->session->sess_regenerate(TRUE);
100 100
 		$this->CI->session->sess_destroy();
101 101
 		return redirect(base_url('login'));
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
 	* Mencegah guest untuk mengakses halaman
105 105
 	* @return void
106 106
 	*/
107
-	public function protect($hakAksesId = null){
108
-		if(!$this->check()){
107
+	public function protect($hakAksesId = null) {
108
+		if (!$this->check()) {
109 109
 			$this->destroy();
110
-		} else{
111
-		   if(!empty($hakAksesId)){
112
-			   	 if(is_array($hakAksesId)){
113
-			   	 	if(!in_array($this->user()->level, $hakAksesId)) { 
114
-						$this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.');
115
-						return /** @scrutinizer ignore-call */ redirect(array_key_exists('HTTP_REFERER',$_SERVER)?$_SERVER['HTTP_REFERER']:/** @scrutinizer ignore-call */base_url('/'));
110
+		} else {
111
+		   if (!empty($hakAksesId)) {
112
+			   	 if (is_array($hakAksesId)) {
113
+			   	 	if (!in_array($this->user()->level, $hakAksesId)) { 
114
+						$this->CI->session->set_flashdata('warning', 'Anda tidak dapat mengakses halaman ini.');
115
+						return /** @scrutinizer ignore-call */ redirect(array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : /** @scrutinizer ignore-call */base_url('/'));
116 116
 					} 
117
-			   	 }else{
118
-					if($this->user()->level != $hakAksesId) {
119
-						$this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.');
120
-						return /** @scrutinizer ignore-call */redirect(array_key_exists('HTTP_REFERER',$_SERVER)?$_SERVER['HTTP_REFERER']:/** @scrutinizer ignore-call */base_url('/'));
117
+			   	 } else {
118
+					if ($this->user()->level != $hakAksesId) {
119
+						$this->CI->session->set_flashdata('warning', 'Anda tidak dapat mengakses halaman ini.');
120
+						return /** @scrutinizer ignore-call */redirect(array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : /** @scrutinizer ignore-call */base_url('/'));
121 121
 					} 
122 122
 				}
123 123
 			}
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -114,7 +114,7 @@
 block discarded – undo
114 114
 						$this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.');
115 115
 						return /** @scrutinizer ignore-call */ redirect(array_key_exists('HTTP_REFERER',$_SERVER)?$_SERVER['HTTP_REFERER']:/** @scrutinizer ignore-call */base_url('/'));
116 116
 					} 
117
-			   	 }else{
117
+			   	 } else{
118 118
 					if($this->user()->level != $hakAksesId) {
119 119
 						$this->CI->session->set_flashdata('warning','Anda tidak dapat mengakses halaman ini.');
120 120
 						return /** @scrutinizer ignore-call */redirect(array_key_exists('HTTP_REFERER',$_SERVER)?$_SERVER['HTTP_REFERER']:/** @scrutinizer ignore-call */base_url('/'));
Please login to merge, or discard this patch.