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 App\Services\TcpSocketClient;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use App\Services\MachineStatusForwarder;
|
use App\Services\MachineStatusForwarder;
|
||||||
use App\Services\ApiClient;
|
use App\Services\ApiClient;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -78,26 +79,37 @@ class RoomControlController extends Controller
|
|||||||
{
|
{
|
||||||
// 1. 驗證帳密(登入用)
|
// 1. 驗證帳密(登入用)
|
||||||
$credentials = $request->only('email', 'password');
|
$credentials = $request->only('email', 'password');
|
||||||
|
|
||||||
if (!Auth::attempt($credentials)) {
|
|
||||||
return ApiResponse::unauthorized();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 取得登入使用者
|
// 2. 取得登入使用者
|
||||||
//$user = Auth::user();
|
|
||||||
$response = Http::withOptions(['verify' => false])
|
$response = Http::withOptions(['verify' => false])
|
||||||
->post(config('services.backend.url').'/api/login', [
|
->post(config('services.backend.url').'/api/login', [
|
||||||
'email' => $this->form->email,
|
'email' => $credentials['email'],
|
||||||
'password' => $this->form->password,
|
'password' => $credentials['password'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($response->failed()) {
|
if ($response->failed()) {
|
||||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||||
'email' => '登入失敗,請檢查帳號或密碼。',
|
'email' => '登入失敗,請檢查帳號或密碼。',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
$data = $response->json("data");
|
||||||
$token = $response->json("data")['token'];
|
$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();
|
$branch = Branch::first();
|
||||||
$otherSet = OtherSet::pluck('value', 'name')->toArray();
|
$otherSet = OtherSet::pluck('value', 'name')->toArray();
|
||||||
return ApiResponse::success([
|
return ApiResponse::success([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user