Skip to content

Commit 17bb68f

Browse files
authored
Merge pull request #3630 from codeeu/fix/password-max-length
edit to online course page
2 parents 3281386 + 6b9e09d commit 17bb68f

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

app/Services/UserEmailChangeService.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\User;
1010
use Illuminate\Support\Facades\DB;
1111
use Illuminate\Support\Facades\Hash;
12+
use Illuminate\Support\Facades\Log;
1213
use Illuminate\Support\Facades\Mail;
1314
use Illuminate\Support\Facades\URL;
1415
use Illuminate\Support\Str;
@@ -106,7 +107,7 @@ private function dispatchConfirmationEmail(User $user, string $newEmail, string
106107
['user' => $user->id, 'token' => $token],
107108
);
108109

109-
Mail::to($newEmail)->queue(new PendingEmailChangeConfirmation($user, $confirmUrl));
110+
$this->deliverNow($newEmail, new PendingEmailChangeConfirmation($user, $confirmUrl), 'confirmation');
110111
}
111112

112113
private function sendChangeNotification(User $user, string $newEmail, ?string $currentEmail): void
@@ -115,7 +116,25 @@ private function sendChangeNotification(User $user, string $newEmail, ?string $c
115116
return;
116117
}
117118

118-
Mail::to($currentEmail)->queue(new PendingEmailChangeNotification($user, $newEmail));
119+
$this->deliverNow($currentEmail, new PendingEmailChangeNotification($user, $newEmail), 'notification');
120+
}
121+
122+
private function deliverNow(string $email, PendingEmailChangeConfirmation|PendingEmailChangeNotification $mailable, string $type): void
123+
{
124+
try {
125+
Mail::to($email)->send($mailable);
126+
} catch (\Throwable $exception) {
127+
Log::error('Failed to send login email change message.', [
128+
'type' => $type,
129+
'recipient' => $email,
130+
'user_id' => $mailable->user->id ?? null,
131+
'message' => $exception->getMessage(),
132+
]);
133+
134+
throw ValidationException::withMessages([
135+
$type === 'confirmation' ? 'new_email' : 'email' => 'We could not send the email right now. Please try again in a few minutes or contact info@codeweek.eu.',
136+
]);
137+
}
119138
}
120139

121140
public function cancelPending(User $user): void

tests/Feature/UserEmailChangeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public function test_user_can_request_email_change_from_profile(): void
4747
$user->refresh();
4848
$this->assertSame('new@example.com', $user->pending_email);
4949

50-
Mail::assertQueued(PendingEmailChangeConfirmation::class, function ($mail) {
50+
Mail::assertSent(PendingEmailChangeConfirmation::class, function ($mail) {
5151
return $mail->hasTo('new@example.com');
5252
});
5353

54-
Mail::assertQueued(PendingEmailChangeNotification::class, function ($mail) {
54+
Mail::assertSent(PendingEmailChangeNotification::class, function ($mail) {
5555
return $mail->hasTo('old@example.com');
5656
});
5757
}
@@ -131,11 +131,11 @@ public function test_user_can_resend_pending_confirmation_email(): void
131131
$response->assertRedirect();
132132
$response->assertSessionHas('email_change_status');
133133

134-
Mail::assertQueued(PendingEmailChangeConfirmation::class, function ($mail) {
134+
Mail::assertSent(PendingEmailChangeConfirmation::class, function ($mail) {
135135
return $mail->hasTo('new@example.com');
136136
});
137137

138-
Mail::assertNotQueued(PendingEmailChangeNotification::class);
138+
Mail::assertNotSent(PendingEmailChangeNotification::class);
139139
}
140140

141141
public function test_profile_update_still_cannot_change_login_email_directly(): void

0 commit comments

Comments
 (0)