Add App\Support\SafeNotifier that wraps $notifiable->notify() in a Throwable guard with a logged warning, so SMTP outages (the current Gmail 535 errors) no longer propagate as a 500 to the user. Apply to the two hot paths that were still unprotected: CommentController (new comment, reply, like) and RegisteredUserController (super-admin registration alert). User::sendEmailVerificationNotification() is wrapped inline for the same reason. Also add docs/mail-setup.md covering the three delivery options: Gmail app password (quick), Mailgun, Postmark — with the exact .env keys for each. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\User;
|
|
use App\Notifications\NewUserRegistered;
|
|
use App\Rules\NotDisposableEmail;
|
|
use App\Rules\ReservedIdentifier;
|
|
use App\Support\SafeNotifier;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\Rules\Password;
|
|
|
|
class RegisteredUserController extends Controller
|
|
{
|
|
public function create()
|
|
{
|
|
return view('auth.register');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
// Honeypot — bots fill hidden fields; real users never do
|
|
if ($request->filled('_hp')) {
|
|
// Silently appear to succeed to confuse the bot
|
|
return redirect()->route('login');
|
|
}
|
|
|
|
$request->validate([
|
|
'name' => ['required', 'string', 'max:255', new ReservedIdentifier('name')],
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users', new NotDisposableEmail, new ReservedIdentifier('email')],
|
|
'password' => ['required', 'confirmed', Password::defaults()],
|
|
'birthday' => ['required', 'date', 'before:today'],
|
|
'gender' => ['required', 'in:male,female'],
|
|
'nationality' => ['required', 'string', 'size:2'],
|
|
]);
|
|
|
|
$user = User::create([
|
|
'name' => $request->name,
|
|
'email' => $request->email,
|
|
'password' => Hash::make($request->password),
|
|
'birthday' => $request->birthday,
|
|
'gender' => $request->gender,
|
|
'nationality' => $request->nationality,
|
|
]);
|
|
|
|
event(new Registered($user));
|
|
|
|
// Notify all super admins of the new registration
|
|
User::where('role', 'super_admin')->each(function (User $admin) use ($user) {
|
|
SafeNotifier::send($admin, new NewUserRegistered($user));
|
|
});
|
|
|
|
auth()->login($user);
|
|
|
|
return redirect()->route('verification.notice');
|
|
}
|
|
}
|