Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix

Andras Bacsai3e18f0f23841
diff --git a/app/Notifications/TransactionalEmails/ResetPasswordEmail.php b/app/Notifications/TransactionalEmails/ResetPasswordEmail.php
new file mode 100644
index 0000000000..a23b64d47b
--- /dev/null
+++ b/app/Notifications/TransactionalEmails/ResetPasswordEmail.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace App\Notifications\TransactionalEmails;
+
+use App\Models\User;
+use App\Notifications\Channels\TransactionalEmailChannel;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Notifications\Messages\MailMessage;
+use Illuminate\Notifications\Notification;
+
+class ResetPasswordEmail extends Notification implements ShouldQueue
+{
+ use Queueable;
+ public string $token;
+ public function __construct(string $token)
+ {
+ $this->token = $token;
+ }
+ public function via()
+ {
+ return [TransactionalEmailChannel::class];
+ }
+
+ public function toMail(User $user): MailMessage
+ {
+ $url = url('/') . '/reset-password/' . $this->token . '?email=' . $user->email;
+ $mail = new MailMessage();
+ $mail->subject('Reset Password');
+ $mail->view('emails.reset-password', [
+ 'user' => $user,
+ 'url' => $url,
+ ]);
+ return $mail;
+ }
+}
diff --git a/lang/en.json b/lang/en.json
index 36c7b0283b..6908255fd6 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -3,7 +3,7 @@
"auth.already_registered": "Already registered?",
"auth.confirm_password": "Confirm password",
"auth.forgot_password": "Forgot password",
- "auth.forgot_password_send_email": "Send password reset link via email",
+ "auth.forgot_password_send_email": "Send password reset email",
"auth.register_now": "Register a new account",
"auth.logout": "Logout",
"auth.register": "Register",
diff --git a/resources/views/auth/forgot-password.blade.php b/resources/views/auth/forgot-password.blade.php
index 7caec854d2..5be08eeec5 100644
--- a/resources/views/auth/forgot-password.blade.php
+++ b/resources/views/auth/forgot-password.blade.php
@@ -10,19 +10,23 @@
<h1>{{ __('auth.forgot_password') }}</h1>
</div>
<div class="w-96">
- <form action="/forgot-password" method="POST" class="flex flex-col gap-2">
- @csrf
- <x-forms.input required value="[email protected]" type="email" name="email"
- label="{{ __('input.email') }}" autofocus />
- <x-forms.button type="submit">{{ __('auth.forgot_password_send_email') }}</x-forms.button>
- </form>
+ @if (is_transactional_emails_active())
+ <form action="/forgot-password" method="POST" class="flex flex-col gap-2">
+ @csrf
+ <x-forms.input required value="[email protected]" type="email" name="email"
+ label="{{ __('input.email') }}" autofocus />
+ <x-forms.button type="submit">{{ __('auth.forgot_password_send_email') }}</x-forms.button>
+ </form>
+ @else
+ 'asd'
+ @endif
@if ($errors->any())
- <div class="text-center text-error">
+ <div class="text-xs text-center text-error">
<span>{{ __('auth.failed') }}</span>
</div>
@endif
@if (session('status'))
- <div class="mb-4 text-sm font-medium text-green-600">
+ <div class="mb-4 text-xs font-medium text-green-600">
{{ session('status') }}
</div>
@endif
diff --git a/resources/views/emails/invitation-link.blade.php b/resources/views/emails/invitation-link.blade.php
index 7cdf02259d..4949c8b3ac 100644
--- a/resources/views/emails/invitation-link.blade.php
+++ b/resources/views/emails/invitation-link.blade.php
@@ -2,11 +2,11 @@ Hello,<br><br>
You have been invited to "{{ $team }}" on "{{ config('app.name') }}".<br><br>
-Please click here to accept the invitation: <a href="{{ $invitation_link }}">Accept Invitation</a><br><br>
+Please click here to accept the invitation: <a target="_blank" href="{{ $invitation_link }}">Accept Invitation</a><br><br>
If you have any questions, please contact the team owner.<br><br>
If it was not you who requested this invitation, please ignore this ema il, or instantly revoke the invitation by
-clicking here: <a href="{{ $invitation_link }}/revoke">Revoke Invitation</a><br><br>
+clicking here: <a target="_blank" href="{{ $invitation_link }}/revoke">Revoke Invitation</a><br><br>
Thank you.
diff --git a/resources/views/emails/reset-password.blade.php b/resources/views/emails/reset-password.blade.php
new file mode 100644
index 0000000000..0a521d43d5
--- /dev/null
+++ b/resources/views/emails/reset-password.blade.php
@@ -0,0 +1,5 @@
+Hello,<br><br>
+
+A password reset requested for your email address on "{{ config('app.name') }}".<br><br>
+
+Please click the following link to reset your password: <a target="_blank" href="{{ $url }}">Password Reset</a>
diff --git a/routes/web.php b/routes/web.php
index 1567ceb52e..c2cde371b9 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -11,11 +11,42 @@ use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use App\Models\GithubApp;
use App\Models\Server;
+use App\Models\User;
+use App\Notifications\TransactionalEmails\ResetPasswordEmail;
use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;
+Route::post('/forgot-password', function (Request $request) {
+ $request->validate([
+ 'email' => 'required|email',
+ ]);
+ $user = User::whereEmail($request->email)->first();
+ if (!$user->exists()) {
+ return back()->withErrors([
+ 'email' => 'No user found with that email address.',
+ ]);
+ }
+ if (is_transactional_emails_active()) {
+ $token = Str::random(64);
+ $token_exists = DB::table('password_reset_tokens')->whereEmail($user->email)->first();
+ if ($token_exists) {
+ return back()->withErrors([
+ 'email' => 'Token already exists.',
+ ]);
+ }
+ DB::table('password_reset_tokens')->insert([
+ 'email' => $user->email,
+ 'token' => $token,
+ 'created_at' => now(),
+ ]);
+ $user->notify(new ResetPasswordEmail($token));
+ } else {
+ // $user->sendPasswordResetNotification($user->createToken('password-reset')->plainTextToken);
+ }
+})->name('password.forgot');
Route::prefix('magic')->middleware(['auth'])->group(function () {
Route::get('/servers', [MagicController::class, 'servers']);
Route::get('/destinations', [MagicController::class, 'destinations']);