This commit is contained in:
baodev0
2026-06-22 08:43:32 +07:00
parent 3243473843
commit 0c436153c6
22 changed files with 1389 additions and 95 deletions
@@ -2,9 +2,12 @@
namespace App\Services\Api\Client;
use App\Mail\Customer\Welcome as WelcomeMail;
use App\Models\RefreshToken;
use App\Repositories\Api\Client\ClientRepositoryInterface;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Tymon\JWTAuth\Facades\JWTAuth;
@@ -71,6 +74,8 @@ class ClientAuthService
$token = JWTAuth::fromUser($client);
$refreshToken = $this->createRefreshToken($client->id);
$this->sendWelcomeEmail($client);
return [
'client' => $client,
'token' => $token,
@@ -78,6 +83,24 @@ class ClientAuthService
];
}
/**
* Gửi email chào mừng cho khách hàng mới đăng ký.
*/
protected function sendWelcomeEmail($client): void
{
try {
Mail::to($client->email)->send(new WelcomeMail([
'fullname' => $client->fullname,
'email' => $client->email,
]));
} catch (\Throwable $e) {
Log::warning('Send welcome email failed: ' . $e->getMessage(), [
'customer_id' => $client->id,
'email' => $client->email,
]);
}
}
/**
* Tạo refresh token mới, lưu hash vào DB, trả về raw token.
*/