client api

This commit is contained in:
pbao9
2026-02-11 10:08:39 +07:00
parent 458ad0a4cb
commit d59b2a0840
27 changed files with 4369 additions and 28 deletions
@@ -0,0 +1,57 @@
<?php
namespace App\Services\Api\Client;
use App\Repositories\Api\Client\ClientRepositoryInterface;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
class ClientAuthService
{
protected $clientRepository;
public function __construct(ClientRepositoryInterface $clientRepository)
{
$this->clientRepository = $clientRepository;
}
/**
* Xác thực khách hàng và tạo token
*/
public function authenticateClient(array $credentials): array
{
if (!Auth::guard('client')->attempt($credentials)) {
throw ValidationException::withMessages([
'email' => ['Thông tin đăng nhập không chính xác.'],
]);
}
$client = Auth::guard('client')->user();
$token = $client->createToken('client-token')->plainTextToken;
return [
'client' => $client,
'token' => $token,
];
}
/**
* Đăng ký khách hàng mới và tạo token
*/
public function registerClient(array $data): array
{
$client = $this->clientRepository->create([
'fullname' => $data['fullname'],
'phone' => $data['phone'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
$token = $client->createToken('client-token')->plainTextToken;
return [
'client' => $client,
'token' => $token,
];
}
}