*/ #[\Override] protected $policies = [ // * Policies Exceptions BasketDto::class => BasketPolicy::class, BasketProductDto::class => BasketPolicy::class, DiscountDto::class => DiscountPolicy::class, FaqDto::class => FaqPolicy::class, PageDto::class => PagePolicy::class, PickupExceptionDto::class => PickupExceptionPolicy::class, ProductDto::class => ProductPolicy::class, ProductWithPricingDto::class => FrontendProductPolicy::class, RangeDto::class => RangePolicy::class, Setting::class => SettingPolicy::class, SettingDto::class => SettingPolicy::class, ShopDto::class => ShopPolicy::class, SlideDto::class => SlidePolicy::class, TagDto::class => TagPolicy::class, FetchAndUpsertArcadiaEmployees::class => EmployeePolicy::class, ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->app->singleton( AppAdminAuthService::class, fn (Application $app): AppAdminAuthService => new AppAdminAuthService( Auth::guard('backend') ) ); $this->app->singleton( AppCustomerAuthService::class, fn (Application $app): AppCustomerAuthService => new AppCustomerAuthService( Auth::guard('frontend'), $app->make(CrmService::class) ) ); Auth::shouldUse($this->currentRouteGuard()); Gate::define( 'customerPassOrders', fn (Customer $customer): bool => resolve(ShopperService::class) ->canCustomerPassOrdersApp($customer->getId()) ); $this->registerPolicies(); Gate::guessPolicyNamesUsing(function (string $modelClass) { $context = $this->currentRouteGuard() === 'frontend' ? 'Frontend' : 'Backend'; $classBasename = str_replace('Dto', '', class_basename($modelClass)); $policyClass = "App\\Policies\\{$context}\\{$classBasename}Policy"; return class_exists($policyClass) ? $policyClass : null; }); $this->authUrlCallbacksSetup(); } private function authUrlCallbacksSetup(): void { VerifyEmail::createUrlUsing($this->createEmailVerificationUrl(...)); ResetPassword::createUrlUsing($this->createPasswordResetUrl(...)); } private function createEmailVerificationUrl(mixed $notifiable): string { if (! $notifiable instanceof Customer) { throw new \InvalidArgumentException('Invalid notifiable provided.'); } $appKey = Config::string('app.key'); if (empty(trim($appKey))) { throw new \UnexpectedValueException('App key is not set.'); } return url( URL::temporarySignedRoute( 'fo.auth.verification.verify', Date::now()->addMinutes(Config::integer('auth.verification.expire', 60)), [ 'id' => $notifiable->getKey(), 'hash' => hash_hmac( 'sha256', $notifiable->getEmailForVerification(), $appKey ), ], false ) ); } private function createPasswordResetUrl(mixed $notifiable, string $token): string { if (! $notifiable instanceof Customer) { throw new \InvalidArgumentException('Invalid notifiable provided.'); } return url( URL::temporarySignedRoute( 'fo.auth.reset-password', Date::now()->addMinutes(Config::integer('auth.reset.expire', 60)), [ 'token' => $token, 'email' => $notifiable->getEmailForPasswordReset(), ], false ) ); } private function currentRouteGuard(): string { $request = $this->app->make(Request::class); $defaultGuard = Config::string('auth.defaults.guard', 'frontend'); return match (true) { $request->is('bo', 'bo/*') => 'backend', $request->is('api', 'api/*') => 'api', default => $defaultGuard, }; } }