Skip to content

Commit

Permalink
fixed code style and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarJose123 committed Jun 5, 2023
1 parent c48dcf9 commit cf799a1
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
6 changes: 2 additions & 4 deletions config/filament-lockscreen.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use Filament\Facades\Filament;

return [

/*
Expand Down Expand Up @@ -47,6 +45,6 @@
'segment' => [
'specific_path_only' => false, // if false, then all the request will be blocked by the locker and will be redirected to the authentication page
'segment_needle' => 1, // see the https://laravel.com/api/9.x/Illuminate/Http/Request.html#method_segment
'locked_path' => [] //
]
'locked_path' => [], //
],
];
4 changes: 2 additions & 2 deletions resources/lang/en/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
],
'button' => [
'switch_account' => 'Switch Account',
'submit_label' => 'Sign In'
'submit_label' => 'Sign In',
],
'notification' => [
'title' => 'Login failure',
'message' => 'You have been redirected to the login page after succeeding login failure.',
]
],
];
4 changes: 2 additions & 2 deletions resources/lang/fr/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
'heading' => 'Verouillé',
'button' => [
'switch_account' => 'Changer de compte',
'submit_label' => 'Connexion'
]
'submit_label' => 'Connexion',
],
];
4 changes: 2 additions & 2 deletions resources/lang/ru/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
'heading' => 'Экран блокировки',
'button' => [
'switch_account' => 'Сменить аккаунт',
'submit_label' => 'Войти'
'submit_label' => 'Войти',
],
'notification' => [
'title' => 'Ошибка входа',
'message' => 'Вы были перенаправлены на страницу входа после неудачной попытки входа.',
]
],
];
20 changes: 10 additions & 10 deletions resources/lang/uk/default.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

return [
'heading' => 'Екран блокування',
'button' => [
'switch_account' => 'Змінити обліковий запис',
'submit_label' => 'Увійти'
],
'notification' => [
'title' => 'Помилка входу',
'message' => 'Ви були перенаправлені на сторінку входу після невдалої спроби входу.',
]
];
'heading' => 'Екран блокування',
'button' => [
'switch_account' => 'Змінити обліковий запис',
'submit_label' => 'Увійти',
],
'notification' => [
'title' => 'Помилка входу',
'message' => 'Ви були перенаправлені на сторінку входу після невдалої спроби входу.',
],
];
3 changes: 1 addition & 2 deletions src/FilamentLockscreenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasTranslations()
->hasRoute('web')
;
->hasRoute('web');
}

/**
Expand Down
38 changes: 21 additions & 17 deletions src/Http/Livewire/LockerScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ class LockerScreen extends Component implements HasForms

public ?string $password = '';

private ?string $account_username_field, $account_password_field;
private ?string $account_username_field;

private ?string $account_password_field;

public function mount()
{
session(['lockscreen' => true]);
if(!config('filament-lockscreen.enable_redirect_to'))
if(!session()->has('next') || session()->get('next') === null )
{
if (! config('filament-lockscreen.enable_redirect_to')) {
if (! session()->has('next') || session()->get('next') === null) {
session(['next' => url()->previous()]);
}
}
}

protected function forceLogout()
{
Filament::auth()->logout();
Expand All @@ -50,43 +53,45 @@ public function login()
/*
* Rate Limit
*/
if(config('filament-lockscreen.rate_limit.enable_rate_limit'))
{
if (config('filament-lockscreen.rate_limit.enable_rate_limit')) {
try {
$this->rateLimit(config('filament-lockscreen.rate_limit.rate_limit_max_count', 5));
} catch (TooManyRequestsException $exception) {
if(config('filament-lockscreen.rate_limit.force_logout', false))
{
if (config('filament-lockscreen.rate_limit.force_logout', false)) {
$this->forceLogout();

return redirect(url(config('filament.path')));
}
$this->addError(
'password', __('filament::login.messages.throttled', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]));
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]));

return null;
}
}

if (! Filament::auth()->attempt([
$this->account_username_field => Filament::auth()->user()->{$this->account_username_field},
$this->account_password_field => $data['password']
$this->account_username_field => Filament::auth()->user()->{$this->account_username_field},
$this->account_password_field => $data['password'],
])) {
$this->addError('password', __('filament::login.messages.failed'));

return null;
}



// redirect to the main page and forge the lockscreen session
session()->forget('lockscreen');
session()->regenerate();
if(config('filament-lockscreen.enable_redirect_to')) return redirect()->route(config('filament-lockscreen.redirect_route'));
if (config('filament-lockscreen.enable_redirect_to')) {
return redirect()->route(config('filament-lockscreen.redirect_route'));
}
// store to variable
$url = session()->get('next');
// remove the value
session()->forget('next');

return redirect($url);
}

Expand All @@ -99,7 +104,6 @@ protected function getFormSchema(): array
];
}


public function render()
{
return view('filament-lockscreen::livewire.locker-screen')
Expand Down
11 changes: 5 additions & 6 deletions src/Http/Middleware/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public function handle($request, Closure $next)
* $request->method() === 'GET'
* this will not block the request coming from Livewire page
*/
if(config('filament-lockscreen.segment.specific_path_only', false))
{
if (config('filament-lockscreen.segment.specific_path_only', false)) {
$needle = config('filament-lockscreen.segment.segment_needle', 1);
$blocked_path = config('filament-lockscreen.segment.locked_path');
if ($request->session()->get('lockscreen') && $request->method() === 'GET' && in_array($request->segment($needle),$blocked_path)) return redirect()->route('lockscreenpage');
return $next($request);
if ($request->session()->get('lockscreen') && $request->method() === 'GET' && in_array($request->segment($needle), $blocked_path)) {
return redirect()->route('lockscreenpage');
}

return $next($request);
}


/*
* USE THIS CONDITION IF THE SEGMENT IS DISABLED IN THE CONFIG FILE
* All the request will be blocked
Expand All @@ -39,5 +39,4 @@ public function handle($request, Closure $next)

return $next($request);
}

}

0 comments on commit cf799a1

Please sign in to comment.