update auth

This commit is contained in:
pbao9
2025-08-05 08:58:40 +07:00
parent fc277e5ef6
commit 1a9ade38e8
6 changed files with 81 additions and 54 deletions
+7
View File
@@ -65,6 +65,13 @@ if (!function_exists('customer')) {
}
}
if (!function_exists('user')) {
function user()
{
return Auth::guard('users')->user();
}
}
if (!function_exists('generate_order_number')) {
/**
* Generate a unique order number with given prefix
+1 -1
View File
@@ -33,7 +33,7 @@ return [
|
*/
'guard' => ['admins'],
'guard' => ['admins', 'users'],
/*
|--------------------------------------------------------------------------
@@ -2,7 +2,7 @@
<!-- Avatar -->
<button @click="open = !open" @click.away="open = false"
class="w-8 h-8 rounded-full overflow-hidden shadow-lg image-fit zoom-in focus:outline-none">
<img src="{{ asset('template/' . customer()?->avatar) ?? asset('images/avatar.png') }}" alt="Avatar">
<img src="{{ asset('images/avatar.png') }}" alt="Avatar">
</button>
<!-- Dropdown -->
-1
View File
@@ -79,7 +79,6 @@
@include("frontend.sidebar")
<div class="main content-wrapper d-flex flex-column align-items-stretch flex-shrink-0 bg-white p-3 px-lg-5">
<h1>{{ $title }}</h1>
@include("alerts")
@yield("content")
</div>
@include("frontend.footer")
@@ -112,10 +112,9 @@
const getTicket = new Promise((resolve, reject) => {
$.ajax({
url: '{{ route('api.GetConsoleTicket') }}',
url: '{{ route('api.user.GetConsoleTicket') }}',
type: 'get',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
'Accept': 'application/json',
'Authorization': 'Bearer {{ request()->cookie('aut_accessToken') }}'
},
@@ -128,6 +127,10 @@
} else {
reject(response.message)
}
},
error: function(xhr, status, error) {
console.error('API Error:', xhr.responseText);
reject('API request failed: ' + error);
}
})
});
+21 -3
View File
@@ -458,7 +458,7 @@ Route::prefix('v1')
})
/* Api for customer */
->group(function () {
Route::middleware('auth:sanctum')
Route::middleware(['auth:sanctum'])
->group(function () {
Route::post('get-status-virtual-machine', function (Request $request, ServiceVCenter $serviceVCenter) {
$vmware_id = $request->vmware_id;
@@ -899,6 +899,24 @@ Route::prefix('v1')
return response()->json(['error' => true, 'message' => "Can't find product"]);
}
// Validate that the product belongs to the authenticated user
if ($product->customer_id != user()->id) {
return response()->json([
'error' => true,
'message' => 'Không có quyền truy cập máy ảo này'
]);
}
// Check if service is expired
if ($product->status == 4) {
return response()->json(['error' => true, 'message' => 'Dịch vụ đã hết hạn']);
}
// Check if VM is still initializing
if ($product->status == 3) {
return response()->json(['error' => true, 'message' => 'Máy ảo đang khởi tạo']);
}
$vcenter = null;
if ($product->ipAddress && $product->ipAddress->host && $product->ipAddress->host->datacenter && $product->ipAddress->host->datacenter->vCenter) {
$vcenter = $product->ipAddress->host->datacenter->vCenter;
@@ -1353,7 +1371,7 @@ Route::prefix('v1')
'size_MiB' => $vmInfo['value']['memory']['size_MiB'] ?? 0,
'hot_add_enabled' => $vmInfo['value']['memory']['hot_add_enabled'] ?? false,
],
'disks' => array_map(function($disk) {
'disks' => array_map(function ($disk) {
return [
'key' => $disk['key'] ?? '',
'label' => $disk['value']['label'] ?? '',
@@ -1361,7 +1379,7 @@ Route::prefix('v1')
'type' => $disk['value']['type'] ?? '',
];
}, $vmInfo['value']['disks'] ?? []),
'nics' => array_map(function($nic) {
'nics' => array_map(function ($nic) {
return [
'key' => $nic['key'] ?? '',
'label' => $nic['value']['label'] ?? '',