diff --git a/app/Notifications/TransactionalEmails/ResetPasswordEmail.php b/app/Notifications/TransactionalEmails/ResetPasswordEmail.php new file mode 100644 index 000000000..a23b64d47 --- /dev/null +++ b/app/Notifications/TransactionalEmails/ResetPasswordEmail.php @@ -0,0 +1,36 @@ +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 36c7b0283..6908255fd 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 7caec854d..5be08eeec 100644 --- a/resources/views/auth/forgot-password.blade.php +++ b/resources/views/auth/forgot-password.blade.php @@ -10,19 +10,23 @@

{{ __('auth.forgot_password') }}

-
- @csrf - - {{ __('auth.forgot_password_send_email') }} - + @if (is_transactional_emails_active()) +
+ @csrf + + {{ __('auth.forgot_password_send_email') }} + + @else + 'asd' + @endif @if ($errors->any()) -
+
{{ __('auth.failed') }}
@endif @if (session('status')) -
+
{{ session('status') }}
@endif diff --git a/resources/views/emails/invitation-link.blade.php b/resources/views/emails/invitation-link.blade.php index 7cdf02259..4949c8b3a 100644 --- a/resources/views/emails/invitation-link.blade.php +++ b/resources/views/emails/invitation-link.blade.php @@ -2,11 +2,11 @@ You have been invited to "{{ $team }}" on "{{ config('app.name') }}".

-Please click here to accept the invitation: Accept Invitation

+Please click here to accept the invitation: Accept Invitation

If you have any questions, please contact the team owner.

If it was not you who requested this invitation, please ignore this ema il, or instantly revoke the invitation by -clicking here: Revoke Invitation

+clicking here: Revoke Invitation

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 000000000..0a521d43d --- /dev/null +++ b/resources/views/emails/reset-password.blade.php @@ -0,0 +1,5 @@ +Hello,

+ +A password reset requested for your email address on "{{ config('app.name') }}".

+ +Please click the following link to reset your password: Password Reset diff --git a/routes/web.php b/routes/web.php index 1567ceb52..c2cde371b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,11 +11,42 @@ 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']);