forked from coollabsio/coolify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: force password reset + waitlist
- Loading branch information
1 parent
952d335
commit 88b3005
Showing
35 changed files
with
482 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use Illuminate\Support\Facades\Hash; | ||
use Livewire\Component; | ||
|
||
class ForcePasswordReset extends Component | ||
{ | ||
public string $email; | ||
public string $password; | ||
public string $password_confirmation; | ||
|
||
protected $rules = [ | ||
'email' => 'required|email', | ||
'password' => 'required|min:8', | ||
'password_confirmation' => 'required|same:password', | ||
]; | ||
public function mount() { | ||
$this->email = auth()->user()->email; | ||
} | ||
public function submit() { | ||
try { | ||
$this->validate(); | ||
auth()->user()->forceFill([ | ||
'password' => Hash::make($this->password), | ||
'force_password_reset' => false, | ||
])->save(); | ||
auth()->logout(); | ||
return redirect()->route('login')->with('status', 'Your initial password has been set.'); | ||
} catch(\Exception $e) { | ||
return general_error_handler(err:$e, that:$this); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Http\Livewire; | ||
|
||
use App\Jobs\SendConfirmationForWaitlistJob; | ||
use App\Models\Waitlist as ModelsWaitlist; | ||
use Livewire\Component; | ||
|
||
class Waitlist extends Component | ||
{ | ||
public string $email; | ||
public int $waiting_in_line = 0; | ||
|
||
protected $rules = [ | ||
'email' => 'required|email', | ||
]; | ||
public function mount() | ||
{ | ||
if (is_dev()) { | ||
$this->email = '[email protected]'; | ||
} | ||
} | ||
public function submit() | ||
{ | ||
$this->validate(); | ||
try { | ||
$found = ModelsWaitlist::where('email', $this->email)->first(); | ||
ray($found); | ||
if ($found) { | ||
if (!$found->verified) { | ||
$this->emit('error', 'You are already on the waitlist. <br>Please check your email to verify your email address.'); | ||
return; | ||
} | ||
$this->emit('error', 'You are already on the waitlist.'); | ||
return; | ||
} | ||
$waitlist = ModelsWaitlist::create([ | ||
'email' => $this->email, | ||
'type' => 'registration', | ||
]); | ||
|
||
$this->emit('success', 'You have been added to the waitlist.'); | ||
dispatch(new SendConfirmationForWaitlistJob($this->email, $waitlist->uuid)); | ||
} catch (\Exception $e) { | ||
return general_error_handler(err: $e, that: $this); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CheckForcePasswordReset | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if (auth()->user()) { | ||
$force_password_reset = auth()->user()->force_password_reset; | ||
if ($force_password_reset) { | ||
if ($request->routeIs('auth.force-password-reset') || $request->path() === 'livewire/message/force-password-reset') { | ||
return $next($request); | ||
} | ||
return redirect()->route('auth.force-password-reset'); | ||
} | ||
} | ||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Waitlist; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class CleanupInstanceStuffsJob implements ShouldQueue, ShouldBeUnique | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct() | ||
{ | ||
|
||
} | ||
|
||
// public function uniqueId(): string | ||
// { | ||
// return $this->container_name; | ||
// } | ||
|
||
public function handle(): void | ||
{ | ||
try { | ||
$this->cleanup_waitlist(); | ||
} catch (\Exception $e) { | ||
ray($e->getMessage()); | ||
} | ||
} | ||
|
||
private function cleanup_waitlist() | ||
{ | ||
$waitlist = Waitlist::whereVerified(false)->where('created_at', '<', now()->subMinutes(config('constants.waitlist.confirmation_valid_for_minutes')))->get(); | ||
foreach ($waitlist as $item) { | ||
$item->delete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\InstanceSettings; | ||
use App\Models\Waitlist; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Mail\Message; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class SendConfirmationForWaitlistJob implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
public function __construct(public string $email, public string $uuid) | ||
{ | ||
} | ||
|
||
public function handle() | ||
{ | ||
try { | ||
$settings = InstanceSettings::get(); | ||
|
||
|
||
set_transanctional_email_settings($settings); | ||
$mail = new MailMessage(); | ||
|
||
$confirmation_url = base_url() . '/webhooks/waitlist/confirm?email=' . $this->email . '&confirmation_code=' . $this->uuid; | ||
$cancel_url = base_url() . '/webhooks/waitlist/cancel?email=' . $this->email . '&confirmation_code=' . $this->uuid; | ||
|
||
$mail->view('emails.waitlist-confirmation', | ||
[ | ||
'confirmation_url' => $confirmation_url, | ||
'cancel_url' => $cancel_url, | ||
]); | ||
$mail->subject('You are on the waitlist!'); | ||
Mail::send( | ||
[], | ||
[], | ||
fn(Message $message) => $message | ||
->from( | ||
data_get($settings, 'smtp_from_address'), | ||
data_get($settings, 'smtp_from_name') | ||
) | ||
->to($this->email) | ||
->subject($mail->subject) | ||
->html((string) $mail->render()) | ||
); | ||
} catch (\Throwable $th) { | ||
ray($th->getMessage()); | ||
throw $th; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
|
||
class Waitlist extends BaseModel | ||
{ | ||
use HasFactory; | ||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.