202509091116
API 登入流程調整
This commit is contained in:
parent
6abede45d2
commit
fa987caf85
@ -9,6 +9,7 @@ use App\Http\Requests\SessionRequest;
|
||||
use App\Services\TcpSocketClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Services\MachineStatusForwarder;
|
||||
use App\Services\ApiClient;
|
||||
use App\Models\User;
|
||||
@ -78,26 +79,37 @@ class RoomControlController extends Controller
|
||||
{
|
||||
// 1. 驗證帳密(登入用)
|
||||
$credentials = $request->only('email', 'password');
|
||||
|
||||
if (!Auth::attempt($credentials)) {
|
||||
return ApiResponse::unauthorized();
|
||||
}
|
||||
|
||||
// 2. 取得登入使用者
|
||||
//$user = Auth::user();
|
||||
$response = Http::withOptions(['verify' => false])
|
||||
->post(config('services.backend.url').'/api/login', [
|
||||
'email' => $this->form->email,
|
||||
'password' => $this->form->password,
|
||||
'email' => $credentials['email'],
|
||||
'password' => $credentials['password'],
|
||||
]);
|
||||
|
||||
if ($response->failed()) {
|
||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||
'email' => '登入失敗,請檢查帳號或密碼。',
|
||||
]);
|
||||
}
|
||||
|
||||
$token = $response->json("data")['token'];
|
||||
|
||||
$data = $response->json("data");
|
||||
$token = $data['token'];
|
||||
$userData = $data['user'];
|
||||
$user = \App\Models\User::updateOrCreate(
|
||||
[ 'id' => $userData['id']],
|
||||
[
|
||||
'name' => $userData['name'],
|
||||
'email' => $userData['email'],
|
||||
'phone' => $userData['phone'],
|
||||
'birthday' => $userData['birthday'],
|
||||
'gender' => $userData['gender'],
|
||||
'status' => $userData['status'],
|
||||
'email_verified_at' => $userData['email_verified_at'],
|
||||
'api_plain_token' => $token,
|
||||
'created_at' => $userData['created_at'],
|
||||
'updated_at' => $userData['updated_at'],
|
||||
|
||||
]
|
||||
);
|
||||
$branch = Branch::first();
|
||||
$otherSet = OtherSet::pluck('value', 'name')->toArray();
|
||||
return ApiResponse::success([
|
||||
|
Loading…
x
Reference in New Issue
Block a user