From e2bfbe5868e9f4c004893d0cd45a03cf93438343 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Fri, 29 Jul 2022 19:22:54 +0200 Subject: [PATCH] Bind TwoFAccountService to Service Container --- .../v1/Controllers/TwoFAccountController.php | 2 -- app/Http/Controllers/Auth/UserController.php | 23 +------------------ app/Providers/TwoFAuthServiceProvider.php | 7 ++++++ .../Services/TwoFAccountServiceTest.php | 3 ++- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/app/Api/v1/Controllers/TwoFAccountController.php b/app/Api/v1/Controllers/TwoFAccountController.php index 84e39bcd..cf62f31f 100644 --- a/app/Api/v1/Controllers/TwoFAccountController.php +++ b/app/Api/v1/Controllers/TwoFAccountController.php @@ -3,7 +3,6 @@ namespace App\Api\v1\Controllers; use App\Models\TwoFAccount; -use App\Exceptions\UndecipherableException; use App\Api\v1\Requests\TwoFAccountReorderRequest; use App\Api\v1\Requests\TwoFAccountStoreRequest; use App\Api\v1\Requests\TwoFAccountUpdateRequest; @@ -17,7 +16,6 @@ use App\Services\GroupService; use App\Services\TwoFAccountService; use Illuminate\Support\Arr; -use Illuminate\Support\Str; use Illuminate\Http\Request; use App\Http\Controllers\Controller; diff --git a/app/Http/Controllers/Auth/UserController.php b/app/Http/Controllers/Auth/UserController.php index ccb75f55..ce51d078 100644 --- a/app/Http/Controllers/Auth/UserController.php +++ b/app/Http/Controllers/Auth/UserController.php @@ -2,8 +2,6 @@ namespace App\Http\Controllers\Auth; -use App\Models\User; -use App\Services\TwoFAccountService; use App\Http\Requests\UserUpdateRequest; use App\Http\Requests\UserDeleteRequest; use App\Api\v1\Resources\UserResource; @@ -12,28 +10,9 @@ use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Artisan; -use Exception; class UserController extends Controller -{ - /** - * The TwoFAccount Service instance. - */ - protected $twofaccountService; - - - /** - * Create a new controller instance. - * - * @param \App\Services\TwoFAccountService $twofaccountService - * @return void - */ - public function __construct(TwoFAccountService $twofaccountService) - { - $this->twofaccountService = $twofaccountService; - } - - +{ /** * Update the user's profile information. * diff --git a/app/Providers/TwoFAuthServiceProvider.php b/app/Providers/TwoFAuthServiceProvider.php index 18e5e36d..57ac29aa 100644 --- a/app/Providers/TwoFAuthServiceProvider.php +++ b/app/Providers/TwoFAuthServiceProvider.php @@ -6,6 +6,7 @@ use App\Services\QrCodeService; use App\Services\SettingService; use App\Services\GroupService; +use App\Services\TwoFAccountService; use Illuminate\Support\ServiceProvider; use Illuminate\Contracts\Support\DeferrableProvider; @@ -33,6 +34,10 @@ public function register() $this->app->singleton(QrCodeService::class, function () { return new QrCodeService(); }); + + $this->app->singleton(TwoFAccountService::class, function () { + return new TwoFAccountService(); + }); } /** @@ -54,8 +59,10 @@ public function boot() public function provides() { return [ + GroupService::class, LogoService::class, QrCodeService::class, + TwoFAccountService::class, ]; } } diff --git a/tests/Feature/Services/TwoFAccountServiceTest.php b/tests/Feature/Services/TwoFAccountServiceTest.php index 217047aa..69e33c55 100644 --- a/tests/Feature/Services/TwoFAccountServiceTest.php +++ b/tests/Feature/Services/TwoFAccountServiceTest.php @@ -6,6 +6,7 @@ use App\Models\TwoFAccount; use Tests\FeatureTestCase; use Tests\Classes\OtpTestData; +use App\Services\TwoFAccountService; /** @@ -44,7 +45,7 @@ public function setUp() : void { parent::setUp(); - $this->twofaccountService = $this->app->make('App\Services\TwoFAccountService'); + $this->twofaccountService = $this->app->make(TwoFAccountService::class); $this->customTotpTwofaccount = new TwoFAccount; $this->customTotpTwofaccount->legacy_uri = OtpTestData::TOTP_FULL_CUSTOM_URI;