diff --git a/backend/app/User/Controllers/GatewayManagementController.php b/backend/app/User/Controllers/GatewayManagementController.php index 690d364e..d8ce7ce6 100644 --- a/backend/app/User/Controllers/GatewayManagementController.php +++ b/backend/app/User/Controllers/GatewayManagementController.php @@ -14,6 +14,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; +use Laravel\Passport\ClientRepository; use Throwable; class GatewayManagementController extends Controller @@ -27,7 +28,7 @@ class GatewayManagementController extends Controller $request, allowedFilters: ['*'], allowedSortings: ['*'], - allowedSelects: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', 'business_type_id', 'business_type_name'], + allowedSelects: ['*'], ); } @@ -38,9 +39,15 @@ class GatewayManagementController extends Controller { $user = Auth::guard('web')->user(); - $logo = $request->has('logo') ? FileFacade::save($request->file('logo'), "{$user->id}") : null; + $logo = $request->hasFile('logo') + ? FileFacade::save($request->file('logo'), "{$user->id}") + : null; + + $passportClient = DB::transaction(function () use ($user, $logo, $request) { + + $clientName = "Gateway {$request->name} - User {$user->id}"; + $client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users'); - DB::transaction(function () use ($user, $logo, $request) { UserGateway::query()->create([ 'user_id' => $user->id, 'username' => $user->username, @@ -53,15 +60,20 @@ class GatewayManagementController extends Controller 'business_type_id' => $request->business_type_id, 'business_type_name' => BusinessTypeEnum::name($request->business_type_id), 'logo' => $logo, + 'client_id' => $client->id, + 'client_secret' => $client->secret, ]); $user->update(['authority_level' => 1]); + + return $client; }); - - return $this->successResponse(); + return $this->successResponse([ + 'client_id' => $passportClient->id, + 'client_secret' => $passportClient->secret, + ]); } - public function show(UserGateway $gateway): JsonResponse { return $this->successResponse($gateway); diff --git a/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php b/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php new file mode 100644 index 00000000..db86590a --- /dev/null +++ b/backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php @@ -0,0 +1,30 @@ +string('client_id')->nullable(); + $table->string('client_secret')->nullable(); + $table->integer('status')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('user_gateways', function (Blueprint $table) { + $table->dropColumn(['client_id', 'client_secret','status']); + }); + } +}; diff --git a/backend/routes/expert.php b/backend/routes/expert.php index 40a27bdd..79cbd0c2 100755 --- a/backend/routes/expert.php +++ b/backend/routes/expert.php @@ -77,7 +77,7 @@ Route::prefix('expert') Route::prefix('profile') ->name('profile.') - ->middleware('auth') + ->middleware('auth:expert') ->controller(ProfileController::class) ->group(function () { Route::get('info', 'info')->name('info');