Passed
Pull Request — master (#2)
by
unknown
03:04
created
src/LockoutAccountServiceProvider.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,13 +35,13 @@
 block discarded – undo
35 35
             CleanLockoutAccount::class
36 36
         );
37 37
 
38
-        if(in_array('api', config('irfa.lockout.protected_middleware_group'))){
38
+        if (in_array('api', config('irfa.lockout.protected_middleware_group'))) {
39 39
             $router->pushMiddlewareToGroup('api', \Irfa\Lockout\Middleware\ApiLockAccount::class);
40 40
         }
41
-        if(in_array('web', config('irfa.lockout.protected_middleware_group'))){
41
+        if (in_array('web', config('irfa.lockout.protected_middleware_group'))) {
42 42
                 $router->pushMiddlewareToGroup('web', \Irfa\Lockout\Middleware\LockAccount::class);
43 43
         }
44
-        if(in_array(null, config('irfa.lockout.protected_middleware_group'))){
44
+        if (in_array(null, config('irfa.lockout.protected_middleware_group'))) {
45 45
                 $router->pushMiddlewareToGroup('web', \Irfa\Lockout\Middleware\LockAccount::class);
46 46
         }
47 47
 
Please login to merge, or discard this patch.
src/Func/Lockout.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,56 +6,56 @@
 block discarded – undo
6 6
 
7 7
 class Lockout extends Core {
8 8
 	
9
-    public function unlock($username){
10
-        if(is_array($username)){
11
-            foreach($username as $key){
9
+    public function unlock($username) {
10
+        if (is_array($username)) {
11
+            foreach ($username as $key) {
12 12
                 $this->_unlock($key);
13 13
             }
14
-        } else{
14
+        } else {
15 15
             $this->_unlock($username);
16 16
         }
17 17
         return true;
18 18
     }
19 19
   
20
-    public function message(){
20
+    public function message() {
21 21
         return $this->showMessage();
22 22
     }
23
-    public function lock($username){
24
-        if(is_array($username)){
25
-            foreach($username as $key){
23
+    public function lock($username) {
24
+        if (is_array($username)) {
25
+            foreach ($username as $key) {
26 26
                     $this->_lock($key);
27 27
             }
28
-        } else{
28
+        } else {
29 29
                 $this->_lock($username);
30 30
         }
31 31
         return true;
32 32
     }
33 33
     public function check($username) {	 
34 34
         $ret = null;
35
-        if(is_array($username)){
36
-            foreach($username as $key){
35
+        if (is_array($username)) {
36
+            foreach ($username as $key) {
37 37
                 $get = $this->_check($key);
38
-                if(!empty($get)){
38
+                if (!empty($get)) {
39 39
                     $ret[] = $get;
40 40
                 }
41 41
             }
42
-        } else{
42
+        } else {
43 43
                 $ret = $this->_check($username);
44 44
         }
45 45
         $ret = json_encode($ret);
46 46
         return json_decode($ret);
47 47
     }
48
-    public function clearLocked(){
48
+    public function clearLocked() {
49 49
         return $this->clear_all();
50 50
     }
51 51
 
52
-    private function _unlock($username){
52
+    private function _unlock($username) {
53 53
         $this->unlock_account($username);
54 54
     }
55
-    private function _lock($username){
55
+    private function _lock($username) {
56 56
         $this->lock_account($username);
57 57
     }
58
-    private function _check($username){
59
-        return json_decode($this->check_account($username),true);
58
+    private function _check($username) {
59
+        return json_decode($this->check_account($username), true);
60 60
     }
61 61
 }
Please login to merge, or discard this patch.
src/Func/Core.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -2,182 +2,182 @@
 block discarded – undo
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
 
9 9
 class Core
10 10
 {
11
-    protected function eventFailedLogin(){
11
+    protected function eventFailedLogin() {
12 12
         $ip = Request::ip();
13 13
         $input = Request::input(config('irfa.lockout.input_name'));
14
-        $matchip= config('irfa.lockout.match_ip') == true ? $ip :null;
14
+        $matchip = config('irfa.lockout.match_ip') == true ? $ip : null;
15 15
         $dir = config('irfa.lockout.lockout_file_path');
16 16
         $path = $dir.md5($input);
17 17
 
18
-        if(!File::exists($dir)){
18
+        if (!File::exists($dir)) {
19 19
                 File::makeDirectory($dir, 0750, true);
20 20
         }
21 21
 
22
-        if(!File::exists($path))
22
+        if (!File::exists($path))
23 23
         {
24 24
             $login_fail = 1;
25
-        } else{
25
+        } else {
26 26
 
27 27
             $get = json_decode(File::get($path));
28 28
             $ip_list = $get->ip;
29
-            if(!$this->checkIp($ip_list,$ip)){
30
-                array_push($ip_list,$ip);
29
+            if (!$this->checkIp($ip_list, $ip)) {
30
+                array_push($ip_list, $ip);
31 31
             }
32
-            if($get->attemps == "lock"){
32
+            if ($get->attemps == "lock") {
33 33
                 $login_fail = "lock";
34
-            } else{
34
+            } else {
35 35
                 $login_fail = $get->attemps+1;
36 36
             }
37 37
         }
38 38
         
39
-            $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())];
40
-            File::put($path,json_encode($content));
39
+            $content = ['username' => $input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$ip], 'last_attemps' => date("Y-m-d H:i:s", time())];
40
+            File::put($path, json_encode($content));
41 41
           
42 42
     }
43
-        protected function eventCleanLockoutAccount(){
43
+        protected function eventCleanLockoutAccount() {
44 44
         $input = Request::input(config('irfa.lockout.input_name'));
45 45
         $this->unlock_account($input);
46 46
           
47 47
     }
48
-    protected function logging($middleware="WEB"){
49
-        if(config('irfa.lockout.logging')){
48
+    protected function logging($middleware = "WEB") {
49
+        if (config('irfa.lockout.logging')) {
50 50
                     Log::notice($middleware." | Login attemps fail | "."username : ".Request::input(config('irfa.lockout.input_name'))." | ipAddress : ".Request::ip()." | userAgent : ".$_SERVER['HTTP_USER_AGENT'].PHP_EOL);
51 51
             }
52 52
     }
53
-    protected function showMessage(){
54
-        if(Session::has(config('irfa.lockout.message_name'))){
53
+    protected function showMessage() {
54
+        if (Session::has(config('irfa.lockout.message_name'))) {
55 55
             return Session::get(config('irfa.lockout.message_name'));
56 56
         }
57 57
 
58 58
         return null;
59 59
     }
60
-    protected function lockLogin(){
60
+    protected function lockLogin() {
61 61
         $ip = Request::ip();
62
-        $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip');
62
+        $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip');
63 63
         $dir = config('irfa.lockout.lockout_file_path');
64 64
         $attemps = config('irfa.lockout.login_attemps');
65 65
         $path = $dir.md5(Request::input('email'));
66
-        if(File::exists($path))
66
+        if (File::exists($path))
67 67
         {
68 68
                 $get = json_decode(File::get($path));
69 69
             // dd($get->attemps.">".$attemps);
70
-                if($get->attemps == "lock"){
70
+                if ($get->attemps == "lock") {
71 71
                 return true;
72 72
                 }
73
-                if($get->attemps > $attemps){
74
-                    if($matchip){
75
-                    if($this->checkIp($ip_list,$ip)){
73
+                if ($get->attemps > $attemps) {
74
+                    if ($matchip) {
75
+                    if ($this->checkIp($ip_list, $ip)) {
76 76
                         return true;
77
-                    } else{
77
+                    } else {
78 78
                         return false;
79 79
                     }
80
-                    } else{
80
+                    } else {
81 81
                     return true;
82 82
                     }
83
-                } else{
83
+                } else {
84 84
                 return false;
85 85
                 }
86
-        } else{
86
+        } else {
87 87
             return false;
88 88
             }
89 89
     }
90
-    private function checkIp($ip_list,$ip){
91
-        if(collect($ip_list)->contains($ip)){
90
+    private function checkIp($ip_list, $ip) {
91
+        if (collect($ip_list)->contains($ip)) {
92 92
             return true;
93
-        } else{
93
+        } else {
94 94
             return false;
95 95
         }
96 96
 
97 97
     }
98
-    public function clear_all(){
98
+    public function clear_all() {
99 99
         $file = new Filesystem();
100
-        if($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))){
100
+        if ($file->cleanDirectory(config('irfa.lockout.lockout_file_path'))) {
101 101
         return true;
102
-        } else{
102
+        } else {
103 103
         return false;
104 104
         }
105 105
     }
106
-    public function unlock_account($username){
106
+    public function unlock_account($username) {
107 107
         $ip = Request::ip();
108
-        $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip');
108
+        $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip');
109 109
         $dir = config('irfa.lockout.lockout_file_path');
110 110
         $attemps = config('irfa.lockout.attemps');
111 111
         $path = $dir.md5($username);
112 112
 
113
-        if(File::exists($path)){
113
+        if (File::exists($path)) {
114 114
             $readf = File::get($path);
115 115
                 File::delete($path);
116
-            if(php_sapi_name() == "cli"){
116
+            if (php_sapi_name() == "cli") {
117 117
                 echo Lang::get('lockoutMessage.user_unlock_success')."\n";
118 118
                 return $readf;
119 119
               
120
-            } else{
120
+            } else {
121 121
                 return true;
122 122
             }
123
-        } else{
124
-            if(php_sapi_name() == "cli"){
123
+        } else {
124
+            if (php_sapi_name() == "cli") {
125 125
                 echo Lang::get('lockoutMessage.user_lock_404')."\n";
126 126
                 exit();
127
-            } else{
127
+            } else {
128 128
                 return false;
129 129
             }
130 130
         }
131 131
         }
132
-        public function check_account($username){
132
+        public function check_account($username) {
133 133
         $dir = config('irfa.lockout.lockout_file_path');
134 134
         $path = $dir.md5($username);
135 135
 
136
-        if(File::exists($path)){
136
+        if (File::exists($path)) {
137 137
             $readf = File::get($path);
138
-            if(php_sapi_name() == "cli"){
138
+            if (php_sapi_name() == "cli") {
139 139
               
140 140
                 return $readf;
141 141
               
142
-            } else{
142
+            } else {
143 143
                 return $readf;
144 144
             }
145
-        } else{
146
-            if(php_sapi_name() == "cli"){
145
+        } else {
146
+            if (php_sapi_name() == "cli") {
147 147
                 echo Lang::get('lockoutMessage.user_lock_404')."\n";
148 148
                 exit();
149
-            } else{
149
+            } else {
150 150
                 return false;
151 151
             }
152 152
         }
153 153
         }
154 154
 
155
-        public function lock_account($username){
156
-        $ip = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web";
155
+        public function lock_account($username) {
156
+        $ip = php_sapi_name() == "cli" ? "lock-via-cli" : "lock-via-web";
157 157
         $input = $username;
158
-        $matchip= empty(config('irfa.lockout.match_ip'))?false:config('irfa.lockout.match_ip');
158
+        $matchip = empty(config('irfa.lockout.match_ip')) ?false:config('irfa.lockout.match_ip');
159 159
         $dir = config('irfa.lockout.lockout_file_path');
160 160
         $attemps = config('irfa.lockout.login_attemps');
161 161
         $path = $dir.md5($username);
162
-        try{
163
-            if(!File::exists($dir)){
162
+        try {
163
+            if (!File::exists($dir)) {
164 164
                 File::makeDirectory($dir, 0750, true);
165 165
             }
166 166
                 $login_fail = "lock";
167 167
           
168
-                $content = ['username' => $input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$ip],'last_attemps' => date("Y-m-d H:i:s",time())];
169
-                File::put($path,json_encode($content));
170
-                if(php_sapi_name() == "cli"){
168
+                $content = ['username' => $input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$ip], 'last_attemps' => date("Y-m-d H:i:s", time())];
169
+                File::put($path, json_encode($content));
170
+                if (php_sapi_name() == "cli") {
171 171
                 return Lang::get('lockoutMessage.user_lock_success')."\n";
172 172
                   
173
-                } else{
173
+                } else {
174 174
                 return true;
175 175
                 }
176
-            } catch(Exception $e){
177
-                if(php_sapi_name() == "cli"){
176
+            } catch (Exception $e) {
177
+                if (php_sapi_name() == "cli") {
178 178
                 return "error";
179 179
                   
180
-                } else{
180
+                } else {
181 181
                 return false;
182 182
                 }
183 183
             }
Please login to merge, or discard this patch.