feat: live-verify SMTP configuration by sending verification test mail before enabling Email 2FA
This commit is contained in:
@@ -104,9 +104,6 @@ class TwoFactorController extends Controller
|
||||
return back()->with('success', 'Two-Factor Authentication has been disabled.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Email 2FA.
|
||||
*/
|
||||
public function toggleEmail(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
@@ -116,6 +113,19 @@ class TwoFactorController extends Controller
|
||||
|
||||
$user = auth()->user();
|
||||
if ($request->enabled) {
|
||||
// Live-verify SMTP configuration by sending a test validation email
|
||||
try {
|
||||
\Illuminate\Support\Facades\Mail::to($user->email)->send(
|
||||
new \App\Mail\Send2FACode('123456')
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error("SMTP verification failed: " . $e->getMessage());
|
||||
|
||||
return back()->withErrors([
|
||||
'password' => 'Cannot enable Email 2FA: Your SMTP mail configuration is invalid or not working. We tried to send a validation email but failed. Error: ' . $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
$user->update([
|
||||
'email_2fa_enabled' => true,
|
||||
'two_factor_secret' => null,
|
||||
|
||||
Reference in New Issue
Block a user