Skip to content

Commit

Permalink
wip login
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-the-Diamond committed Sep 9, 2024
1 parent 457431b commit a82f9b2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"pest_2.35.1","defects":[],"times":{"Tests\\Unit\\ExampleTest::testThatTrueIsTrue":0.028,"P\\Packages\\core\\tests\\Unit\\ExampleTest::__pest_evaluable_core_example_unit":0.089,"Tests\\Feature\\LandingPageTest::testHealthyResponse":0.169,"Tests\\Feature\\LandingPageTest::testContainsWelcome":0.008,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_healthy_response":0.008,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_redirects_to_login":1.046,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_contains_Sign_in":1.141,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_healthy_response":1.077,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_redirects_to_login":1.04,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_contains_Sign_in":1.165,"P\\Packages\\core\\tests\\Feature\\ExampleTest::__pest_evaluable_core_example_feature":0}}
{"version":"pest_2.35.1","defects":[],"times":{"Tests\\Unit\\ExampleTest::testThatTrueIsTrue":0.019,"P\\Packages\\core\\tests\\Unit\\ExampleTest::__pest_evaluable_core_example_unit":0.088,"Tests\\Feature\\LandingPageTest::testHealthyResponse":0.25,"Tests\\Feature\\LandingPageTest::testContainsWelcome":0.011,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_healthy_response":0.008,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_redirects_to_login":0.989,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_contains_Sign_in":7.243,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_healthy_response":0.918,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_redirects_to_login":0.886,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_contains_Sign_in":1.296,"P\\Packages\\core\\tests\\Feature\\ExampleTest::__pest_evaluable_core_example_feature":0}}
1 change: 1 addition & 0 deletions config/press.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,4 +1301,5 @@
],
],
],
'ip_whitelist' => config('user-session.whitelisted_ips'),
];
53 changes: 37 additions & 16 deletions packages/press/src/Services/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,24 @@ protected function getLoginFormComponent(): Component

public function authenticate(): Redirector|RedirectResponse|LoginResponse|null
{
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
Notification::make()
->title(__('filament-panels::pages/auth/login.notifications.throttled.title', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]))
->body(array_key_exists('body', __('filament-panels::pages/auth/login.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/login.notifications.throttled.body', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => $exception->minutesUntilAvailable,
]) : null)
->danger()
->send();

return null;
if (! $this->isWhitelisted()) {
try {
$this->rateLimit(5);
} catch (TooManyRequestsException $exception) {
Notification::make()
->title(__('filament-panels::pages/auth/login.notifications.throttled.title', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => ceil($exception->secondsUntilAvailable / 60),
]))
->body(array_key_exists('body', __('filament-panels::pages/auth/login.notifications.throttled') ?: []) ? __('filament-panels::pages/auth/login.notifications.throttled.body', [
'seconds' => $exception->secondsUntilAvailable,
'minutes' => $exception->minutesUntilAvailable,
]) : null)
->danger()
->send();

return null;
}
}

$guardName = Filament::getAuthGuard();
Expand Down Expand Up @@ -264,4 +266,23 @@ protected function hasFullWidthFormActions(): bool
{
return true;
}

private function isWhitelisted(): bool
{
$ipAddress = request()->ip();

$ipWhiteList = config('press.ip_whitelist');

if (isset($ipWhiteList) && ! empty($ipWhiteList)) {

if (is_array($ipWhiteList) && in_array($ipAddress, $ipWhiteList)) {
return true;
}
if ($ipWhiteList === $ipAddress) {
return true;
}
}

return false;
}
}
19 changes: 19 additions & 0 deletions packages/user/src/Services/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,23 @@ protected function hasFullWidthFormActions(): bool
{
return true;
}

private function isWhitelisted(): bool

Check failure on line 238 in packages/user/src/Services/Login.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Moox\User\Services\Login::isWhitelisted() is unused.
{
$ipAddress = request()->ip();

$ipWhiteList = config('user.ip_whitelist');

if (isset($ipWhiteList) && ! empty($ipWhiteList)) {

if (is_array($ipWhiteList) && in_array($ipAddress, $ipWhiteList)) {
return true;
}
if ($ipWhiteList === $ipAddress) {
return true;
}
}

return false;
}
}

0 comments on commit a82f9b2

Please sign in to comment.