diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index ba4ddf7..1dfffe8 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -23,11 +23,11 @@ public function login(){ public function loginAction(LoginRequest $request){ $validatedData = $request->validated(); - if(Auth::attempt($validatedData)){ + if(Auth::attempt(['email' => $validatedData['email'], 'password' => $validatedData['password']])){ $request->session()->regenerate(); return redirect()->intended('/dashboard/overview'); }else{ - return redirect()->back()->with('failed-status', 'Pastikan data benar dan akun sudah terdaftar.'); + return redirect()->back()->with('failed-status', 'Pastikan data dan akun sudah terdaftar.'); } } diff --git a/app/Http/Requests/LoginRequest.php b/app/Http/Requests/LoginRequest.php index 68731a4..763a0b1 100644 --- a/app/Http/Requests/LoginRequest.php +++ b/app/Http/Requests/LoginRequest.php @@ -28,7 +28,8 @@ public function rules(): array 'password' => ['required' => Password::min(8) ->mixedCase() ->numbers() - ->symbols()] + ->symbols()], + 'g-recaptcha-response' => 'recaptcha', ]; } diff --git a/composer.json b/composer.json index 2a57ba0..a1bb350 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "license": "MIT", "require": { "php": "^8.2", + "biscolab/laravel-recaptcha": "^6.1", "laravel/framework": "^11.31", "laravel/tinker": "^2.9", "maatwebsite/excel": "^3.1", diff --git a/composer.lock b/composer.lock index 4f7a5c2..d860d05 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,80 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5c58a50b4393d487354e2e3d976a3d16", + "content-hash": "3c05bddedb1d2b1f538ace6db6f4b8d1", "packages": [ + { + "name": "biscolab/laravel-recaptcha", + "version": "v6.1.0", + "source": { + "type": "git", + "url": "https://github.com/biscolab/laravel-recaptcha.git", + "reference": "440fc617cba9f39aab7fda5d7697b76a55286e31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/biscolab/laravel-recaptcha/zipball/440fc617cba9f39aab7fda5d7697b76a55286e31", + "reference": "440fc617cba9f39aab7fda5d7697b76a55286e31", + "shasum": "" + }, + "require": { + "illuminate/routing": "^7.0|^8.0|^9.0|^10.0|^11.0", + "illuminate/support": "^7.0|^8.0|^9.0|^10.0|^11.0", + "php": "^7.3|^8.0" + }, + "require-dev": { + "orchestra/testbench": "5.*|6.*|^7.0|^8.0|^9.0", + "phpunit/phpunit": "^9.1|^10.5" + }, + "suggest": { + "biscolab/laravel-authlog": "It allows to handle logged-in users and force log-out if needed" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Biscolab\\ReCaptcha\\ReCaptchaServiceProvider" + ], + "aliases": { + "ReCaptcha": "Biscolab\\ReCaptcha\\Facades\\ReCaptcha" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Biscolab\\ReCaptcha\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roberto Belotti", + "email": "roby.belotti@gmail.com", + "homepage": "https://biscolab.com", + "role": "Developer" + } + ], + "description": "Simple and painless Google reCAPTCHA package for Laravel framework", + "homepage": "https://biscolab.com/laravel-recaptcha", + "keywords": [ + "captcha", + "laravel", + "recaptcha", + "validation" + ], + "support": { + "issues": "https://github.com/biscolab/laravel-recaptcha/issues", + "source": "https://github.com/biscolab/laravel-recaptcha/tree/v6.1.0" + }, + "abandoned": true, + "time": "2024-03-27T11:06:21+00:00" + }, { "name": "brick/math", "version": "0.12.3", diff --git a/config/recaptcha.php b/config/recaptcha.php new file mode 100644 index 0000000..f1b23b8 --- /dev/null +++ b/config/recaptcha.php @@ -0,0 +1,179 @@ + env('RECAPTCHA_SITE_KEY', ''), + + /** + * + * The secret key + * get secret key @ www.google.com/recaptcha/admin + * + */ + 'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''), + + /** + * + * ReCATCHA version + * Supported: "v2", "invisible", "v3", + * + * get more info @ https://developers.google.com/recaptcha/docs/versions + * + */ + 'version' => 'v2', + + /** + * + * The curl timout in seconds to validate a recaptcha token + * @since v3.5.0 + * + */ + 'curl_timeout' => 10, + + /** + * + * IP addresses for which validation will be skipped + * IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed + * + */ + 'skip_ip' => env('RECAPTCHA_SKIP_IP', []), + + /** + * + * Default route called to check the Google reCAPTCHA token + * @since v3.2.0 + * + */ + 'default_validation_route' => 'biscolab-recaptcha/validate', + + /** + * + * The name of the parameter used to send Google reCAPTCHA token to verify route + * @since v3.2.0 + * + */ + 'default_token_parameter_name' => 'token', + + /** + * + * The default Google reCAPTCHA language code + * It has no effect with v3 + * @see https://developers.google.com/recaptcha/docs/language + * @since v3.6.0 + * + */ + 'default_language' => null, + + /** + * + * The default form ID. Only for "invisible" reCAPTCHA + * @since v4.0.0 + * + */ + 'default_form_id' => 'biscolab-recaptcha-invisible-form', + + /** + * + * Deferring the render can be achieved by specifying your onload callback function and adding parameters to the JavaScript resource. + * It has no effect with v3 and invisible + * @see https://developers.google.com/recaptcha/docs/display#explicit_render + * @since v4.0.0 + * Supported true, false + * + */ + 'explicit' => false, + + /** + * + * Set API domain. You can use "www.recaptcha.net" in case "www.google.com" is not accessible. + * (no check will be made on the entered value) + * @see https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally + * @since v4.3.0 + * Default 'www.google.com' (ReCaptchaBuilder::DEFAULT_RECAPTCHA_API_DOMAIN) + * + */ + 'api_domain' => 'www.google.com', + + /** + * + * Set `true` when the error message must be null + * @since v5.1.0 + * Default false + * + */ + 'empty_message' => false, + + /** + * + * Set either the error message or the errom message translation key + * @since v5.1.0 + * Default 'validation.recaptcha' + * + */ + 'error_message_key' => 'validation.recaptcha', + + /** + * + * g-recaptcha tag attributes and grecaptcha.render parameters (v2 only) + * @see https://developers.google.com/recaptcha/docs/display#render_param + * @since v4.0.0 + */ + 'tag_attributes' => [ + + /** + * The color theme of the widget. + * Supported "light", "dark" + */ + 'theme' => 'light', + + /** + * The size of the widget. + * Supported "normal", "compact" + */ + 'size' => 'normal', + + /** + * The tabindex of the widget and challenge. + * If other elements in your page use tabindex, it should be set to make user navigation easier. + */ + 'tabindex' => 0, + + /** + * The name of your callback function, executed when the user submits a successful response. + * The g-recaptcha-response token is passed to your callback. + * DO NOT SET "biscolabOnloadCallback" + */ + 'callback' => null, + + /** + * The name of your callback function, executed when the reCAPTCHA response expires and the user needs to re-verify. + * DO NOT SET "biscolabOnloadCallback" + */ + 'expired-callback' => null, + + /** + * The name of your callback function, executed when reCAPTCHA encounters an error (usually network connectivity) and cannot continue until connectivity is restored. + * If you specify a function here, you are responsible for informing the user that they should retry. + * DO NOT SET "biscolabOnloadCallback" + */ + 'error-callback' => null, + ] +]; diff --git a/public/assets/dashboard/css/custom.css b/public/assets/dashboard/css/custom.css index 4310aab..1128aa5 100644 --- a/public/assets/dashboard/css/custom.css +++ b/public/assets/dashboard/css/custom.css @@ -156,3 +156,8 @@ .pdf-label{ font-size: 0.6rem !important; color: grey !important; } + +.captcha-error { + border: 2px dotted red; + padding: 0.5rem 0rem !important; +} diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 17c0f3f..d4d249b 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -69,6 +69,14 @@ {{$message}} @enderror + {!! ReCaptcha::htmlScriptTagJsApi() !!} +
+
+ {!! htmlFormSnippet() !!}
+