Feature: Updating Listreners, Separating Logic from listeners, Queuing Policies
This commit is contained in:
@@ -10,6 +10,7 @@ use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Modules\Core\Auth\Events\UserAuthenticated;
|
||||
use Modules\Core\Auth\Events\UserCreated;
|
||||
use Modules\Core\Auth\Exceptions\OtpThrottledException;
|
||||
use Modules\Core\Auth\Mail\UserOtpMail;
|
||||
|
||||
@@ -75,6 +76,18 @@ class UserOtpService
|
||||
$model = config('auth.providers.users.model');
|
||||
$user = $model::firstOrCreate(['email' => $email]);
|
||||
|
||||
// wasRecentlyCreated is Eloquent's own "did firstOrCreate() just
|
||||
// INSERT, or did it find an existing row" flag — the only reliable
|
||||
// way to tell them apart from firstOrCreate()'s return value alone.
|
||||
// Without this check, a genuinely new signup never fired
|
||||
// UserCreated at all (this class's own docblock claimed the
|
||||
// Customer/User pairing cascade "already triggers" here, which was
|
||||
// false as written — see Modules\Core\Customer\Listeners\
|
||||
// CreateCustomerForUser, which depends entirely on this event).
|
||||
if ($user->wasRecentlyCreated) {
|
||||
Event::dispatch(new UserCreated($user));
|
||||
}
|
||||
|
||||
$code = str_pad((string) random_int(0, 999999), self::CODE_LENGTH, '0', STR_PAD_LEFT);
|
||||
|
||||
$user->otp_code = $code;
|
||||
|
||||
Reference in New Issue
Block a user