fix
This commit is contained in:
parent
3e18f0f238
commit
18fde01ed5
@ -36,16 +36,6 @@ class TransactionalEmailChannel
|
|||||||
|
|
||||||
private function bootConfigs(InstanceSettings $settings): void
|
private function bootConfigs(InstanceSettings $settings): void
|
||||||
{
|
{
|
||||||
config()->set('mail.default', 'smtp');
|
set_transanctional_email_settings();
|
||||||
config()->set('mail.mailers.smtp', [
|
|
||||||
"transport" => "smtp",
|
|
||||||
"host" => $settings->extra_attributes?->get('smtp_host'),
|
|
||||||
"port" => $settings->extra_attributes?->get('smtp_port'),
|
|
||||||
"encryption" => $settings->extra_attributes?->get('smtp_encryption'),
|
|
||||||
"username" => $settings->extra_attributes?->get('smtp_username'),
|
|
||||||
"password" => $settings->extra_attributes?->get('smtp_password'),
|
|
||||||
"timeout" => $settings->extra_attributes?->get('smtp_timeout'),
|
|
||||||
"local_domain" => null,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,11 @@ class ResetPasswordEmail extends Notification implements ShouldQueue
|
|||||||
|
|
||||||
public function toMail(User $user): MailMessage
|
public function toMail(User $user): MailMessage
|
||||||
{
|
{
|
||||||
|
if (config('app.env') === 'local') {
|
||||||
|
$url = url('/') . ":8000" . '/reset-password/' . $this->token . '?email=' . $user->email;
|
||||||
|
} else {
|
||||||
$url = url('/') . '/reset-password/' . $this->token . '?email=' . $user->email;
|
$url = url('/') . '/reset-password/' . $this->token . '?email=' . $user->email;
|
||||||
|
}
|
||||||
$mail = new MailMessage();
|
$mail = new MailMessage();
|
||||||
$mail->subject('Reset Password');
|
$mail->subject('Reset Password');
|
||||||
$mail->view('emails.reset-password', [
|
$mail->view('emails.reset-password', [
|
||||||
|
@ -65,3 +65,19 @@ function is_transactional_emails_active()
|
|||||||
{
|
{
|
||||||
return data_get(InstanceSettings::get(), 'extra_attributes.smtp_host');
|
return data_get(InstanceSettings::get(), 'extra_attributes.smtp_host');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function set_transanctional_email_settings()
|
||||||
|
{
|
||||||
|
$settings = InstanceSettings::get();
|
||||||
|
config()->set('mail.default', 'smtp');
|
||||||
|
config()->set('mail.mailers.smtp', [
|
||||||
|
"transport" => "smtp",
|
||||||
|
"host" => $settings->extra_attributes?->get('smtp_host'),
|
||||||
|
"port" => $settings->extra_attributes?->get('smtp_port'),
|
||||||
|
"encryption" => $settings->extra_attributes?->get('smtp_encryption'),
|
||||||
|
"username" => $settings->extra_attributes?->get('smtp_username'),
|
||||||
|
"password" => $settings->extra_attributes?->get('smtp_password'),
|
||||||
|
"timeout" => $settings->extra_attributes?->get('smtp_timeout'),
|
||||||
|
"local_domain" => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<h1>{{ __('auth.forgot_password') }}</h1>
|
<h1>{{ __('auth.forgot_password') }}</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-96">
|
<div>
|
||||||
@if (is_transactional_emails_active())
|
@if (is_transactional_emails_active())
|
||||||
<form action="/forgot-password" method="POST" class="flex flex-col gap-2">
|
<form action="/forgot-password" method="POST" class="flex flex-col gap-2">
|
||||||
@csrf
|
@csrf
|
||||||
@ -18,7 +18,9 @@
|
|||||||
<x-forms.button type="submit">{{ __('auth.forgot_password_send_email') }}</x-forms.button>
|
<x-forms.button type="submit">{{ __('auth.forgot_password_send_email') }}</x-forms.button>
|
||||||
</form>
|
</form>
|
||||||
@else
|
@else
|
||||||
'asd'
|
<div>Transactional emails are not active on this instance.</div>
|
||||||
|
<div>See how to set it in our <a class="text-white" target="_blank"
|
||||||
|
href="https://docs.coollabs.io/coolify">docs</a>, or how to manually reset password.</div>
|
||||||
@endif
|
@endif
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
<div class="text-xs text-center text-error">
|
<div class="text-xs text-center text-error">
|
||||||
|
@ -15,37 +15,27 @@ use App\Models\User;
|
|||||||
use App\Notifications\TransactionalEmails\ResetPasswordEmail;
|
use App\Notifications\TransactionalEmails\ResetPasswordEmail;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Password;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse;
|
||||||
|
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse;
|
||||||
|
use Laravel\Fortify\Fortify;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::post('/forgot-password', function (Request $request) {
|
Route::post('/forgot-password', function (Request $request) {
|
||||||
$request->validate([
|
if (!is_transactional_emails_active()) {
|
||||||
'email' => 'required|email',
|
set_transanctional_email_settings();
|
||||||
]);
|
$request->validate([Fortify::email() => 'required|email']);
|
||||||
$user = User::whereEmail($request->email)->first();
|
$status = Password::broker(config('fortify.passwords'))->sendResetLink(
|
||||||
if (!$user->exists()) {
|
$request->only(Fortify::email())
|
||||||
return back()->withErrors([
|
);
|
||||||
'email' => 'No user found with that email address.',
|
return $status == Password::RESET_LINK_SENT
|
||||||
]);
|
? app(SuccessfulPasswordResetLinkRequestResponse::class, ['status' => $status])
|
||||||
}
|
: app(FailedPasswordResetLinkRequestResponse::class, ['status' => $status]);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
return response()->json(['message' => 'Transactional emails are not active'], 400);
|
||||||
})->name('password.forgot');
|
})->name('password.forgot');
|
||||||
Route::prefix('magic')->middleware(['auth'])->group(function () {
|
Route::prefix('magic')->middleware(['auth'])->group(function () {
|
||||||
Route::get('/servers', [MagicController::class, 'servers']);
|
Route::get('/servers', [MagicController::class, 'servers']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user