@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | protected function eventFailedLogin($username=null){ |
30 | 30 | |
31 | 31 | if($username !== null){ |
32 | - $this->setPath($username); |
|
32 | + $this->setPath($username); |
|
33 | 33 | } |
34 | 34 | if(!File::exists($this->dir)){ |
35 | 35 | File::makeDirectory($this->dir, 0755, true); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$this->ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
56 | 56 | File::put($this->path,json_encode($content)); |
57 | 57 | if(File::exists($this->path)){ |
58 | - chmod($this->path,0755); |
|
58 | + chmod($this->path,0755); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -84,31 +84,31 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * Check if user is locked |
|
89 | - * |
|
90 | - * @param string $username |
|
91 | - * @return boolean |
|
92 | - */ |
|
87 | + /** |
|
88 | + * Check if user is locked |
|
89 | + * |
|
90 | + * @param string $username |
|
91 | + * @return boolean |
|
92 | + */ |
|
93 | 93 | protected function is_locked($username){ |
94 | 94 | $this->setPath($username); |
95 | 95 | if(File::exists($this->path)) |
96 | 96 | { |
97 | - $get = json_decode(File::get($this->path)); |
|
98 | - if($get->attemps > $this->attemps || $get->attemps == "lock"){ |
|
99 | - return true; |
|
100 | - } else{ |
|
101 | - return false; |
|
102 | - } |
|
97 | + $get = json_decode(File::get($this->path)); |
|
98 | + if($get->attemps > $this->attemps || $get->attemps == "lock"){ |
|
99 | + return true; |
|
100 | + } else{ |
|
101 | + return false; |
|
102 | + } |
|
103 | 103 | } else{ |
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
109 | - * Show message if failed x attemps |
|
110 | - * |
|
111 | - * @return mixed |
|
109 | + * Show message if failed x attemps |
|
110 | + * |
|
111 | + * @return mixed |
|
112 | 112 | */ |
113 | 113 | protected function showMessage(){ |
114 | 114 | if(Session::has(config('irfa.lockout.message_name'))){ |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | protected function lockLogin($username = null){ |
127 | 127 | |
128 | 128 | if(php_sapi_name() == "cli" AND $username != null){ |
129 | - $this->setPath($username); |
|
129 | + $this->setPath($username); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | if(File::exists($this->path)) |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - /** |
|
158 | - * Check ip locked |
|
159 | - * |
|
160 | - * @return boolean |
|
161 | - */ |
|
157 | + /** |
|
158 | + * Check ip locked |
|
159 | + * |
|
160 | + * @return boolean |
|
161 | + */ |
|
162 | 162 | private function checkIp($ip_list,$ip){ |
163 | 163 | if(collect($ip_list)->contains($ip)){ |
164 | 164 | return true; |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | |
169 | 169 | } |
170 | 170 | |
171 | - /** |
|
172 | - * Clear all locked account |
|
173 | - * |
|
174 | - * @return boolean |
|
175 | - */ |
|
171 | + /** |
|
172 | + * Clear all locked account |
|
173 | + * |
|
174 | + * @return boolean |
|
175 | + */ |
|
176 | 176 | public function clear_all(){ |
177 | 177 | $file = new Filesystem(); |
178 | 178 | if($file->cleanDirectory($this->path)){ |
@@ -182,15 +182,15 @@ discard block |
||
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - /** |
|
186 | - * Unlocking account manually. |
|
187 | - * |
|
188 | - * @param string $username |
|
189 | - * @return mixed |
|
190 | - */ |
|
185 | + /** |
|
186 | + * Unlocking account manually. |
|
187 | + * |
|
188 | + * @param string $username |
|
189 | + * @return mixed |
|
190 | + */ |
|
191 | 191 | public function unlock_account($username){ |
192 | 192 | $this->setPath($username); |
193 | - if(File::exists($this->path)){ |
|
193 | + if(File::exists($this->path)){ |
|
194 | 194 | $readf = File::get($this->path); |
195 | 195 | File::delete($this->path); |
196 | 196 | if(php_sapi_name() == "cli"){ |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | } |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * For Testing |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function test_unlock_account($username){ |
219 | 219 | $this->setPath($username); |
220 | - if(File::exists($this->path)){ |
|
220 | + if(File::exists($this->path)){ |
|
221 | 221 | $readf = File::get($this->path); |
222 | 222 | File::delete($this->path); |
223 | 223 | if(php_sapi_name() == "cli"){ |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | } |
229 | 229 | } else{ |
230 | 230 | if(php_sapi_name() == "cli"){ |
231 | - return false; |
|
231 | + return false; |
|
232 | 232 | } else{ |
233 | 233 | return false; |
234 | 234 | } |
235 | 235 | } |
236 | - } |
|
236 | + } |
|
237 | 237 | |
238 | 238 | /** |
239 | 239 | * Check account with details |
@@ -242,59 +242,59 @@ discard block |
||
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | 244 | public function check_account($username){ |
245 | - $this->setPath($username); |
|
246 | - if(File::exists($this->path)){ |
|
247 | - $readf = File::get($this->path); |
|
248 | - if(php_sapi_name() == "cli"){ |
|
245 | + $this->setPath($username); |
|
246 | + if(File::exists($this->path)){ |
|
247 | + $readf = File::get($this->path); |
|
248 | + if(php_sapi_name() == "cli"){ |
|
249 | 249 | |
250 | - return $readf; |
|
250 | + return $readf; |
|
251 | 251 | |
252 | - } else{ |
|
253 | - return $readf; |
|
254 | - } |
|
255 | - } else{ |
|
256 | - if(php_sapi_name() == "cli"){ |
|
257 | - echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
258 | - exit(); |
|
259 | - } else{ |
|
260 | - return false; |
|
261 | - } |
|
262 | - } |
|
252 | + } else{ |
|
253 | + return $readf; |
|
254 | + } |
|
255 | + } else{ |
|
256 | + if(php_sapi_name() == "cli"){ |
|
257 | + echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
|
258 | + exit(); |
|
259 | + } else{ |
|
260 | + return false; |
|
261 | + } |
|
262 | + } |
|
263 | 263 | } |
264 | 264 | |
265 | - /** |
|
266 | - * Locking account manually |
|
267 | - * |
|
268 | - * @param string $username |
|
269 | - * @return mixed |
|
270 | - */ |
|
265 | + /** |
|
266 | + * Locking account manually |
|
267 | + * |
|
268 | + * @param string $username |
|
269 | + * @return mixed |
|
270 | + */ |
|
271 | 271 | public function lock_account($username){ |
272 | 272 | $sapi = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; |
273 | 273 | $this->setPath($username); |
274 | 274 | try{ |
275 | - if(!File::exists($this->dir)){ |
|
276 | - File::makeDirectory($this->dir, 0755, true); |
|
277 | - } |
|
278 | - $login_fail = "lock"; |
|
275 | + if(!File::exists($this->dir)){ |
|
276 | + File::makeDirectory($this->dir, 0755, true); |
|
277 | + } |
|
278 | + $login_fail = "lock"; |
|
279 | 279 | |
280 | - $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => [$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
281 | - File::put($this->path,json_encode($content)); |
|
282 | - if(File::exists($this->path)){ |
|
280 | + $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => [$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
281 | + File::put($this->path,json_encode($content)); |
|
282 | + if(File::exists($this->path)){ |
|
283 | 283 | chmod($this->path,0755); |
284 | - } |
|
285 | - if(php_sapi_name() == "cli"){ |
|
284 | + } |
|
285 | + if(php_sapi_name() == "cli"){ |
|
286 | 286 | return Lang::get('lockoutMessage.user_lock_success')."\n"; |
287 | 287 | |
288 | - } else{ |
|
289 | - return true; |
|
290 | - } |
|
291 | - } catch(\Exception $e){ |
|
292 | - if(php_sapi_name() == "cli"){ |
|
288 | + } else{ |
|
289 | + return true; |
|
290 | + } |
|
291 | + } catch(\Exception $e){ |
|
292 | + if(php_sapi_name() == "cli"){ |
|
293 | 293 | return "error"; |
294 | 294 | |
295 | - } else{ |
|
295 | + } else{ |
|
296 | 296 | return false; |
297 | - } |
|
298 | - } |
|
297 | + } |
|
298 | + } |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace Irfa\Lockout\Func; |
3 | 3 | |
4 | 4 | use Log; |
5 | -use Illuminate\Support\Facades\Request,File,Lang,Session; |
|
5 | +use Illuminate\Support\Facades\Request, File, Lang, Session; |
|
6 | 6 | use Illuminate\Filesystem\Filesystem; |
7 | 7 | use Symfony\Component\Console\Helper\Table; |
8 | 8 | use Irfa\Lockout\Initializing\Variable; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @return void |
18 | 18 | */ |
19 | - public function __construct(){ |
|
19 | + public function __construct() { |
|
20 | 20 | $this->initVar(); |
21 | 21 | } |
22 | 22 | |
@@ -26,36 +26,36 @@ discard block |
||
26 | 26 | * @param string $username |
27 | 27 | * @return void |
28 | 28 | */ |
29 | - protected function eventFailedLogin($username=null){ |
|
29 | + protected function eventFailedLogin($username = null) { |
|
30 | 30 | |
31 | - if($username !== null){ |
|
31 | + if ($username !== null) { |
|
32 | 32 | $this->setPath($username); |
33 | 33 | } |
34 | - if(!File::exists($this->dir)){ |
|
34 | + if (!File::exists($this->dir)) { |
|
35 | 35 | File::makeDirectory($this->dir, 0755, true); |
36 | 36 | } |
37 | 37 | |
38 | - if(!File::exists($this->path)) |
|
38 | + if (!File::exists($this->path)) |
|
39 | 39 | { |
40 | 40 | $login_fail = 1; |
41 | - } else{ |
|
41 | + } else { |
|
42 | 42 | |
43 | 43 | $get = json_decode(File::get($this->path)); |
44 | 44 | $ip_list = $get->ip; |
45 | - if(!$this->checkIp($ip_list,$this->ip)){ |
|
46 | - array_push($ip_list,$this->ip); |
|
45 | + if (!$this->checkIp($ip_list, $this->ip)) { |
|
46 | + array_push($ip_list, $this->ip); |
|
47 | 47 | } |
48 | - if($get->attemps == "lock"){ |
|
48 | + if ($get->attemps == "lock") { |
|
49 | 49 | $login_fail = "lock"; |
50 | - } else{ |
|
50 | + } else { |
|
51 | 51 | $login_fail = $get->attemps+1; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$this->ip],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
56 | - File::put($this->path,json_encode($content)); |
|
57 | - if(File::exists($this->path)){ |
|
58 | - chmod($this->path,0755); |
|
55 | + $content = ['username' => $this->input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$this->ip], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
56 | + File::put($this->path, json_encode($content)); |
|
57 | + if (File::exists($this->path)) { |
|
58 | + chmod($this->path, 0755); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param string $rootNamespace |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - protected function eventCleanLockoutAccount(){ |
|
69 | + protected function eventCleanLockoutAccount() { |
|
70 | 70 | $this->unlock_account($this->input); |
71 | 71 | |
72 | 72 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param string $middleware |
79 | 79 | * @return void |
80 | 80 | */ |
81 | - protected function logging($middleware="WEB"){ |
|
82 | - if(config('irfa.lockout.logging')){ |
|
81 | + protected function logging($middleware = "WEB") { |
|
82 | + if (config('irfa.lockout.logging')) { |
|
83 | 83 | Log::notice($middleware." | Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL); |
84 | 84 | } |
85 | 85 | } |
@@ -90,17 +90,17 @@ discard block |
||
90 | 90 | * @param string $username |
91 | 91 | * @return boolean |
92 | 92 | */ |
93 | - protected function is_locked($username){ |
|
93 | + protected function is_locked($username) { |
|
94 | 94 | $this->setPath($username); |
95 | - if(File::exists($this->path)) |
|
95 | + if (File::exists($this->path)) |
|
96 | 96 | { |
97 | 97 | $get = json_decode(File::get($this->path)); |
98 | - if($get->attemps > $this->attemps || $get->attemps == "lock"){ |
|
98 | + if ($get->attemps > $this->attemps || $get->attemps == "lock") { |
|
99 | 99 | return true; |
100 | - } else{ |
|
100 | + } else { |
|
101 | 101 | return false; |
102 | 102 | } |
103 | - } else{ |
|
103 | + } else { |
|
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | } |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return mixed |
112 | 112 | */ |
113 | - protected function showMessage(){ |
|
114 | - if(Session::has(config('irfa.lockout.message_name'))){ |
|
113 | + protected function showMessage() { |
|
114 | + if (Session::has(config('irfa.lockout.message_name'))) { |
|
115 | 115 | return Session::get(config('irfa.lockout.message_name')); |
116 | 116 | } |
117 | 117 | |
@@ -123,19 +123,19 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return boolean |
125 | 125 | */ |
126 | - protected function lockLogin($username = null){ |
|
126 | + protected function lockLogin($username = null) { |
|
127 | 127 | |
128 | - if(php_sapi_name() == "cli" AND $username != null){ |
|
128 | + if (php_sapi_name() == "cli" AND $username != null) { |
|
129 | 129 | $this->setPath($username); |
130 | 130 | } |
131 | 131 | |
132 | - if(File::exists($this->path)) |
|
132 | + if (File::exists($this->path)) |
|
133 | 133 | { |
134 | 134 | $get = json_decode(File::get($this->path)); |
135 | - if($get->attemps == "lock"){ |
|
135 | + if ($get->attemps == "lock") { |
|
136 | 136 | return true; |
137 | 137 | } |
138 | - if($get->attemps > $this->attemps){ |
|
138 | + if ($get->attemps > $this->attemps) { |
|
139 | 139 | // if($matchip){ |
140 | 140 | // if($this->checkIp($ip_list,$this->ip)){ |
141 | 141 | // return true; |
@@ -146,10 +146,10 @@ discard block |
||
146 | 146 | // else{ |
147 | 147 | return true; |
148 | 148 | // } |
149 | - } else{ |
|
149 | + } else { |
|
150 | 150 | return false; |
151 | 151 | } |
152 | - } else{ |
|
152 | + } else { |
|
153 | 153 | return false; |
154 | 154 | } |
155 | 155 | } |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return boolean |
161 | 161 | */ |
162 | - private function checkIp($ip_list,$ip){ |
|
163 | - if(collect($ip_list)->contains($ip)){ |
|
162 | + private function checkIp($ip_list, $ip) { |
|
163 | + if (collect($ip_list)->contains($ip)) { |
|
164 | 164 | return true; |
165 | - } else{ |
|
165 | + } else { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
@@ -173,11 +173,11 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return boolean |
175 | 175 | */ |
176 | - public function clear_all(){ |
|
176 | + public function clear_all() { |
|
177 | 177 | $file = new Filesystem(); |
178 | - if($file->cleanDirectory($this->path)){ |
|
178 | + if ($file->cleanDirectory($this->path)) { |
|
179 | 179 | return true; |
180 | - } else{ |
|
180 | + } else { |
|
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | } |
@@ -188,23 +188,23 @@ discard block |
||
188 | 188 | * @param string $username |
189 | 189 | * @return mixed |
190 | 190 | */ |
191 | - public function unlock_account($username){ |
|
191 | + public function unlock_account($username) { |
|
192 | 192 | $this->setPath($username); |
193 | - if(File::exists($this->path)){ |
|
193 | + if (File::exists($this->path)) { |
|
194 | 194 | $readf = File::get($this->path); |
195 | 195 | File::delete($this->path); |
196 | - if(php_sapi_name() == "cli"){ |
|
196 | + if (php_sapi_name() == "cli") { |
|
197 | 197 | echo Lang::get('lockoutMessage.user_unlock_success')."\n"; |
198 | 198 | return $readf; |
199 | 199 | |
200 | - } else{ |
|
200 | + } else { |
|
201 | 201 | return true; |
202 | 202 | } |
203 | - } else{ |
|
204 | - if(php_sapi_name() == "cli"){ |
|
203 | + } else { |
|
204 | + if (php_sapi_name() == "cli") { |
|
205 | 205 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
206 | 206 | return false; |
207 | - } else{ |
|
207 | + } else { |
|
208 | 208 | return false; |
209 | 209 | } |
210 | 210 | } |
@@ -215,21 +215,21 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @return mixed |
217 | 217 | */ |
218 | - public function test_unlock_account($username){ |
|
218 | + public function test_unlock_account($username) { |
|
219 | 219 | $this->setPath($username); |
220 | - if(File::exists($this->path)){ |
|
220 | + if (File::exists($this->path)) { |
|
221 | 221 | $readf = File::get($this->path); |
222 | 222 | File::delete($this->path); |
223 | - if(php_sapi_name() == "cli"){ |
|
223 | + if (php_sapi_name() == "cli") { |
|
224 | 224 | return true; |
225 | 225 | |
226 | - } else{ |
|
226 | + } else { |
|
227 | 227 | return true; |
228 | 228 | } |
229 | - } else{ |
|
230 | - if(php_sapi_name() == "cli"){ |
|
229 | + } else { |
|
230 | + if (php_sapi_name() == "cli") { |
|
231 | 231 | return false; |
232 | - } else{ |
|
232 | + } else { |
|
233 | 233 | return false; |
234 | 234 | } |
235 | 235 | } |
@@ -241,22 +241,22 @@ discard block |
||
241 | 241 | * @param string $username |
242 | 242 | * @return mixed |
243 | 243 | */ |
244 | - public function check_account($username){ |
|
244 | + public function check_account($username) { |
|
245 | 245 | $this->setPath($username); |
246 | - if(File::exists($this->path)){ |
|
246 | + if (File::exists($this->path)) { |
|
247 | 247 | $readf = File::get($this->path); |
248 | - if(php_sapi_name() == "cli"){ |
|
248 | + if (php_sapi_name() == "cli") { |
|
249 | 249 | |
250 | 250 | return $readf; |
251 | 251 | |
252 | - } else{ |
|
252 | + } else { |
|
253 | 253 | return $readf; |
254 | 254 | } |
255 | - } else{ |
|
256 | - if(php_sapi_name() == "cli"){ |
|
255 | + } else { |
|
256 | + if (php_sapi_name() == "cli") { |
|
257 | 257 | echo Lang::get('lockoutMessage.user_lock_404')."\n"; |
258 | 258 | exit(); |
259 | - } else{ |
|
259 | + } else { |
|
260 | 260 | return false; |
261 | 261 | } |
262 | 262 | } |
@@ -268,31 +268,31 @@ discard block |
||
268 | 268 | * @param string $username |
269 | 269 | * @return mixed |
270 | 270 | */ |
271 | - public function lock_account($username){ |
|
272 | - $sapi = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; |
|
271 | + public function lock_account($username) { |
|
272 | + $sapi = php_sapi_name() == "cli" ? "lock-via-cli" : "lock-via-web"; |
|
273 | 273 | $this->setPath($username); |
274 | - try{ |
|
275 | - if(!File::exists($this->dir)){ |
|
274 | + try { |
|
275 | + if (!File::exists($this->dir)) { |
|
276 | 276 | File::makeDirectory($this->dir, 0755, true); |
277 | 277 | } |
278 | 278 | $login_fail = "lock"; |
279 | 279 | |
280 | - $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => [$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; |
|
281 | - File::put($this->path,json_encode($content)); |
|
282 | - if(File::exists($this->path)){ |
|
283 | - chmod($this->path,0755); |
|
280 | + $content = ['username' => $this->input, 'attemps' => $login_fail, 'ip' => [$sapi], 'last_attemps' => date("Y-m-d H:i:s", time())]; |
|
281 | + File::put($this->path, json_encode($content)); |
|
282 | + if (File::exists($this->path)) { |
|
283 | + chmod($this->path, 0755); |
|
284 | 284 | } |
285 | - if(php_sapi_name() == "cli"){ |
|
285 | + if (php_sapi_name() == "cli") { |
|
286 | 286 | return Lang::get('lockoutMessage.user_lock_success')."\n"; |
287 | 287 | |
288 | - } else{ |
|
288 | + } else { |
|
289 | 289 | return true; |
290 | 290 | } |
291 | - } catch(\Exception $e){ |
|
292 | - if(php_sapi_name() == "cli"){ |
|
291 | + } catch (\Exception $e) { |
|
292 | + if (php_sapi_name() == "cli") { |
|
293 | 293 | return "error"; |
294 | 294 | |
295 | - } else{ |
|
295 | + } else { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | } |