mirror of
https://github.com/cupcakearmy/coolify.git
synced 2024-10-22 08:04:19 +02:00
rate limit things
This commit is contained in:
parent
88b3005589
commit
f8d7c5209e
@ -3,10 +3,12 @@
|
|||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class ForcePasswordReset extends Component
|
class ForcePasswordReset extends Component
|
||||||
{
|
{
|
||||||
|
use WithRateLimiting;
|
||||||
public string $email;
|
public string $email;
|
||||||
public string $password;
|
public string $password;
|
||||||
public string $password_confirmation;
|
public string $password_confirmation;
|
||||||
@ -21,6 +23,7 @@ public function mount() {
|
|||||||
}
|
}
|
||||||
public function submit() {
|
public function submit() {
|
||||||
try {
|
try {
|
||||||
|
$this->rateLimit(10);
|
||||||
$this->validate();
|
$this->validate();
|
||||||
auth()->user()->forceFill([
|
auth()->user()->forceFill([
|
||||||
'password' => Hash::make($this->password),
|
'password' => Hash::make($this->password),
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Http\Livewire;
|
namespace App\Http\Livewire;
|
||||||
|
|
||||||
use App\Jobs\SendConfirmationForWaitlistJob;
|
use App\Jobs\SendConfirmationForWaitlistJob;
|
||||||
|
use App\Models\User;
|
||||||
use App\Models\Waitlist as ModelsWaitlist;
|
use App\Models\Waitlist as ModelsWaitlist;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
@ -24,6 +25,11 @@ public function submit()
|
|||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
try {
|
try {
|
||||||
|
$already_registered = User::whereEmail($this->email)->first();
|
||||||
|
if ($already_registered) {
|
||||||
|
$this->emit('success', 'You are already registered (Thank you 💜).');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$found = ModelsWaitlist::where('email', $this->email)->first();
|
$found = ModelsWaitlist::where('email', $this->email)->first();
|
||||||
ray($found);
|
ray($found);
|
||||||
if ($found) {
|
if ($found) {
|
||||||
|
@ -98,6 +98,14 @@ public function boot(): void
|
|||||||
return view('auth.two-factor-challenge');
|
return view('auth.two-factor-challenge');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RateLimiter::for('force-password-reset', function (Request $request) {
|
||||||
|
return Limit::perMinute(15)->by($request->user()->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
RateLimiter::for('forgot-password', function (Request $request) {
|
||||||
|
return Limit::perMinute(5)->by($request->ip());
|
||||||
|
});
|
||||||
|
|
||||||
RateLimiter::for('login', function (Request $request) {
|
RateLimiter::for('login', function (Request $request) {
|
||||||
$email = (string)$request->email;
|
$email = (string)$request->email;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
use Nubs\RandomNameGenerator\All;
|
use Nubs\RandomNameGenerator\All;
|
||||||
use Poliander\Cron\CronExpression;
|
use Poliander\Cron\CronExpression;
|
||||||
use Visus\Cuid2\Cuid2;
|
use Visus\Cuid2\Cuid2;
|
||||||
|
use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
|
||||||
|
|
||||||
function application_configuration_dir(): string
|
function application_configuration_dir(): string
|
||||||
{
|
{
|
||||||
@ -46,7 +47,9 @@ function general_error_handler(Throwable|null $err = null, $that = null, $isJson
|
|||||||
} else {
|
} else {
|
||||||
throw new Exception($customErrorMessage ?? $err->errorInfo[2]);
|
throw new Exception($customErrorMessage ?? $err->errorInfo[2]);
|
||||||
}
|
}
|
||||||
} else {
|
} elseif($err instanceof TooManyRequestsException){
|
||||||
|
throw new Exception($customErrorMessage ?? "Too many requests. Please try again in {$err->secondsUntilAvailable} seconds.");
|
||||||
|
}else {
|
||||||
throw new Exception($customErrorMessage ?? $err->getMessage());
|
throw new Exception($customErrorMessage ?? $err->getMessage());
|
||||||
}
|
}
|
||||||
} catch (Throwable $error) {
|
} catch (Throwable $error) {
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.2",
|
"php": "^8.2",
|
||||||
|
"danharrin/livewire-rate-limiting": "^1.1",
|
||||||
"doctrine/dbal": "^3.6",
|
"doctrine/dbal": "^3.6",
|
||||||
"guzzlehttp/guzzle": "^7.5.0",
|
"guzzlehttp/guzzle": "^7.5.0",
|
||||||
"laravel/fortify": "^v1.16.0",
|
"laravel/fortify": "^v1.16.0",
|
||||||
|
55
composer.lock
generated
55
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "ba59e457afa0cfb65b82118f7287147b",
|
"content-hash": "0c023bed552776ee5e4eeda1ff0a5e19",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "aws/aws-crt-php",
|
"name": "aws/aws-crt-php",
|
||||||
@ -330,6 +330,59 @@
|
|||||||
],
|
],
|
||||||
"time": "2022-02-21T13:15:14+00:00"
|
"time": "2022-02-21T13:15:14+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "danharrin/livewire-rate-limiting",
|
||||||
|
"version": "v1.1.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/danharrin/livewire-rate-limiting.git",
|
||||||
|
"reference": "a55996683cabf2e93893280d602191243b3b80b8"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/danharrin/livewire-rate-limiting/zipball/a55996683cabf2e93893280d602191243b3b80b8",
|
||||||
|
"reference": "a55996683cabf2e93893280d602191243b3b80b8",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/support": "^9.0|^10.0",
|
||||||
|
"php": "^8.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"livewire/livewire": "^2.3",
|
||||||
|
"orchestra/testbench": "^7.0|^8.0",
|
||||||
|
"phpunit/phpunit": "^9.0|^10.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DanHarrin\\LivewireRateLimiting\\": "src"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Dan Harrin",
|
||||||
|
"email": "dan@danharrin.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Apply rate limiters to Laravel Livewire actions.",
|
||||||
|
"homepage": "https://github.com/danharrin/livewire-rate-limiting",
|
||||||
|
"support": {
|
||||||
|
"issues": "https://github.com/danharrin/livewire-rate-limiting/issues",
|
||||||
|
"source": "https://github.com/danharrin/livewire-rate-limiting"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://github.com/danharrin",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2023-03-12T12:17:29+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "dasprid/enum",
|
"name": "dasprid/enum",
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
|
@ -105,6 +105,7 @@
|
|||||||
'limiters' => [
|
'limiters' => [
|
||||||
'login' => 'login',
|
'login' => 'login',
|
||||||
'two-factor' => 'two-factor',
|
'two-factor' => 'two-factor',
|
||||||
|
'forgot-password' => 'forgot-password',
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
<div class="w-96 min-w-fit">
|
<div class="w-96 min-w-fit">
|
||||||
<div class="flex flex-col items-center pb-8">
|
<div class="flex flex-col items-center pb-8">
|
||||||
<div class="text-5xl font-extrabold tracking-tight text-center text-white">Coolify</div>
|
<div class="text-5xl font-extrabold tracking-tight text-center text-white">Coolify</div>
|
||||||
<x-version />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<h1>{{ __('auth.login') }}</h1>
|
<h1>{{ __('auth.login') }}</h1>
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
<h2>Set your initial password</h2>
|
<h2>Set your initial password</h2>
|
||||||
</div>
|
</div>
|
||||||
<form class="flex flex-col gap-2" wire:submit.prevent='submit'>
|
<form class="flex flex-col gap-2" wire:submit.prevent='submit'>
|
||||||
<x-forms.input id="email" type="email" placeholder="Email" readonly />
|
<x-forms.input id="email" type="email" placeholder="Email" readonly label="Email" />
|
||||||
<x-forms.input id="password" type="password" placeholder="New Password" />
|
<x-forms.input id="password" type="password" placeholder="New Password" label="New Password" required />
|
||||||
<x-forms.input id="password_confirmation" type="password" placeholder="Confirm New Password" />
|
<x-forms.input id="password_confirmation" type="password" placeholder="Confirm New Password" label="Confirm New Password" required />
|
||||||
<x-forms.button type="submit">Reset Password</x-forms.button>
|
<x-forms.button type="submit">Reset Password</x-forms.button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
<div class="min-h-screen hero">
|
<div class="min-h-screen hero">
|
||||||
<div class="w-96 min-w-fit">
|
<div class="w-96 min-w-fit">
|
||||||
|
<div class="flex flex-col items-center pb-8">
|
||||||
|
<a href="{{ route('dashboard') }}">
|
||||||
|
<div class="text-5xl font-bold tracking-tight text-center text-white">Coolify</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="flex items-center justify-center pb-4 text-center">
|
<div class="flex items-center justify-center pb-4 text-center">
|
||||||
<h2>Start self-hosting in the
|
<h2>Self-hosting in the cloud
|
||||||
<svg class="inline-block w-8 h-8 text-warning width="512" height="512" viewBox="0 0 20 20"
|
<svg class="inline-block w-8 h-8 text-warning width="512" height="512" viewBox="0 0 20 20"
|
||||||
xmlns="http://www.w3.org/2000/svg">
|
xmlns="http://www.w3.org/2000/svg">
|
||||||
<g fill="currentColor" fill-rule="evenodd" clip-rule="evenodd">
|
<g fill="currentColor" fill-rule="evenodd" clip-rule="evenodd">
|
||||||
@ -18,6 +23,6 @@
|
|||||||
<x-forms.input id="email" type="email" label="Email" placeholder="youareawesome@protonmail.com" />
|
<x-forms.input id="email" type="email" label="Email" placeholder="youareawesome@protonmail.com" />
|
||||||
<x-forms.button type="submit">Join Waitlist</x-forms.button>
|
<x-forms.button type="submit">Join Waitlist</x-forms.button>
|
||||||
</form>
|
</form>
|
||||||
Waiting: {{$waiting_in_line}}
|
Waiting in the line: {{$waiting_in_line}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -93,7 +93,9 @@
|
|||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/', [Controller::class, 'dashboard'])->name('dashboard');
|
Route::get('/', [Controller::class, 'dashboard'])->name('dashboard');
|
||||||
Route::get('/force-password-reset', [Controller::class, 'force_passoword_reset'])->name('auth.force-password-reset');
|
Route::middleware(['throttle:force-password-reset'])->group(function() {
|
||||||
|
Route::get('/force-password-reset', [Controller::class, 'force_passoword_reset'])->name('auth.force-password-reset');
|
||||||
|
});
|
||||||
Route::get('/subscription', [Controller::class, 'subscription'])->name('subscription');
|
Route::get('/subscription', [Controller::class, 'subscription'])->name('subscription');
|
||||||
Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration');
|
Route::get('/settings', [Controller::class, 'settings'])->name('settings.configuration');
|
||||||
Route::get('/settings/license', [Controller::class, 'license'])->name('settings.license');
|
Route::get('/settings/license', [Controller::class, 'license'])->name('settings.license');
|
||||||
|
Loading…
Reference in New Issue
Block a user