diff --git a/app/application/.env.example b/app/application/.env.example index e77cefd..78bdd22 100644 --- a/app/application/.env.example +++ b/app/application/.env.example @@ -6,6 +6,12 @@ APP_URL=http://localhost APP_FORCE_HTTPS=false +APP_CAPTCHA=false +CAPTCHA_API_DOMAIN=http://your-domain-captcha-or-IP:8081 +CAPTCHA_PRIVATE_TOKEN= +CAPTCHA_STATIC_PATH=http://your-domain-captcha-or-IP:8081/captcha +CAPTCHA_PUBLIC_TOKEN= + APP_DEMO_MODE=false APP_DEMO_EMAIL= APP_DEMO_PASSWORD= diff --git a/app/application/app/Http/Controllers/AuthController.php b/app/application/app/Http/Controllers/AuthController.php index 096f082..b32e1de 100644 --- a/app/application/app/Http/Controllers/AuthController.php +++ b/app/application/app/Http/Controllers/AuthController.php @@ -19,7 +19,9 @@ public function __construct( public function login(): View { - return view('public/login'); + return view('public/login', [ + 'captcha' => config('app.captcha', false) + ]); } public function authorization(AuthorizationRequest $request): RedirectResponse diff --git a/app/application/app/Http/Requests/AuthorizationRequest.php b/app/application/app/Http/Requests/AuthorizationRequest.php index f4ed7af..c7dae76 100644 --- a/app/application/app/Http/Requests/AuthorizationRequest.php +++ b/app/application/app/Http/Requests/AuthorizationRequest.php @@ -13,11 +13,17 @@ final class AuthorizationRequest extends FormRequest implements FormRequestDto */ public function rules(): array { - return [ + $rules = [ 'email' => ['required', 'email', 'max:255'], 'password' => ['required', 'min:3'], 'remember' => ['nullable', 'boolean'], ]; + + if (config('app.captcha', false)) { + $rules['captcha-verified'] = ['captcha']; + } + + return $rules; } public function getDto(): Authorization diff --git a/app/application/composer.json b/app/application/composer.json index 2365235..104ec0e 100644 --- a/app/application/composer.json +++ b/app/application/composer.json @@ -7,6 +7,7 @@ "require": { "php": "^8.3", "guzzlehttp/guzzle": "^7.2", + "kor-elf/captcha-rule-for-laravel": "^1.0", "laravel/framework": "^11.0", "laravel/sanctum": "^4.0", "laravel/tinker": "^2.8" diff --git a/app/application/composer.lock b/app/application/composer.lock index 0ba478a..f015161 100644 --- a/app/application/composer.lock +++ b/app/application/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "680bb583053c6714b7b932ef1d099191", + "content-hash": "94e26ab4b33fa6f72cca1475dace5690", "packages": [ { "name": "brick/math", @@ -1045,6 +1045,56 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "kor-elf/captcha-rule-for-laravel", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://git.kor-elf.net/kor-elf/captcha-rule-for-laravel", + "reference": "b2c9242d51059bcd4275da6544134d8f28f08750" + }, + "require": { + "guzzlehttp/guzzle": "^7.0.1", + "illuminate/support": "^10.0|^11.0", + "php": "^8.2" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "korElf\\CaptchaRuleForLaravel\\CaptchaProvider" + ] + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "korElf\\CaptchaRuleForLaravel\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Leonid Nikitin", + "email": "i@kor-elf.net", + "homepage": "https://git.kor-elf.net/kor-elf", + "role": "Developer" + } + ], + "description": "Validation Rule Captcha for Laravel", + "homepage": "https://git.kor-elf.net/kor-elf/captcha-rule-for-laravel", + "keywords": [ + "captcha", + "laravel", + "validation" + ], + "time": "2024-04-02T17:36:12+00:00" + }, { "name": "laravel/framework", "version": "v11.5.0", diff --git a/app/application/config/app.php b/app/application/config/app.php index 6235015..c9dcca0 100644 --- a/app/application/config/app.php +++ b/app/application/config/app.php @@ -42,6 +42,15 @@ 'demo_email' => env('APP_DEMO_EMAIL', false), 'demo_password' => env('APP_DEMO_PASSWORD', false), + /* + |-------------------------------------------------------------------------- + | Сaptcha + |-------------------------------------------------------------------------- + | + | Enables or disables captcha. + */ + 'captcha' => (bool) env('APP_CAPTCHA', false), + /* |-------------------------------------------------------------------------- | Application Debug Mode diff --git a/app/application/lang/en/validation.php b/app/application/lang/en/validation.php index 0e251fb..ffd8e0b 100644 --- a/app/application/lang/en/validation.php +++ b/app/application/lang/en/validation.php @@ -142,6 +142,7 @@ 'url' => 'The :attribute format is invalid.', 'uuid' => 'The :attribute must be a valid UUID.', 'no_type' => 'The :attribute can only use: :type.', + 'captcha' => 'Failed to pass human verification.', 'attributes' => [ 'address' => 'address', 'age' => 'age', diff --git a/app/application/lang/ru/validation.php b/app/application/lang/ru/validation.php index 3a75b75..dfe3ba2 100644 --- a/app/application/lang/ru/validation.php +++ b/app/application/lang/ru/validation.php @@ -142,6 +142,7 @@ 'url' => 'Значение поля :attribute имеет ошибочный формат URL.', 'uuid' => 'Значение поля :attribute должно быть корректным UUID.', 'no_type' => 'Значение поля :attribute может использовать только: :type.', + 'captcha' => 'Не удалось пройти проверку человеком.', 'attributes' => [ 'address' => 'адрес', 'age' => 'возраст', diff --git a/app/application/resources/views/public/login.blade.php b/app/application/resources/views/public/login.blade.php index 472f602..d7f7f77 100644 --- a/app/application/resources/views/public/login.blade.php +++ b/app/application/resources/views/public/login.blade.php @@ -50,6 +50,11 @@ + @if($captcha) +
+ @captcha +
+ @endif
diff --git a/app/docker/Dockerfile b/app/docker/Dockerfile index 6b7bcc1..e0c8fc1 100644 --- a/app/docker/Dockerfile +++ b/app/docker/Dockerfile @@ -48,32 +48,32 @@ RUN apk --no-cache add pcre2 libbz2 libpng libwebp libjpeg-turbo icu-libs freety && ln -sf /dev/stdout /var/log/unit.log \ && addgroup -S unit && adduser -S unit -G unit -#FROM BUILD as APP_BUILD_FOR_PRODUCTION -#WORKDIR /home/app -# -#COPY application /home/app -# -#RUN apk --no-cache add git nodejs npm \ -# && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ -# && composer install --optimize-autoloader --no-dev \ -# && npm install && npm run build \ -# && rm -rf /home/app/node_modules /home/app/.env -# -# -#FROM BUILD AS PRODUCTION -# -#COPY --from=APP_BUILD_FOR_PRODUCTION /home/app /var/www/html -#COPY docker/docker-entrypoint_prod.sh /home/unit/docker-entrypoint.sh -# -#WORKDIR /var/www/html -# -#RUN chmod 755 /home/unit/docker-entrypoint.sh -# -#STOPSIGNAL SIGTERM -# -#ENTRYPOINT ["/home/unit/docker-entrypoint.sh"] -#EXPOSE 9000 -#CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock", "--user", "unit", "--group", "unit"] +FROM BUILD as APP_BUILD_FOR_PRODUCTION +WORKDIR /home/app + +COPY application /home/app + +RUN apk --no-cache add git nodejs npm \ + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + && composer install --optimize-autoloader --no-dev \ + && npm install && npm run build \ + && rm -rf /home/app/node_modules /home/app/.env + + +FROM BUILD AS PRODUCTION + +COPY --from=APP_BUILD_FOR_PRODUCTION /home/app /var/www/html +COPY docker/docker-entrypoint_prod.sh /home/unit/docker-entrypoint.sh + +WORKDIR /var/www/html + +RUN chmod 755 /home/unit/docker-entrypoint.sh + +STOPSIGNAL SIGTERM + +ENTRYPOINT ["/home/unit/docker-entrypoint.sh"] +EXPOSE 9000 +CMD ["unitd", "--no-daemon", "--control", "unix:/var/run/control.unit.sock", "--user", "unit", "--group", "unit"] FROM BUILD AS DEVELOP @@ -105,7 +105,8 @@ FROM BUILD AS COMPOSER WORKDIR /var/www/html STOPSIGNAL SIGTERM RUN apk --no-cache add git \ - && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \ + && mkdir /.composer && chmod 0777 /.composer ENTRYPOINT ["composer"]