From 392fca86350dc03a8063a825d471b6dd05c185f1 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Jun 2026 15:26:09 +0330 Subject: [PATCH 1/4] add three column in user_gateways and use them in controller --- .../GatewayManagementController.php | 31 ++++++++++++++----- ...ent_credentials_to_user_gateways_table.php | 30 ++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 backend/database/migrations/2026_06_01_102551_add_client_credentials_to_user_gateways_table.php diff --git a/backend/app/User/Controllers/GatewayManagementController.php b/backend/app/User/Controllers/GatewayManagementController.php index 690d364e..51fa183a 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,8 @@ 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: ['id', 'name', 'domain', 'tax_id', 'bank_name', 'account_holder', 'iban', + 'business_type_id', 'business_type_name','created_at', 'status'], ); } @@ -38,10 +40,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; - DB::transaction(function () use ($user, $logo, $request) { - UserGateway::query()->create([ + $result = DB::transaction(function () use ($user, $logo, $request) { + $client = app(ClientRepository::class) + ->createClientCredentialsGrantClient($request->name); + + $gateway = UserGateway::query()->create([ 'user_id' => $user->id, 'username' => $user->username, 'name' => $request->name, @@ -53,15 +60,25 @@ class GatewayManagementController extends Controller 'business_type_id' => $request->business_type_id, 'business_type_name' => BusinessTypeEnum::name($request->business_type_id), 'logo' => $logo, + + // save Passport client info in your own table + 'client_id' => $client->id, + 'client_secret' => $client->secret, ]); $user->update(['authority_level' => 1]); + + return [ + 'gateway' => $gateway, + 'client' => $client, + ]; }); - - return $this->successResponse(); + return $this->successResponse([ + 'client_id' => $result['client']->id, + 'client_secret' => $result['client']->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..29c56dce --- /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')->unique()->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'); + }); + } +}; -- 2.49.1 From a1466d8f576491084926e72d5e809076aa1bc89b Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Jun 2026 15:33:06 +0330 Subject: [PATCH 2/4] fix migration --- ..._01_102551_add_client_credentials_to_user_gateways_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 29c56dce..e4c49c57 100644 --- 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 @@ -24,7 +24,7 @@ return new class extends Migration public function down(): void { Schema::table('user_gateways', function (Blueprint $table) { - $table->dropColumn('client_id', 'client_secret','status'); + $table->dropColumn(['client_id', 'client_secret','status']); }); } }; -- 2.49.1 From 69ffe322ce75d0a029dd641a67bdf81e98806e13 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Jun 2026 15:34:54 +0330 Subject: [PATCH 3/4] fix migration --- ..._01_102551_add_client_credentials_to_user_gateways_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e4c49c57..db86590a 100644 --- 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 @@ -12,7 +12,7 @@ return new class extends Migration public function up(): void { Schema::table('user_gateways', function (Blueprint $table) { - $table->string('client_id')->unique()->nullable(); + $table->string('client_id')->nullable(); $table->string('client_secret')->nullable(); $table->integer('status')->default(0); }); -- 2.49.1 From 675d2bdbad7e69ddeadc7be6c82de4070dc5fc2b Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Mon, 1 Jun 2026 16:36:02 +0330 Subject: [PATCH 4/4] fix clied password nd fix rote for expert --- .../GatewayManagementController.php | 23 ++++++++----------- backend/routes/expert.php | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/backend/app/User/Controllers/GatewayManagementController.php b/backend/app/User/Controllers/GatewayManagementController.php index 51fa183a..d8ce7ce6 100644 --- a/backend/app/User/Controllers/GatewayManagementController.php +++ b/backend/app/User/Controllers/GatewayManagementController.php @@ -28,8 +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','created_at', 'status'], + allowedSelects: ['*'], ); } @@ -44,11 +43,12 @@ class GatewayManagementController extends Controller ? FileFacade::save($request->file('logo'), "{$user->id}") : null; - $result = DB::transaction(function () use ($user, $logo, $request) { - $client = app(ClientRepository::class) - ->createClientCredentialsGrantClient($request->name); + $passportClient = DB::transaction(function () use ($user, $logo, $request) { - $gateway = UserGateway::query()->create([ + $clientName = "Gateway {$request->name} - User {$user->id}"; + $client = app(ClientRepository::class)->createPasswordGrantClient($clientName, 'users'); + + UserGateway::query()->create([ 'user_id' => $user->id, 'username' => $user->username, 'name' => $request->name, @@ -60,23 +60,18 @@ class GatewayManagementController extends Controller 'business_type_id' => $request->business_type_id, 'business_type_name' => BusinessTypeEnum::name($request->business_type_id), 'logo' => $logo, - - // save Passport client info in your own table 'client_id' => $client->id, 'client_secret' => $client->secret, ]); $user->update(['authority_level' => 1]); - return [ - 'gateway' => $gateway, - 'client' => $client, - ]; + return $client; }); return $this->successResponse([ - 'client_id' => $result['client']->id, - 'client_secret' => $result['client']->secret, + 'client_id' => $passportClient->id, + 'client_secret' => $passportClient->secret, ]); } public function show(UserGateway $gateway): JsonResponse 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'); -- 2.49.1