Return stock of cancelled maintenance, throttle the PIN page's password
Cancelling a maintenance record now reverses the stock it used, through Inventory's new ReverseMaintenanceStockUse behind the MaintenanceMaterials port, in the same transaction as the cancellation. The PIN page allows 5 wrong current passwords a minute per user, as the login form does, so a signed-in session cannot be used to guess the password. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
use App\Modules\Users\Application\UseCases\LoginPins;
|
||||
use App\Modules\Users\Domain\Exceptions\InvalidLoginPin;
|
||||
use App\Modules\Users\Domain\Exceptions\WrongPassword;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* The user's own PIN code for switching user on a machine console (spec
|
||||
* 19.6). Setting or removing it asks for the user's password.
|
||||
* 19.6). Setting or removing it asks for the user's password, which may
|
||||
* be wrong 5 times a minute, as on the login page.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
@@ -37,6 +39,10 @@ new class extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->passwordThrottled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$pins->set((int) auth()->id(), $this->currentPassword, $this->pin);
|
||||
} catch (InvalidLoginPin) {
|
||||
@@ -44,11 +50,13 @@ new class extends Component
|
||||
|
||||
return;
|
||||
} catch (WrongPassword) {
|
||||
$this->addError('currentPassword', __('users.pin.errors.password'));
|
||||
$this->wrongPassword();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
|
||||
$this->reset('currentPassword', 'pin', 'pinConfirmation');
|
||||
$this->message = __('users.pin.saved');
|
||||
}
|
||||
@@ -58,14 +66,20 @@ new class extends Component
|
||||
$this->authorize('machines.use');
|
||||
$this->resetErrorBag();
|
||||
|
||||
if ($this->passwordThrottled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$pins->remove((int) auth()->id(), $this->currentPassword);
|
||||
} catch (WrongPassword) {
|
||||
$this->addError('currentPassword', __('users.pin.errors.password'));
|
||||
$this->wrongPassword();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RateLimiter::clear($this->throttleKey());
|
||||
|
||||
$this->reset('currentPassword', 'pin', 'pinConfirmation');
|
||||
$this->message = __('users.pin.removed');
|
||||
}
|
||||
@@ -74,6 +88,30 @@ new class extends Component
|
||||
{
|
||||
return $this->view()->title(__('users.pin.title'));
|
||||
}
|
||||
|
||||
private function throttleKey(): string
|
||||
{
|
||||
return 'pin-password|'.auth()->id();
|
||||
}
|
||||
|
||||
private function passwordThrottled(): bool
|
||||
{
|
||||
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->addError('currentPassword', __('auth.throttle', ['seconds' => RateLimiter::availableIn($this->throttleKey())]));
|
||||
$this->reset('currentPassword');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function wrongPassword(): void
|
||||
{
|
||||
RateLimiter::hit($this->throttleKey());
|
||||
$this->addError('currentPassword', __('users.pin.errors.password'));
|
||||
$this->reset('currentPassword');
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user