Skip to content

Commit

Permalink
Merge pull request #33 from MarJose123/revert-31-feat_custom_auth_fields
Browse files Browse the repository at this point in the history
Revert "Feat custom auth fields"
  • Loading branch information
MarJose123 committed Jun 5, 2023
2 parents c344795 + 433d00c commit 2d326bc
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 58 deletions.
20 changes: 2 additions & 18 deletions config/filament-lockscreen.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
<?php

use Filament\Facades\Filament;

return [

/*
* Lock Screen Icon
*/
'icon' => 'heroicon-s-lock-closed',

/*
| ------------------------------------------------------------------------------------------------
| Table Column Name
| ------------------------------------------------------------------------------------------------
| Change the table column name if your login authentication column is checking on a different field and not on the default field ('email and password') column of the table.
*/
'table_columns' => [
'account_username_field' => 'email',
'account_username' => Filament::auth()->user()->email,
'account_password' => 'password',
],

/* =======================================
* if `enable_redirect_to` is TRUE then after login, it will be redirected to the route setup under `redirect_route`
*/
Expand All @@ -36,7 +21,6 @@
'rate_limit_max_count' => 5, // max count for failure login allowed.
'force_logout' => false,
],

/* =========================
* Path segmentation locking
* e.g., if the segment is enabled then locked_path = ['admin', 'employee']
Expand All @@ -49,6 +33,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: 2 additions & 1 deletion src/FilamentLockscreenServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function configurePackage(Package $package): void
->hasConfigFile()
->hasViews()
->hasTranslations()
->hasRoute('web');
->hasRoute('web')
;
}

/**
Expand Down
34 changes: 16 additions & 18 deletions src/Http/Livewire/LockerScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ class LockerScreen extends Component implements HasForms
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 @@ -47,45 +46,43 @@ 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([
config('filament-lockscreen.table_columns.account_username_field') => config('filament-lockscreen.table_columns.account_username'),
config('filament-lockscreen.table_columns.account_password') => $data['password'],
'email' => Filament::auth()->user()->email,
'password' => $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 @@ -98,6 +95,7 @@ protected function getFormSchema(): array
];
}


public function render()
{
return view('filament-lockscreen::livewire.locker-screen')
Expand Down
11 changes: 6 additions & 5 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');
}

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,4 +39,5 @@ public function handle($request, Closure $next)

return $next($request);
}

}

0 comments on commit 2d326bc

Please sign in to comment.