Added functionalities to restrict certain user operations like update, password change, and deletion in demo mode. This is done to prevent demo users from modifying crucial data. Helper methods are created for standard re-usable checks. Also, Blade directive is added for frontend UI demo checks.
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php declare(strict_types=1);
 | 
						|
 | 
						|
namespace App\Providers;
 | 
						|
 | 
						|
use App\Captcha\Contracts\ImageBody;
 | 
						|
use App\Captcha\Contracts\ImageHead;
 | 
						|
use App\Captcha\Contracts\ImageLines;
 | 
						|
use App\Captcha\Contracts\ImageManager as ImageManagerContract;
 | 
						|
use App\Captcha\Images\Body;
 | 
						|
use App\Captcha\Images\Head;
 | 
						|
use App\Captcha\Images\ImageManager;
 | 
						|
use App\Captcha\Images\Lines;
 | 
						|
use App\Contracts\CryptographyContract;
 | 
						|
use App\Helpers\Helpers;
 | 
						|
use App\Services\Api\V1\CaptchaGenerateService;
 | 
						|
use App\Services\CaptchaToken\CaptchaTokenHandler;
 | 
						|
use App\Services\CryptographyString;
 | 
						|
use App\Services\GenerateTokenCommand\GenerateTokenUlidCommand;
 | 
						|
use App\Services\GenerateTokenCommand\GenerateTokenUuidCommand;
 | 
						|
use App\Services\Search\CreateSearchInstanceCommand;
 | 
						|
use App\Services\Search\Search;
 | 
						|
use Illuminate\Contracts\Foundation\Application;
 | 
						|
use Illuminate\Pagination\Paginator;
 | 
						|
use Illuminate\Support\Facades\Blade;
 | 
						|
use Illuminate\Support\ServiceProvider;
 | 
						|
use Illuminate\Validation\Rules\Password;
 | 
						|
 | 
						|
final class AppServiceProvider extends ServiceProvider
 | 
						|
{
 | 
						|
    /**
 | 
						|
     * Register any application services.
 | 
						|
     */
 | 
						|
    public function register(): void
 | 
						|
    {
 | 
						|
        $this->app->bind(ImageManagerContract::class, function () {
 | 
						|
            return new ImageManager(imageClassName: config('captcha.imageClass'));
 | 
						|
        });
 | 
						|
        $this->app->bind(ImageHead::class, Head::class);
 | 
						|
        $this->app->bind(ImageBody::class, Body::class);
 | 
						|
        $this->app->bind(ImageLines::class, Lines::class);
 | 
						|
 | 
						|
        $this->app->bind(CryptographyContract::class, CryptographyString::class);
 | 
						|
 | 
						|
        $this->app->bind(CreateSearchInstanceCommand::class, function () {
 | 
						|
            return new CreateSearchInstanceCommand(Search::class);
 | 
						|
        });
 | 
						|
 | 
						|
        $this->app->bind(CaptchaGenerateService::class, function (Application $app) {
 | 
						|
            return new CaptchaGenerateService(
 | 
						|
                config: config('captcha', []),
 | 
						|
                imageHead: $app->make(ImageHead::class),
 | 
						|
                imageBody: $app->make(ImageBody::class)
 | 
						|
            );
 | 
						|
        });
 | 
						|
 | 
						|
        $this->app->bind(CaptchaTokenHandler::class, function (Application $app) {
 | 
						|
            return new CaptchaTokenHandler(
 | 
						|
                generatePublicTokenCommand: $app->make(GenerateTokenUlidCommand::class),
 | 
						|
                generatePrivateTokenCommand: $app->make(GenerateTokenUuidCommand::class)
 | 
						|
            );
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Bootstrap any application services.
 | 
						|
     */
 | 
						|
    public function boot(): void
 | 
						|
    {
 | 
						|
        Blade::if('demo', function () {
 | 
						|
            return Helpers::isDemoMode();
 | 
						|
        });
 | 
						|
 | 
						|
        Password::defaults(function () {
 | 
						|
            $rule = Password::min(8);
 | 
						|
 | 
						|
            return $this->app->isProduction()
 | 
						|
                ? $rule->letters()
 | 
						|
                       ->mixedCase()
 | 
						|
                       ->numbers()
 | 
						|
                       ->symbols()
 | 
						|
                       ->uncompromised()
 | 
						|
                : $rule;
 | 
						|
        });
 | 
						|
 | 
						|
        Paginator::useBootstrapFive();
 | 
						|
    }
 | 
						|
}
 |