| @@ -41,15 +41,15 @@ | ||
| 41 | 41 |      {  | 
| 42 | 42 |          $ret = $core->unlock_account($this->argument('username')); | 
| 43 | 43 | $table = new Table($this->output); | 
| 44 | - $read_enc = json_decode( $ret); | |
| 44 | + $read_enc = json_decode($ret); | |
| 45 | 45 | $time = $read_enc->last_attemps; | 
| 46 | 46 | $attemps = $read_enc->attemps; | 
| 47 | 47 | $ip = $read_enc->ip; | 
| 48 | 48 | $table->setRows([ | 
| 49 | - ['<fg=cyan>Login attemps', $attemps], | |
| 50 | - ['<fg=cyan>Last login attemps',$time], | |
| 51 | - ['<fg=cyan>Last IP Address',empty(end($ip))? "unknown":end($ip)], | |
| 52 | -                        ['<fg=cyan>Unlocked at',date('Y-m-d H:i:s', time())], | |
| 49 | + ['<fg=cyan>Login attemps', $attemps], | |
| 50 | + ['<fg=cyan>Last login attemps', $time], | |
| 51 | + ['<fg=cyan>Last IP Address', empty(end($ip)) ? "unknown" : end($ip)], | |
| 52 | +                        ['<fg=cyan>Unlocked at', date('Y-m-d H:i:s', time())], | |
| 53 | 53 | ]); | 
| 54 | 54 | $table->render(); | 
| 55 | 55 |                  // $this->line('<fg=yellow>Valid input is  lock, unlock, and attemps.'); | 
| @@ -41,14 +41,14 @@ | ||
| 41 | 41 |      {  | 
| 42 | 42 |          $ret = $core->check_account($this->argument('username')); | 
| 43 | 43 | $table = new Table($this->output); | 
| 44 | - $read_enc = json_decode( $ret); | |
| 44 | + $read_enc = json_decode($ret); | |
| 45 | 45 | $time = $read_enc->last_attemps; | 
| 46 | 46 | $attemps = $read_enc->attemps; | 
| 47 | 47 | $ip = $read_enc->ip; | 
| 48 | 48 | $table->setRows([ | 
| 49 | - ['<fg=yellow>Login attemps', $attemps], | |
| 50 | - ['<fg=yellow>Last login attemps',$time], | |
| 51 | - ['<fg=yellow>Last IP Address',empty(end($ip))? "unknown":end($ip)],]); | |
| 49 | + ['<fg=yellow>Login attemps', $attemps], | |
| 50 | + ['<fg=yellow>Last login attemps', $time], | |
| 51 | + ['<fg=yellow>Last IP Address', empty(end($ip)) ? "unknown" : end($ip)], ]); | |
| 52 | 52 | $table->render(); | 
| 53 | 53 |                  // $this->line('<fg=yellow>Valid input is  lock, unlock, and attemps.'); | 
| 54 | 54 | |
| @@ -40,14 +40,14 @@ | ||
| 40 | 40 | public function handle(Core $core) | 
| 41 | 41 |      { | 
| 42 | 42 |          $this->line('Cleaning locked user...'); | 
| 43 | -        if($core->clear_all()){ | |
| 43 | +        if ($core->clear_all()) { | |
| 44 | 44 | $table = new Table($this->output); | 
| 45 | 45 | $table->setRows([ | 
| 46 | 46 | ['<fg=green>Locked Account(s) Cleared.'], | 
| 47 | 47 | |
| 48 | 48 | ]); | 
| 49 | 49 | $table->render(); | 
| 50 | -        } else{ | |
| 50 | +        } else { | |
| 51 | 51 |                  $this->line('<fg=red> Clearing failed.'); | 
| 52 | 52 | } | 
| 53 | 53 | } | 
| @@ -40,14 +40,14 @@ | ||
| 40 | 40 | public function handle(Core $core) | 
| 41 | 41 |      { | 
| 42 | 42 |          $this->line('Locking '.$this->argument('username').'...'); | 
| 43 | -        if($core->lock_account($this->argument('username'))!="error"){ | |
| 43 | +        if ($core->lock_account($this->argument('username')) != "error") { | |
| 44 | 44 | $table = new Table($this->output); | 
| 45 | 45 | $table->setRows([ | 
| 46 | 46 |                          ['<fg=green>'.$this->argument('username').' successfully locked.'], | 
| 47 | 47 | |
| 48 | 48 | ]); | 
| 49 | 49 | $table->render(); | 
| 50 | -        } else{ | |
| 50 | +        } else { | |
| 51 | 51 |                  $this->line('<fg=red> Locking failed.'); | 
| 52 | 52 | } | 
| 53 | 53 | } | 
| @@ -56,8 +56,8 @@ discard block | ||
| 56 | 56 |      $conf = config('irfa.lockout'); | 
| 57 | 57 | |
| 58 | 58 |          $this->line('<fg=default>-------------------------------------------------------------------------------'); | 
| 59 | -         $this->line('<fg=yellow>Commands'); | |
| 60 | - $table = new Table($this->output); | |
| 59 | +            $this->line('<fg=yellow>Commands'); | |
| 60 | + $table = new Table($this->output); | |
| 61 | 61 | $table->setRows([ | 
| 62 | 62 |                  ['<fg=cyan>php artisan lockout:lock {username}','<fg=default>locking account'], | 
| 63 | 63 |                  ['<fg=cyan>php artisan lockout:unlock {username}','<fg=default>unlocking account'], | 
| @@ -65,8 +65,8 @@ discard block | ||
| 65 | 65 |                  ['<fg=cyan>php artisan lockout:is-locked {username}','<fg=default>checking account (return boolean)'], | 
| 66 | 66 | ['<fg=cyan>php artisan lockout:clear','<fg=default>unlocking all account']] | 
| 67 | 67 | ); | 
| 68 | - $table->render(); | |
| 69 | -         $this->line('<fg=default>-------------------------------------------------------------------------------'); | |
| 68 | + $table->render(); | |
| 69 | +            $this->line('<fg=default>-------------------------------------------------------------------------------'); | |
| 70 | 70 |          $this->line('<fg=yellow>Configuration'); | 
| 71 | 71 |      foreach($conf as $key => $val){ | 
| 72 | 72 |          if(is_array($val)){ | 
| @@ -79,7 +79,7 @@ discard block | ||
| 79 | 79 | $row[] = ['<fg=default>'.$key,' <fg=cyan>'.$vl]; | 
| 80 | 80 | } | 
| 81 | 81 | // dd($row); | 
| 82 | - $table = new Table($this->output); | |
| 82 | + $table = new Table($this->output); | |
| 83 | 83 | $table->setRows($row); | 
| 84 | 84 | $table->render(); | 
| 85 | 85 | } | 
| @@ -41,7 +41,7 @@ discard block | ||
| 41 | 41 | $this->informasi(); | 
| 42 | 42 | } | 
| 43 | 43 | |
| 44 | -    private function informasi(){ | |
| 44 | +    private function informasi() { | |
| 45 | 45 |              $this->line(" _____      __             _                _               _    | 
| 46 | 46 | |_ _| / _| | | | | | | | 
| 47 | 47 | | | _ __| |_ __ _ ______| | ___ ___| | _____ _ _| |_ | 
| @@ -59,24 +59,24 @@ discard block | ||
| 59 | 59 |           $this->line('<fg=yellow>Commands'); | 
| 60 | 60 | $table = new Table($this->output); | 
| 61 | 61 | $table->setRows([ | 
| 62 | -                ['<fg=cyan>php artisan lockout:lock {username}','<fg=default>locking account'], | |
| 63 | -                ['<fg=cyan>php artisan lockout:unlock {username}','<fg=default>unlocking account'], | |
| 64 | -                ['<fg=cyan>php artisan lockout:check {username}','<fg=default>checking account with details'], | |
| 65 | -                ['<fg=cyan>php artisan lockout:is-locked {username}','<fg=default>checking account (return boolean)'], | |
| 66 | - ['<fg=cyan>php artisan lockout:clear','<fg=default>unlocking all account']] | |
| 62 | +                ['<fg=cyan>php artisan lockout:lock {username}', '<fg=default>locking account'], | |
| 63 | +                ['<fg=cyan>php artisan lockout:unlock {username}', '<fg=default>unlocking account'], | |
| 64 | +                ['<fg=cyan>php artisan lockout:check {username}', '<fg=default>checking account with details'], | |
| 65 | +                ['<fg=cyan>php artisan lockout:is-locked {username}', '<fg=default>checking account (return boolean)'], | |
| 66 | + ['<fg=cyan>php artisan lockout:clear', '<fg=default>unlocking all account']] | |
| 67 | 67 | ); | 
| 68 | 68 | $table->render(); | 
| 69 | 69 |           $this->line('<fg=default>-------------------------------------------------------------------------------'); | 
| 70 | 70 |          $this->line('<fg=yellow>Configuration'); | 
| 71 | -    foreach($conf as $key => $val){ | |
| 72 | -        if(is_array($val)){ | |
| 73 | -            foreach($val as $v){ | |
| 71 | +    foreach ($conf as $key => $val) { | |
| 72 | +        if (is_array($val)) { | |
| 73 | +            foreach ($val as $v) { | |
| 74 | 74 | $vl .= $v.", "; | 
| 75 | 75 | } | 
| 76 | -        } else{ | |
| 76 | +        } else { | |
| 77 | 77 | $vl = $val; | 
| 78 | 78 | } | 
| 79 | - $row[] = ['<fg=default>'.$key,' <fg=cyan>'.$vl]; | |
| 79 | + $row[] = ['<fg=default>'.$key, ' <fg=cyan>'.$vl]; | |
| 80 | 80 | } | 
| 81 | 81 | // dd($row); | 
| 82 | 82 | $table = new Table($this->output); | 
| @@ -45,13 +45,13 @@ | ||
| 45 | 45 |              if($lock){ | 
| 46 | 46 | $table->setRows([ | 
| 47 | 47 | ['<fg=yellow>'.$username.' is locked',]]); | 
| 48 | - $table->render(); | |
| 48 | + $table->render(); | |
| 49 | 49 |                  $this->line('<fg=default>Run <fg=cyan>php artisan lockout:unlock '.$username.'<fg=default> to unlock account.');  | 
| 50 | 50 |              } else{ | 
| 51 | - $table->setRows([ | |
| 51 | + $table->setRows([ | |
| 52 | 52 | ['<fg=green>'.$username.' is unlocked',]]); | 
| 53 | - $table->render(); | |
| 54 | -                         $this->line('<fg=default>Run <fg=cyan>php artisan lockout:lock '.$username.'<fg=default> to lock account.');   | |
| 53 | + $table->render(); | |
| 54 | +                            $this->line('<fg=default>Run <fg=cyan>php artisan lockout:lock '.$username.'<fg=default> to lock account.');   | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 |                  // $this->line('<fg=yellow>Valid input is  lock, unlock, and attemps.'); | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | namespace Irfa\Lockout\Console\Commands; | 
| 4 | 4 | |
| 5 | 5 | use Illuminate\Console\Command; | 
| 6 | -use Irfa\Lockout\Func\Core,Lockout; | |
| 6 | +use Irfa\Lockout\Func\Core, Lockout; | |
| 7 | 7 | use Symfony\Component\Console\Helper\Table; | 
| 8 | 8 | |
| 9 | 9 | class CheckLockedCommands extends Command | 
| @@ -42,14 +42,14 @@ discard block | ||
| 42 | 42 |          $username = $this->argument('username'); | 
| 43 | 43 | $lock = Lockout::isLocked($username); | 
| 44 | 44 | $table = new Table($this->output); | 
| 45 | -            if($lock){ | |
| 45 | +            if ($lock) { | |
| 46 | 46 | $table->setRows([ | 
| 47 | - ['<fg=yellow>'.$username.' is locked',]]); | |
| 47 | + ['<fg=yellow>'.$username.' is locked', ]]); | |
| 48 | 48 | $table->render(); | 
| 49 | 49 |                  $this->line('<fg=default>Run <fg=cyan>php artisan lockout:unlock '.$username.'<fg=default> to unlock account.');  | 
| 50 | -            } else{ | |
| 50 | +            } else { | |
| 51 | 51 | $table->setRows([ | 
| 52 | - ['<fg=green>'.$username.' is unlocked',]]); | |
| 52 | + ['<fg=green>'.$username.' is unlocked', ]]); | |
| 53 | 53 | $table->render(); | 
| 54 | 54 |                           $this->line('<fg=default>Run <fg=cyan>php artisan lockout:lock '.$username.'<fg=default> to lock account.');   | 
| 55 | 55 | } | 
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | } | 
| 17 | 17 | return true; | 
| 18 | 18 | } | 
| 19 | -  	public function isLocked($username){ | |
| 20 | - return $this->is_locked($username); | |
| 21 | - } | |
| 19 | +        public function isLocked($username){ | |
| 20 | + return $this->is_locked($username); | |
| 21 | + } | |
| 22 | 22 |      public function message(){ | 
| 23 | 23 | return $this->showMessage(); | 
| 24 | 24 | } | 
| @@ -6,58 +6,58 @@ | ||
| 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 | -  	public function isLocked($username){ | |
| 19 | +  	public function isLocked($username) { | |
| 20 | 20 | return $this->is_locked($username); | 
| 21 | 21 | } | 
| 22 | -    public function message(){ | |
| 22 | +    public function message() { | |
| 23 | 23 | return $this->showMessage(); | 
| 24 | 24 | } | 
| 25 | -    public function lock($username){ | |
| 26 | -        if(is_array($username)){ | |
| 27 | -            foreach($username as $key){ | |
| 25 | +    public function lock($username) { | |
| 26 | +        if (is_array($username)) { | |
| 27 | +            foreach ($username as $key) { | |
| 28 | 28 | $this->_lock($key); | 
| 29 | 29 | } | 
| 30 | -        } else{ | |
| 30 | +        } else { | |
| 31 | 31 | $this->_lock($username); | 
| 32 | 32 | } | 
| 33 | 33 | return true; | 
| 34 | 34 | } | 
| 35 | 35 |      public function check($username) {	  | 
| 36 | 36 | $ret = null; | 
| 37 | -        if(is_array($username)){ | |
| 38 | -            foreach($username as $key){ | |
| 37 | +        if (is_array($username)) { | |
| 38 | +            foreach ($username as $key) { | |
| 39 | 39 | $get = $this->_check($key); | 
| 40 | -                if(!empty($get)){ | |
| 40 | +                if (!empty($get)) { | |
| 41 | 41 | $ret[] = $get; | 
| 42 | 42 | } | 
| 43 | 43 | } | 
| 44 | -        } else{ | |
| 44 | +        } else { | |
| 45 | 45 | $ret = $this->_check($username); | 
| 46 | 46 | } | 
| 47 | 47 | $ret = json_encode($ret); | 
| 48 | 48 | return json_decode($ret); | 
| 49 | 49 | } | 
| 50 | -    public function clearLocked(){ | |
| 50 | +    public function clearLocked() { | |
| 51 | 51 | return $this->clear_all(); | 
| 52 | 52 | } | 
| 53 | 53 | |
| 54 | -    private function _unlock($username){ | |
| 54 | +    private function _unlock($username) { | |
| 55 | 55 | $this->unlock_account($username); | 
| 56 | 56 | } | 
| 57 | -    private function _lock($username){ | |
| 57 | +    private function _lock($username) { | |
| 58 | 58 | $this->lock_account($username); | 
| 59 | 59 | } | 
| 60 | -    private function _check($username){ | |
| 61 | - return json_decode($this->check_account($username),true); | |
| 60 | +    private function _check($username) { | |
| 61 | + return json_decode($this->check_account($username), true); | |
| 62 | 62 | } | 
| 63 | 63 | } | 
| @@ -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 string | |
| 109 | + * Show message if failed x attemps | |
| 110 | + * | |
| 111 | + * @return string | |
| 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)) | 
| @@ -153,11 +153,11 @@ discard block | ||
| 153 | 153 | } | 
| 154 | 154 | } | 
| 155 | 155 | |
| 156 | - /** | |
| 157 | - * Check ip locked | |
| 158 | - * | |
| 159 | - * @return boolean | |
| 160 | - */ | |
| 156 | + /** | |
| 157 | + * Check ip locked | |
| 158 | + * | |
| 159 | + * @return boolean | |
| 160 | + */ | |
| 161 | 161 |      private function checkIp($ip_list,$ip){ | 
| 162 | 162 |          if(collect($ip_list)->contains($ip)){ | 
| 163 | 163 | return true; | 
| @@ -167,11 +167,11 @@ discard block | ||
| 167 | 167 | |
| 168 | 168 | } | 
| 169 | 169 | |
| 170 | - /** | |
| 171 | - * Clear all locked account | |
| 172 | - * | |
| 173 | - * @return boolean | |
| 174 | - */ | |
| 170 | + /** | |
| 171 | + * Clear all locked account | |
| 172 | + * | |
| 173 | + * @return boolean | |
| 174 | + */ | |
| 175 | 175 |      public function clear_all(){ | 
| 176 | 176 | $file = new Filesystem(); | 
| 177 | 177 |          if($file->cleanDirectory($this->path)){ | 
| @@ -181,15 +181,15 @@ discard block | ||
| 181 | 181 | } | 
| 182 | 182 | } | 
| 183 | 183 | |
| 184 | - /** | |
| 185 | - * Unlocking account manually. | |
| 186 | - * | |
| 187 | - * @param string $username | |
| 188 | - * @return mixed | |
| 189 | - */ | |
| 184 | + /** | |
| 185 | + * Unlocking account manually. | |
| 186 | + * | |
| 187 | + * @param string $username | |
| 188 | + * @return mixed | |
| 189 | + */ | |
| 190 | 190 |      public function unlock_account($username){ | 
| 191 | 191 | $this->setPath($username); | 
| 192 | -         if(File::exists($this->path)){ | |
| 192 | +            if(File::exists($this->path)){ | |
| 193 | 193 | $readf = File::get($this->path); | 
| 194 | 194 | File::delete($this->path); | 
| 195 | 195 |              if(php_sapi_name() == "cli"){ | 
| @@ -207,7 +207,7 @@ discard block | ||
| 207 | 207 | return false; | 
| 208 | 208 | } | 
| 209 | 209 | } | 
| 210 | - } | |
| 210 | + } | |
| 211 | 211 | |
| 212 | 212 | /** | 
| 213 | 213 | * For Testing | 
| @@ -216,7 +216,7 @@ discard block | ||
| 216 | 216 | */ | 
| 217 | 217 |      public function test_unlock_account($username){ | 
| 218 | 218 | $this->setPath($username); | 
| 219 | -         if(File::exists($this->path)){ | |
| 219 | +            if(File::exists($this->path)){ | |
| 220 | 220 | $readf = File::get($this->path); | 
| 221 | 221 | File::delete($this->path); | 
| 222 | 222 |              if(php_sapi_name() == "cli"){ | 
| @@ -227,12 +227,12 @@ discard block | ||
| 227 | 227 | } | 
| 228 | 228 |          } else{ | 
| 229 | 229 |              if(php_sapi_name() == "cli"){ | 
| 230 | - return false; | |
| 230 | + return false; | |
| 231 | 231 |              } else{ | 
| 232 | 232 | return false; | 
| 233 | 233 | } | 
| 234 | 234 | } | 
| 235 | - } | |
| 235 | + } | |
| 236 | 236 | |
| 237 | 237 | /** | 
| 238 | 238 | * Check account with details | 
| @@ -241,59 +241,59 @@ discard block | ||
| 241 | 241 | * @return boolean | 
| 242 | 242 | */ | 
| 243 | 243 |      public function check_account($username){ | 
| 244 | - $this->setPath($username); | |
| 245 | -       if(File::exists($this->path)){ | |
| 246 | - $readf = File::get($this->path); | |
| 247 | -              if(php_sapi_name() == "cli"){ | |
| 244 | + $this->setPath($username); | |
| 245 | +        if(File::exists($this->path)){ | |
| 246 | + $readf = File::get($this->path); | |
| 247 | +                if(php_sapi_name() == "cli"){ | |
| 248 | 248 | |
| 249 | - return $readf; | |
| 249 | + return $readf; | |
| 250 | 250 | |
| 251 | -              } else{ | |
| 252 | - return $readf; | |
| 253 | - } | |
| 254 | -          } else{ | |
| 255 | -              if(php_sapi_name() == "cli"){ | |
| 256 | -                  echo Lang::get('lockoutMessage.user_lock_404')."\n"; | |
| 257 | - exit(); | |
| 258 | -              } else{ | |
| 259 | - return false; | |
| 260 | - } | |
| 261 | - } | |
| 251 | +                } else{ | |
| 252 | + return $readf; | |
| 253 | + } | |
| 254 | +            } else{ | |
| 255 | +                if(php_sapi_name() == "cli"){ | |
| 256 | +                    echo Lang::get('lockoutMessage.user_lock_404')."\n"; | |
| 257 | + exit(); | |
| 258 | +                } else{ | |
| 259 | + return false; | |
| 260 | + } | |
| 261 | + } | |
| 262 | 262 | } | 
| 263 | 263 | |
| 264 | - /** | |
| 265 | - * Locking account manually | |
| 266 | - * | |
| 267 | - * @param string $username | |
| 268 | - * @return boolean | |
| 269 | - */ | |
| 264 | + /** | |
| 265 | + * Locking account manually | |
| 266 | + * | |
| 267 | + * @param string $username | |
| 268 | + * @return boolean | |
| 269 | + */ | |
| 270 | 270 |      public function lock_account($username){ | 
| 271 | 271 | $sapi = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; | 
| 272 | 272 | $this->setPath($username); | 
| 273 | 273 |          try{ | 
| 274 | -          if(!File::exists($this->dir)){ | |
| 275 | - File::makeDirectory($this->dir, 0755, true); | |
| 276 | - } | |
| 277 | - $login_fail = "lock"; | |
| 274 | +            if(!File::exists($this->dir)){ | |
| 275 | + File::makeDirectory($this->dir, 0755, true); | |
| 276 | + } | |
| 277 | + $login_fail = "lock"; | |
| 278 | 278 | |
| 279 | -              $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; | |
| 280 | - File::put($this->path,json_encode($content)); | |
| 281 | -              if(File::exists($this->path)){ | |
| 279 | +                $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; | |
| 280 | + File::put($this->path,json_encode($content)); | |
| 281 | +                if(File::exists($this->path)){ | |
| 282 | 282 | chmod($this->path,0755); | 
| 283 | - } | |
| 284 | -              if(php_sapi_name() == "cli"){ | |
| 283 | + } | |
| 284 | +                if(php_sapi_name() == "cli"){ | |
| 285 | 285 |                  return Lang::get('lockoutMessage.user_lock_success')."\n"; | 
| 286 | 286 | |
| 287 | -              } else{ | |
| 288 | - return true; | |
| 289 | - } | |
| 290 | -          } catch(Exception $e){ | |
| 291 | -              if(php_sapi_name() == "cli"){ | |
| 287 | +                } else{ | |
| 288 | + return true; | |
| 289 | + } | |
| 290 | +            } catch(Exception $e){ | |
| 291 | +                if(php_sapi_name() == "cli"){ | |
| 292 | 292 | return "error"; | 
| 293 | 293 | |
| 294 | -              } else{ | |
| 294 | +                } else{ | |
| 295 | 295 | return false; | 
| 296 | - } | |
| 297 | - } | |
| 296 | + } | |
| 297 | + } | |
| 298 | 298 | } | 
| 299 | 299 | } | 
| 300 | 300 | \ 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 string | 
| 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,32 +123,32 @@ 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){ | |
| 139 | -                    if($matchip){ | |
| 140 | -                    if($this->checkIp($ip_list,$this->ip)){ | |
| 138 | +                if ($get->attemps > $this->attemps) { | |
| 139 | +                    if ($matchip) { | |
| 140 | +                    if ($this->checkIp($ip_list, $this->ip)) { | |
| 141 | 141 | return true; | 
| 142 | -                    } else{ | |
| 142 | +                    } else { | |
| 143 | 143 | return false; | 
| 144 | 144 | } | 
| 145 | -                    } else{ | |
| 145 | +                    } else { | |
| 146 | 146 | return true; | 
| 147 | 147 | } | 
| 148 | -                } else{ | |
| 148 | +                } else { | |
| 149 | 149 | return false; | 
| 150 | 150 | } | 
| 151 | -        } else{ | |
| 151 | +        } else { | |
| 152 | 152 | return false; | 
| 153 | 153 | } | 
| 154 | 154 | } | 
| @@ -158,10 +158,10 @@ discard block | ||
| 158 | 158 | * | 
| 159 | 159 | * @return boolean | 
| 160 | 160 | */ | 
| 161 | -    private function checkIp($ip_list,$ip){ | |
| 162 | -        if(collect($ip_list)->contains($ip)){ | |
| 161 | +    private function checkIp($ip_list, $ip) { | |
| 162 | +        if (collect($ip_list)->contains($ip)) { | |
| 163 | 163 | return true; | 
| 164 | -        } else{ | |
| 164 | +        } else { | |
| 165 | 165 | return false; | 
| 166 | 166 | } | 
| 167 | 167 | |
| @@ -172,11 +172,11 @@ discard block | ||
| 172 | 172 | * | 
| 173 | 173 | * @return boolean | 
| 174 | 174 | */ | 
| 175 | -    public function clear_all(){ | |
| 175 | +    public function clear_all() { | |
| 176 | 176 | $file = new Filesystem(); | 
| 177 | -        if($file->cleanDirectory($this->path)){ | |
| 177 | +        if ($file->cleanDirectory($this->path)) { | |
| 178 | 178 | return true; | 
| 179 | -        } else{ | |
| 179 | +        } else { | |
| 180 | 180 | return false; | 
| 181 | 181 | } | 
| 182 | 182 | } | 
| @@ -187,23 +187,23 @@ discard block | ||
| 187 | 187 | * @param string $username | 
| 188 | 188 | * @return mixed | 
| 189 | 189 | */ | 
| 190 | -    public function unlock_account($username){ | |
| 190 | +    public function unlock_account($username) { | |
| 191 | 191 | $this->setPath($username); | 
| 192 | -         if(File::exists($this->path)){ | |
| 192 | +         if (File::exists($this->path)) { | |
| 193 | 193 | $readf = File::get($this->path); | 
| 194 | 194 | File::delete($this->path); | 
| 195 | -            if(php_sapi_name() == "cli"){ | |
| 195 | +            if (php_sapi_name() == "cli") { | |
| 196 | 196 |                  echo Lang::get('lockoutMessage.user_unlock_success')."\n"; | 
| 197 | 197 | return $readf; | 
| 198 | 198 | |
| 199 | -            } else{ | |
| 199 | +            } else { | |
| 200 | 200 | return true; | 
| 201 | 201 | } | 
| 202 | -        } else{ | |
| 203 | -            if(php_sapi_name() == "cli"){ | |
| 202 | +        } else { | |
| 203 | +            if (php_sapi_name() == "cli") { | |
| 204 | 204 |                  echo Lang::get('lockoutMessage.user_lock_404')."\n"; | 
| 205 | 205 | return false; | 
| 206 | -            } else{ | |
| 206 | +            } else { | |
| 207 | 207 | return false; | 
| 208 | 208 | } | 
| 209 | 209 | } | 
| @@ -214,21 +214,21 @@ discard block | ||
| 214 | 214 | * | 
| 215 | 215 | * @return boolean or json(if cli) | 
| 216 | 216 | */ | 
| 217 | -    public function test_unlock_account($username){ | |
| 217 | +    public function test_unlock_account($username) { | |
| 218 | 218 | $this->setPath($username); | 
| 219 | -         if(File::exists($this->path)){ | |
| 219 | +         if (File::exists($this->path)) { | |
| 220 | 220 | $readf = File::get($this->path); | 
| 221 | 221 | File::delete($this->path); | 
| 222 | -            if(php_sapi_name() == "cli"){ | |
| 222 | +            if (php_sapi_name() == "cli") { | |
| 223 | 223 | return true; | 
| 224 | 224 | |
| 225 | -            } else{ | |
| 225 | +            } else { | |
| 226 | 226 | return true; | 
| 227 | 227 | } | 
| 228 | -        } else{ | |
| 229 | -            if(php_sapi_name() == "cli"){ | |
| 228 | +        } else { | |
| 229 | +            if (php_sapi_name() == "cli") { | |
| 230 | 230 | return false; | 
| 231 | -            } else{ | |
| 231 | +            } else { | |
| 232 | 232 | return false; | 
| 233 | 233 | } | 
| 234 | 234 | } | 
| @@ -240,22 +240,22 @@ discard block | ||
| 240 | 240 | * @param string $username | 
| 241 | 241 | * @return boolean | 
| 242 | 242 | */ | 
| 243 | -    public function check_account($username){ | |
| 243 | +    public function check_account($username) { | |
| 244 | 244 | $this->setPath($username); | 
| 245 | -       if(File::exists($this->path)){ | |
| 245 | +       if (File::exists($this->path)) { | |
| 246 | 246 | $readf = File::get($this->path); | 
| 247 | -              if(php_sapi_name() == "cli"){ | |
| 247 | +              if (php_sapi_name() == "cli") { | |
| 248 | 248 | |
| 249 | 249 | return $readf; | 
| 250 | 250 | |
| 251 | -              } else{ | |
| 251 | +              } else { | |
| 252 | 252 | return $readf; | 
| 253 | 253 | } | 
| 254 | -          } else{ | |
| 255 | -              if(php_sapi_name() == "cli"){ | |
| 254 | +          } else { | |
| 255 | +              if (php_sapi_name() == "cli") { | |
| 256 | 256 |                    echo Lang::get('lockoutMessage.user_lock_404')."\n"; | 
| 257 | 257 | exit(); | 
| 258 | -              } else{ | |
| 258 | +              } else { | |
| 259 | 259 | return false; | 
| 260 | 260 | } | 
| 261 | 261 | } | 
| @@ -267,31 +267,31 @@ discard block | ||
| 267 | 267 | * @param string $username | 
| 268 | 268 | * @return boolean | 
| 269 | 269 | */ | 
| 270 | -    public function lock_account($username){ | |
| 271 | - $sapi = php_sapi_name() == "cli"?"lock-via-cli":"lock-via-web"; | |
| 270 | +    public function lock_account($username) { | |
| 271 | + $sapi = php_sapi_name() == "cli" ? "lock-via-cli" : "lock-via-web"; | |
| 272 | 272 | $this->setPath($username); | 
| 273 | -        try{ | |
| 274 | -          if(!File::exists($this->dir)){ | |
| 273 | +        try { | |
| 274 | +          if (!File::exists($this->dir)) { | |
| 275 | 275 | File::makeDirectory($this->dir, 0755, true); | 
| 276 | 276 | } | 
| 277 | 277 | $login_fail = "lock"; | 
| 278 | 278 | |
| 279 | -              $content = ['username' => $this->input,'attemps' => $login_fail,'ip' => isset($ip_list)?$ip_list:[$sapi],'last_attemps' => date("Y-m-d H:i:s",time())]; | |
| 280 | - File::put($this->path,json_encode($content)); | |
| 281 | -              if(File::exists($this->path)){ | |
| 282 | - chmod($this->path,0755); | |
| 279 | +              $content = ['username' => $this->input, 'attemps' => $login_fail, 'ip' => isset($ip_list) ? $ip_list : [$sapi], 'last_attemps' => date("Y-m-d H:i:s", time())]; | |
| 280 | + File::put($this->path, json_encode($content)); | |
| 281 | +              if (File::exists($this->path)) { | |
| 282 | + chmod($this->path, 0755); | |
| 283 | 283 | } | 
| 284 | -              if(php_sapi_name() == "cli"){ | |
| 284 | +              if (php_sapi_name() == "cli") { | |
| 285 | 285 |                  return Lang::get('lockoutMessage.user_lock_success')."\n"; | 
| 286 | 286 | |
| 287 | -              } else{ | |
| 287 | +              } else { | |
| 288 | 288 | return true; | 
| 289 | 289 | } | 
| 290 | -          } catch(Exception $e){ | |
| 291 | -              if(php_sapi_name() == "cli"){ | |
| 290 | +          } catch (Exception $e) { | |
| 291 | +              if (php_sapi_name() == "cli") { | |
| 292 | 292 | return "error"; | 
| 293 | 293 | |
| 294 | -              } else{ | |
| 294 | +              } else { | |
| 295 | 295 | return false; | 
| 296 | 296 | } | 
| 297 | 297 | } | 
| @@ -31,7 +31,7 @@ discard block | ||
| 31 | 31 | |
| 32 | 32 | $router = $this->app['router']; | 
| 33 | 33 | $this->commands($this->commands); | 
| 34 | -        if(!empty(config('irfa.lockout'))){ | |
| 34 | +        if (!empty(config('irfa.lockout'))) { | |
| 35 | 35 | \Illuminate\Support\Facades\Event::listen( | 
| 36 | 36 | \Illuminate\Auth\Events\Failed::class, | 
| 37 | 37 | LockoutAccount::class | 
| @@ -40,13 +40,13 @@ discard block | ||
| 40 | 40 | \Illuminate\Auth\Events\Authenticated::class, | 
| 41 | 41 | CleanLockoutAccount::class | 
| 42 | 42 | ); | 
| 43 | -                if(in_array('api', config('irfa.lockout.protected_middleware_group'))){ | |
| 43 | +                if (in_array('api', config('irfa.lockout.protected_middleware_group'))) { | |
| 44 | 44 |                      $router->pushMiddlewareToGroup('api', \Irfa\Lockout\Middleware\ApiLockAccount::class); | 
| 45 | 45 | } | 
| 46 | -                if(in_array('web', config('irfa.lockout.protected_middleware_group'))){ | |
| 46 | +                if (in_array('web', config('irfa.lockout.protected_middleware_group'))) { | |
| 47 | 47 |                          $router->pushMiddlewareToGroup('web', \Irfa\Lockout\Middleware\LockAccount::class); | 
| 48 | 48 | } | 
| 49 | -                if(in_array(null, config('irfa.lockout.protected_middleware_group'))){ | |
| 49 | +                if (in_array(null, config('irfa.lockout.protected_middleware_group'))) { | |
| 50 | 50 |                          $router->pushMiddlewareToGroup('web', \Irfa\Lockout\Middleware\LockAccount::class); | 
| 51 | 51 | } | 
| 52 | 52 | } |