From 01fef431b164f985e12c94a5ef906253f291e9d5 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 25 Jun 2021 17:06:47 +0530 Subject: [PATCH 01/15] Captcha Backend Completed --- config/app.php | 30 +++-- packages/Webkul/Customer/src/Captcha.php | 127 ++++++++++++++++++ .../Webkul/Customer/src/Contracts/Captcha.php | 10 ++ .../Webkul/Customer/src/Facades/Captcha.php | 18 +++ .../Http/Controllers/SessionController.php | 9 +- .../src/Providers/CustomerServiceProvider.php | 19 ++- 6 files changed, 197 insertions(+), 16 deletions(-) create mode 100644 packages/Webkul/Customer/src/Captcha.php create mode 100644 packages/Webkul/Customer/src/Contracts/Captcha.php create mode 100644 packages/Webkul/Customer/src/Facades/Captcha.php diff --git a/config/app.php b/config/app.php index 1aff706f6..ea88f140c 100755 --- a/config/app.php +++ b/config/app.php @@ -297,6 +297,11 @@ return [ 'aliases' => [ + /** + * Laravel + * + * Place your aliases in alphabetical order. + */ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, @@ -330,18 +335,25 @@ return [ 'URL' => Illuminate\Support\Facades\URL::class, 'Validator' => Illuminate\Support\Facades\Validator::class, 'View' => Illuminate\Support\Facades\View::class, - 'Datagrid' => Webkul\Ui\DataGrid\Facades\DataGrid::class, - 'ProductGrid' => Webkul\Ui\DataGrid\Facades\ProductGrid::class, - 'Image' => Intervention\Image\Facades\Image::class, + + /** + * Bagisto + * + * Place your aliases in alphabetical order. + */ + 'Captcha' => Webkul\Customer\Facades\Captcha::class, 'Cart' => Webkul\Checkout\Facades\Cart::class, - 'Core' => Webkul\Core\Facades\Core::class, - 'DbView' => Flynsarmy\DbBladeCompiler\Facades\DbView::class, - 'PDF' => Barryvdh\DomPDF\Facade::class, - 'Excel' => Maatwebsite\Excel\Facades\Excel::class, 'Concord' => Konekt\Concord\Facades\Concord::class, - 'Helper' => Konekt\Concord\Facades\Helper::class, + 'Core' => Webkul\Core\Facades\Core::class, + 'Datagrid' => Webkul\Ui\DataGrid\Facades\DataGrid::class, + 'DbView' => Flynsarmy\DbBladeCompiler\Facades\DbView::class, 'Debugbar' => Barryvdh\Debugbar\Facade::class, + 'Excel' => Maatwebsite\Excel\Facades\Excel::class, + 'Helper' => Konekt\Concord\Facades\Helper::class, + 'Image' => Intervention\Image\Facades\Image::class, + 'PDF' => Barryvdh\DomPDF\Facade::class, 'ProductImage' => Webkul\Product\Facades\ProductImage::class, - 'ProductVideo' => Webkul\Product\Facades\ProductVideo::class + 'ProductGrid' => Webkul\Ui\DataGrid\Facades\ProductGrid::class, + 'ProductVideo' => Webkul\Product\Facades\ProductVideo::class, ], ]; diff --git a/packages/Webkul/Customer/src/Captcha.php b/packages/Webkul/Customer/src/Captcha.php new file mode 100644 index 000000000..f382366b7 --- /dev/null +++ b/packages/Webkul/Customer/src/Captcha.php @@ -0,0 +1,127 @@ +siteKey = '6LcUYlYbAAAAALyF7D5IrwZgufgXBwBrjXlcndAt'; + + $this->secretKey = '6LcUYlYbAAAAAKi3vUJ62a9QEk4JvPfbLoizTajz'; + } + + /** + * Get client endpoint. + * + * @return string + */ + public function getClientEndpoint(): string + { + return static::CLIENT_ENDPOINT; + } + + /** + * Get site verify endpoint. + * + * @return string + */ + public function getSiteVerifyEndpoint(): string + { + return static::SITE_VERIFY_ENDPOINT; + } + + /** + * Render JS. + * + * @return string + */ + public function renderJS(): string + { + return ''; + } + + /** + * Render Captcha. + * + * @return string + */ + public function render(): string + { + $htmlAttributes = $this->buildHTMLAttributes($this->getAttributes()); + + return "
"; + } + + /** + * Validate response. + * + * @return bool + */ + public function validateResponse($response): bool + { + $client = new \GuzzleHttp\Client(); + + $response = $client->post(static::SITE_VERIFY_ENDPOINT, [ + 'query' => [ + 'secret' => '6LcUYlYbAAAAAKi3vUJ62a9QEk4JvPfbLoizTajz', + 'response' => $response + ] + ]); + + return json_decode($response->getBody())->success; + } + + /** + * Get attributes. + * + * @return array + */ + protected function getAttributes(): array + { + return [ + 'class' => 'g-recaptcha', + 'data-sitekey' => $this->siteKey, + ]; + } + + /** + * Build attributes. + * + * @param array $attributes + * @return string + */ + protected function buildHTMLAttributes(array $attributes): string + { + $htmlAttributes = []; + + foreach ($attributes as $key => $value) { + $htmlAttributes[] = "{$key}=\"{$value}\""; + } + + return count($htmlAttributes) + ? implode(' ', $htmlAttributes) + : ''; + } +} diff --git a/packages/Webkul/Customer/src/Contracts/Captcha.php b/packages/Webkul/Customer/src/Contracts/Captcha.php new file mode 100644 index 000000000..e38f8243d --- /dev/null +++ b/packages/Webkul/Customer/src/Contracts/Captcha.php @@ -0,0 +1,10 @@ +middleware('customer')->except(['show','create']); + $this->middleware('customer')->except(['show', 'create']); $this->_config = request('_config'); } @@ -50,6 +50,7 @@ class SessionController extends Controller $this->validate(request(), [ 'email' => 'required|email', 'password' => 'required', + 'g-recaptcha-response' => 'required|captcha', ]); if (! auth()->guard('customer')->attempt(request(['email', 'password']))) { @@ -98,4 +99,4 @@ class SessionController extends Controller return redirect()->route($this->_config['redirect']); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php index f12f69d6e..8bea3c8cf 100755 --- a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php +++ b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php @@ -3,12 +3,18 @@ namespace Webkul\Customer\Providers; use Illuminate\Database\Eloquent\Factory as EloquentFactory; -use Illuminate\Support\ServiceProvider; use Illuminate\Routing\Router; +use Illuminate\Support\ServiceProvider; +use Webkul\Customer\Captcha; use Webkul\Customer\Http\Middleware\RedirectIfNotCustomer; class CustomerServiceProvider extends ServiceProvider { + /** + * Bootstrap application services. + * + * @return void + */ public function boot(Router $router) { $router->aliasMiddleware('customer', RedirectIfNotCustomer::class); @@ -16,6 +22,10 @@ class CustomerServiceProvider extends ServiceProvider $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer'); $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + + $this->app['validator']->extend('captcha', function ($attribute, $value, $parameters) { + return $this->app['captcha']->validateResponse($value); + }); } /** @@ -27,13 +37,16 @@ class CustomerServiceProvider extends ServiceProvider public function register() { $this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories'); + + $this->app->singleton('captcha', function ($app) { + return new Captcha(); + }); } /** * Register factories. * - * @param string $path - * + * @param string $path * @return void * @throws \Illuminate\Contracts\Container\BindingResolutionException */ From 8b0f65f905ec78f8c96710b3e2d9a54f54eb4187 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 25 Jun 2021 17:25:40 +0530 Subject: [PATCH 02/15] Frontend Potion Completed! Now Dynamic Config Pending! --- .../Http/Controllers/SessionController.php | 16 +++++++-------- .../views/customers/session/index.blade.php | 20 +++++++++++++++---- .../shop/customers/session/index.blade.php | 8 ++++++++ 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php index 46c198516..bdacd3cdf 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php @@ -8,14 +8,14 @@ use Illuminate\Support\Facades\Event; class SessionController extends Controller { /** - * Contains route related configuration + * Contains route related configuration. * * @var array */ protected $_config; /** - * Create a new Repository instance. + * Create a new controller instance. * * @return void */ @@ -33,11 +33,9 @@ class SessionController extends Controller */ public function show() { - if (auth()->guard('customer')->check()) { - return redirect()->route('customer.profile.index'); - } else { - return view($this->_config['view']); - } + return auth()->guard('customer')->check() + ? redirect()->route('customer.profile.index') + : view($this->_config['view']); } /** @@ -79,7 +77,9 @@ class SessionController extends Controller return redirect()->back(); } - //Event passed to prepare cart after login + /** + * Event passed to prepare cart after login. + */ Event::dispatch('customer.after.login', request('email')); return redirect()->intended(route($this->_config['redirect'])); diff --git a/packages/Webkul/Shop/src/Resources/views/customers/session/index.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/session/index.blade.php index 38bdbc9b1..8795b9616 100755 --- a/packages/Webkul/Shop/src/Resources/views/customers/session/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/customers/session/index.blade.php @@ -5,7 +5,6 @@ @endsection @section('content-wrapper') -
+
+ + {!! Captcha::render() !!} + +
+ + {!! view_render_event('bagisto.shop.customers.login_form_controls.after') !!} +
+ {!! view_render_event('bagisto.shop.customers.login.after') !!} - @stop +@push('scripts') + +{!! Captcha::renderJS() !!} + +@endpush \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php index 9242d3077..e992da641 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php @@ -91,6 +91,8 @@ + {!! Captcha::render() !!} + {!! view_render_event('bagisto.shop.customers.login_form_controls.after') !!} @@ -103,3 +105,9 @@ {!! view_render_event('bagisto.shop.customers.login.after') !!} @endsection + +@push('scripts') + +{!! Captcha::renderJS() !!} + +@endpush \ No newline at end of file From 921a9ad7062844b4ee63a7da4ee4f0f770009409 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 25 Jun 2021 18:19:31 +0530 Subject: [PATCH 03/15] Dynamic Configuration Completed! Translation Completed! --- packages/Webkul/Customer/src/Captcha.php | 42 +++++++++++++++++-- .../Webkul/Customer/src/Config/system.php | 31 ++++++++++++++ .../src/Providers/CustomerServiceProvider.php | 15 +++++++ .../Customer/src/Resources/lang/ar/app.php | 24 +++++++++-- .../Customer/src/Resources/lang/de/app.php | 23 ++++++++-- .../Customer/src/Resources/lang/en/app.php | 22 ++++++++-- .../Customer/src/Resources/lang/es/app.php | 20 +++++++-- .../Customer/src/Resources/lang/it/app.php | 22 ++++++++-- .../Customer/src/Resources/lang/pt_BR/app.php | 24 +++++++++-- 9 files changed, 198 insertions(+), 25 deletions(-) create mode 100644 packages/Webkul/Customer/src/Config/system.php diff --git a/packages/Webkul/Customer/src/Captcha.php b/packages/Webkul/Customer/src/Captcha.php index f382366b7..13af80402 100644 --- a/packages/Webkul/Customer/src/Captcha.php +++ b/packages/Webkul/Customer/src/Captcha.php @@ -27,9 +27,39 @@ class Captcha implements CaptchaContract */ public function __construct() { - $this->siteKey = '6LcUYlYbAAAAALyF7D5IrwZgufgXBwBrjXlcndAt'; + $this->siteKey = $this->getSiteKey(); - $this->secretKey = '6LcUYlYbAAAAAKi3vUJ62a9QEk4JvPfbLoizTajz'; + $this->secretKey = $this->getSecretKey(); + } + + /** + * Check whether captcha is active or not. + * + * @return bool + */ + public function isActive(): bool + { + return (bool) core()->getConfigData('customer.captcha.credentials.status'); + } + + /** + * Get site key from the core config. + * + * @return null|string + */ + public function getSiteKey(): ?string + { + return core()->getConfigData('customer.captcha.credentials.site_key'); + } + + /** + * Get secret key from the core config. + * + * @return null|string + */ + public function getSecretKey(): ?string + { + return core()->getConfigData('customer.captcha.credentials.secret_key'); } /** @@ -59,7 +89,9 @@ class Captcha implements CaptchaContract */ public function renderJS(): string { - return ''; + return $this->isActive() + ? '' + : ''; } /** @@ -71,7 +103,9 @@ class Captcha implements CaptchaContract { $htmlAttributes = $this->buildHTMLAttributes($this->getAttributes()); - return "
"; + return $this->isActive() + ? "
" + : ''; } /** diff --git a/packages/Webkul/Customer/src/Config/system.php b/packages/Webkul/Customer/src/Config/system.php new file mode 100644 index 000000000..b656be83e --- /dev/null +++ b/packages/Webkul/Customer/src/Config/system.php @@ -0,0 +1,31 @@ + 'customer.captcha', + 'name' => 'customer::app.admin.system.captcha.title', + 'sort' => 1, + ], [ + 'key' => 'customer.captcha.credentials', + 'name' => 'customer::app.admin.system.captcha.credentials', + 'sort' => 1, + 'fields' => [ + [ + 'name' => 'site_key', + 'title' => 'customer::app.admin.system.captcha.site-key', + 'type' => 'text', + 'channel_based' => true, + ], [ + 'name' => 'secret_key', + 'title' => 'customer::app.admin.system.captcha.secret-key', + 'type' => 'text', + 'channel_based' => true, + ], [ + 'name' => 'status', + 'title' => 'customer::app.admin.system.captcha.status', + 'type' => 'boolean', + 'channel_based' => true, + ] + ], + ], +]; diff --git a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php index 8bea3c8cf..8b7f1fd02 100755 --- a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php +++ b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php @@ -36,6 +36,8 @@ class CustomerServiceProvider extends ServiceProvider */ public function register() { + $this->registerConfig(); + $this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories'); $this->app->singleton('captcha', function ($app) { @@ -54,4 +56,17 @@ class CustomerServiceProvider extends ServiceProvider { $this->app->make(EloquentFactory::class)->load($path); } + + /** + * Register package config. + * + * @return void + */ + protected function registerConfig() + { + $this->mergeConfigFrom( + dirname(__DIR__) . '/Config/system.php', + 'core' + ); + } } diff --git a/packages/Webkul/Customer/src/Resources/lang/ar/app.php b/packages/Webkul/Customer/src/Resources/lang/ar/app.php index 8911aef0d..680223f85 100644 --- a/packages/Webkul/Customer/src/Resources/lang/ar/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/ar/app.php @@ -11,7 +11,25 @@ return [ 'select-options' => 'تحتاج إلى تحديد خيارات قبل إضافة إلى قائمة الأمنيات', 'remove-all-success' => 'تمت إزالة جميع العناصر من قائمة الأمنيات الخاصة بك', ], + 'reviews' => [ - 'empty' => '.لم تقم بمراجعة أي منتج حتى الآن' - ] -]; \ No newline at end of file + 'empty' => '.لم تقم بمراجعة أي منتج حتى الآن', + ], + + 'forget_password' => [ + 'reset_link_sent' => 'لقد أرسلنا رابط إعادة تعيين كلمة المرور بالبريد الإلكتروني.', + 'email_not_exist' => "لا يمكننا العثور على مستخدم بعنوان البريد الإلكتروني هذا", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'كلمة التحقق', + 'credentials' => 'أوراق اعتماد', + 'site-key' => 'مفتاح الموقع', + 'secret-key' => 'المفتاح السري', + 'status' => 'حالة', + ], + ], + ], +]; diff --git a/packages/Webkul/Customer/src/Resources/lang/de/app.php b/packages/Webkul/Customer/src/Resources/lang/de/app.php index 9c197a591..ea88c025f 100755 --- a/packages/Webkul/Customer/src/Resources/lang/de/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/de/app.php @@ -11,10 +11,25 @@ return [ 'select-options' => 'Vor dem Hinzufügen zur Wunschliste müssen Optionen ausgewählt werden', 'remove-all-success' => 'Alle Elemente von Ihrer Wunschliste wurden entfernt', ], + 'reviews' => [ - 'empty' => 'Sie haben noch kein Produkt bewertet' + 'empty' => 'Sie haben noch kein Produkt bewertet', ], + 'forget_password' => [ - 'reset_link_sent' => 'Wir haben Ihren Link zum Zurücksetzen des Passworts per E-Mail gesendet.' - ] -]; \ No newline at end of file + 'reset_link_sent' => 'Wir haben Ihren Link zum Zurücksetzen des Passworts per E-Mail gesendet.', + 'email_not_exist' => "Wir können keinen Benutzer mit dieser E-Mail-Adresse finden", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Referenzen', + 'site-key' => 'Site-Schlüssel', + 'secret-key' => 'Geheimer Schlüssel', + 'status' => 'Status', + ], + ], + ], +]; diff --git a/packages/Webkul/Customer/src/Resources/lang/en/app.php b/packages/Webkul/Customer/src/Resources/lang/en/app.php index a229b6fbc..d55b6ebb8 100755 --- a/packages/Webkul/Customer/src/Resources/lang/en/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/en/app.php @@ -11,11 +11,25 @@ return [ 'select-options' => 'Need To Select Options Before Adding To Wishlist', 'remove-all-success' => 'All The Items From Your Wishlist Have Been Removed', ], + 'reviews' => [ - 'empty' => 'You have not reviewed any of product yet' + 'empty' => 'You have not reviewed any of product yet', ], + 'forget_password' => [ 'reset_link_sent' => 'We have e-mailed your reset password link.', - 'email_not_exist' => "We can't find a user with that e-mail address" - ] -]; \ No newline at end of file + 'email_not_exist' => "We can't find a user with that e-mail address", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Credentials', + 'site-key' => 'Site Key', + 'secret-key' => 'Secret Key', + 'status' => 'Status', + ], + ], + ], +]; diff --git a/packages/Webkul/Customer/src/Resources/lang/es/app.php b/packages/Webkul/Customer/src/Resources/lang/es/app.php index 7ef9cac47..a0b51e666 100755 --- a/packages/Webkul/Customer/src/Resources/lang/es/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/es/app.php @@ -11,11 +11,25 @@ return [ 'select-options' => 'Necesita seleccionar opciones antes de agregar a la lista de deseos', 'remove-all-success' => 'Se han eliminado todos los elementos de su lista de deseos', ], + 'reviews' => [ - 'empty' => 'Aún no has calificado ningún producto' + 'empty' => 'Aún no has calificado ningún producto', ], + 'forget_password' => [ 'reset_link_sent' => 'Hemos enviado un correo electrónico con el enlace para restablecer la contraseña.', - 'email_not_exist' => "No podemos encontrar un usuario con esa dirección de correo electrónico" - ] + 'email_not_exist' => "No podemos encontrar un usuario con esa dirección de correo electrónico", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Cartas credenciales', + 'site-key' => 'Clave del sitio', + 'secret-key' => 'Llave secreta', + 'status' => 'Estado', + ], + ], + ], ]; diff --git a/packages/Webkul/Customer/src/Resources/lang/it/app.php b/packages/Webkul/Customer/src/Resources/lang/it/app.php index de13bb197..cb8e7c951 100644 --- a/packages/Webkul/Customer/src/Resources/lang/it/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/it/app.php @@ -11,11 +11,25 @@ return [ 'select-options' => 'Seleziona una opzione del prodotto prima di aggiungerlo ai Preferiti', 'remove-all-success' => 'Tutti i Prodotti presenti nei preferiti sono stati rimossi', ], + 'reviews' => [ 'empty' => 'Non hai ancora recensito i nostri prodotti' ], - 'forget_password' => [ - 'reset_link_sent' => 'Ti abbiamo inviato una email per generare una nuova password.' - ] -]; \ No newline at end of file + 'forget_password' => [ + 'reset_link_sent' => 'Abbiamo inviato un\'e-mail con il link per reimpostare la password.', + 'email_not_exist' => "Non riusciamo a trovare un utente con quell'indirizzo e-mail", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Credenziali', + 'site-key' => 'Chiave del sito', + 'secret-key' => 'Chiave segreta', + 'status' => 'Stato', + ], + ], + ], +]; diff --git a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php index 4f2263f77..cfe908918 100755 --- a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php @@ -11,7 +11,25 @@ return [ 'select-options' => 'Precisa selecionar opções antes de adicionar à lista de desejos', 'remove-all-success' => 'Todos os itens da sua lista de desejos foram removidos', ], + 'reviews' => [ - 'empty' => 'Você não avaliou nenhum produto ainda' - ] -]; \ No newline at end of file + 'empty' => 'Você não avaliou nenhum produto ainda', + ], + + 'forget_password' => [ + 'reset_link_sent' => 'Enviamos por e-mail o link de redefinição de senha.', + 'email_not_exist' => "Não conseguimos encontrar um usuário com esse endereço de e-mail", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Credenciais', + 'site-key' => 'Chave do Site', + 'secret-key' => 'Chave secreta', + 'status' => 'Status', + ], + ], + ], +]; From 2d26834798f2430c064263307c1877f2b4990010 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 25 Jun 2021 19:24:55 +0530 Subject: [PATCH 04/15] Added To Registration Page Also --- .../Controllers/RegistrationController.php | 36 ++++++++-------- .../Http/Controllers/SessionController.php | 16 +++---- .../Http/Requests/CustomerLoginRequest.php | 41 ++++++++++++++++++ .../Requests/CustomerRegistrationRequest.php | 43 +++++++++++++++++++ .../views/customers/signup/index.blade.php | 14 ++++++ .../shop/customers/signup/index.blade.php | 10 +++++ 6 files changed, 132 insertions(+), 28 deletions(-) create mode 100644 packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php create mode 100644 packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php diff --git a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php index a3b14395f..1cdd3cb8e 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/RegistrationController.php @@ -2,54 +2,54 @@ namespace Webkul\Customer\Http\Controllers; -use Illuminate\Support\Str; +use Cookie; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Mail; +use Illuminate\Support\Str; +use Webkul\Core\Repositories\SubscribersListRepository; +use Webkul\Customer\Http\Requests\CustomerRegistrationRequest; use Webkul\Customer\Mail\RegistrationEmail; use Webkul\Customer\Mail\VerificationEmail; -use Webkul\Shop\Mail\SubscriptionEmail; -use Webkul\Customer\Repositories\CustomerRepository; use Webkul\Customer\Repositories\CustomerGroupRepository; -use Webkul\Core\Repositories\SubscribersListRepository; -use Cookie; +use Webkul\Customer\Repositories\CustomerRepository; +use Webkul\Shop\Mail\SubscriptionEmail; class RegistrationController extends Controller { /** - * Contains route related configuration + * Contains route related configuration. * * @var array */ protected $_config; /** - * CustomerRepository object + * Customer repository instance. * * @var \Webkul\Customer\Repositories\CustomerRepository */ protected $customerRepository; /** - * CustomerGroupRepository object + * Customer group repository instance. * * @var \Webkul\Customer\Repositories\CustomerGroupRepository */ protected $customerGroupRepository; /** - * SubscribersListRepository + * Subscribers list repository instance. * * @var \Webkul\Core\Repositories\SubscribersListRepository */ protected $subscriptionRepository; /** - * Create a new Repository instance. + * Create a new controller instance. * * @param \Webkul\Customer\Repositories\CustomerRepository $customer * @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository * @param \Webkul\Core\Repositories\SubscribersListRepository $subscriptionRepository - * * @return void */ public function __construct( @@ -80,16 +80,12 @@ class RegistrationController extends Controller /** * Method to store user's sign up form data to DB. * + * @param \Webkul\Customer\Http\Requests\CustomerRegistrationRequest $request * @return \Illuminate\Http\Response */ - public function create() + public function create(CustomerRegistrationRequest $request) { - $this->validate(request(), [ - 'first_name' => 'string|required', - 'last_name' => 'string|required', - 'email' => 'email|required|unique:customers,email', - 'password' => 'confirmed|min:6|required', - ]); + $request->validated(); $data = array_merge(request()->input(), [ 'password' => bcrypt(request()->input('password')), @@ -169,7 +165,7 @@ class RegistrationController extends Controller } /** - * Method to verify account + * Method to verify account. * * @param string $token * @return \Illuminate\Http\Response @@ -190,6 +186,8 @@ class RegistrationController extends Controller } /** + * Resend verification email. + * * @param string $email * @return \Illuminate\Http\Response */ diff --git a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php index bdacd3cdf..60fbf9b78 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/SessionController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/SessionController.php @@ -4,6 +4,7 @@ namespace Webkul\Customer\Http\Controllers; use Cookie; use Illuminate\Support\Facades\Event; +use Webkul\Customer\Http\Requests\CustomerLoginRequest; class SessionController extends Controller { @@ -41,17 +42,14 @@ class SessionController extends Controller /** * Show the form for creating a new resource. * + * @param \Webkul\Customer\Http\Requests\CustomerLoginRequest $request * @return \Illuminate\Http\Response */ - public function create() + public function create(CustomerLoginRequest $request) { - $this->validate(request(), [ - 'email' => 'required|email', - 'password' => 'required', - 'g-recaptcha-response' => 'required|captcha', - ]); + $request->validated(); - if (! auth()->guard('customer')->attempt(request(['email', 'password']))) { + if (! auth()->guard('customer')->attempt($request->only(['email', 'password']))) { session()->flash('error', trans('shop::app.customer.login-form.invalid-creds')); return redirect()->back(); @@ -70,7 +68,7 @@ class SessionController extends Controller Cookie::queue(Cookie::make('enable-resend', 'true', 1)); - Cookie::queue(Cookie::make('email-for-resend', request('email'), 1)); + Cookie::queue(Cookie::make('email-for-resend', $request->get('email'), 1)); auth()->guard('customer')->logout(); @@ -80,7 +78,7 @@ class SessionController extends Controller /** * Event passed to prepare cart after login. */ - Event::dispatch('customer.after.login', request('email')); + Event::dispatch('customer.after.login', $request->get('email')); return redirect()->intended(route($this->_config['redirect'])); } diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php new file mode 100644 index 000000000..9a79295c1 --- /dev/null +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php @@ -0,0 +1,41 @@ + 'required|email', + 'password' => 'required', + ]; + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return Captcha::isActive() + ? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha']) + : $this->rules; + } +} diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php new file mode 100644 index 000000000..4a7369901 --- /dev/null +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php @@ -0,0 +1,43 @@ + 'string|required', + 'last_name' => 'string|required', + 'email' => 'email|required|unique:customers,email', + 'password' => 'confirmed|min:6|required', + ]; + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return Captcha::isActive() + ? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha']) + : $this->rules; + } +} diff --git a/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php b/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php index 72f74bd86..b151cd885 100755 --- a/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/customers/signup/index.blade.php @@ -59,6 +59,8 @@ @{{ errors.first('password_confirmation') }} + {!! view_render_event('bagisto.shop.customers.signup_form_controls.password_confirmation.after') !!} + {{-- + {!! view_render_event('bagisto.shop.customers.signup_form_controls.password_confirmation.after') !!} + + {!! Captcha::render() !!} + @if (core()->getConfigData('customer.settings.newsletter.subscription'))
@@ -158,3 +162,9 @@
@endsection + +@push('scripts') + +{!! Captcha::renderJS() !!} + +@endpush \ No newline at end of file From 29e4d76d3ba80dee2cfc35ea1b98cf95b99235b7 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 25 Jun 2021 20:15:39 +0530 Subject: [PATCH 05/15] Hardcoded Text Removed --- packages/Webkul/Customer/src/Captcha.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/Customer/src/Captcha.php b/packages/Webkul/Customer/src/Captcha.php index 13af80402..1d9fca522 100644 --- a/packages/Webkul/Customer/src/Captcha.php +++ b/packages/Webkul/Customer/src/Captcha.php @@ -119,7 +119,7 @@ class Captcha implements CaptchaContract $response = $client->post(static::SITE_VERIFY_ENDPOINT, [ 'query' => [ - 'secret' => '6LcUYlYbAAAAAKi3vUJ62a9QEk4JvPfbLoizTajz', + 'secret' => $this->secretKey, 'response' => $response ] ]); From 961b2fb023b329a410ffff94bc59f27982cfa1c3 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 28 Jun 2021 10:29:27 +0530 Subject: [PATCH 06/15] Dutch Translations Added --- .../Customer/src/Resources/lang/nl/app.php | 35 +++++++++++++++++++ .../Customer/src/resources/manifest.php | 6 ---- 2 files changed, 35 insertions(+), 6 deletions(-) create mode 100755 packages/Webkul/Customer/src/Resources/lang/nl/app.php delete mode 100644 packages/Webkul/Customer/src/resources/manifest.php diff --git a/packages/Webkul/Customer/src/Resources/lang/nl/app.php b/packages/Webkul/Customer/src/Resources/lang/nl/app.php new file mode 100755 index 000000000..f1af80033 --- /dev/null +++ b/packages/Webkul/Customer/src/Resources/lang/nl/app.php @@ -0,0 +1,35 @@ + [ + 'success' => 'Artikel succesvol toegevoegd aan verlanglijst', + 'failure' => 'Artikel kan niet worden toegevoegd aan verlanglijst', + 'already' => 'Artikel al aanwezig in uw verlanglijst', + 'removed' => 'Artikel succesvol verwijderd van verlanglijst', + 'remove-fail' => 'Artikel kan niet van verlanglijst worden verwijderd', + 'empty' => 'U heeft geen items op uw verlanglijst', + 'select-options' => 'Moet opties selecteren voordat u aan verlanglijst toevoegt', + 'remove-all-success' => 'Alle items van je verlanglijst zijn verwijderd', + ], + + 'reviews' => [ + 'empty' => 'U heeft nog geen product beoordeeld', + ], + + 'forget_password' => [ + 'reset_link_sent' => 'We hebben de link voor het opnieuw instellen van uw wachtwoord per e-mail verzonden.', + 'email_not_exist' => "We kunnen geen gebruiker met dat e-mailadres vinden", + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Inloggegevens', + 'site-key' => 'Sitesleutel', + 'secret-key' => 'Geheime sleutel', + 'status' => 'Toestand', + ], + ], + ], +]; diff --git a/packages/Webkul/Customer/src/resources/manifest.php b/packages/Webkul/Customer/src/resources/manifest.php deleted file mode 100644 index c732276af..000000000 --- a/packages/Webkul/Customer/src/resources/manifest.php +++ /dev/null @@ -1,6 +0,0 @@ - 'Webkul Bagisto Customer', - 'version' => '0.0.1' - ]; From 919bb8171391cce60c68337ace4fa131bf69a699 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 28 Jun 2021 10:35:23 +0530 Subject: [PATCH 07/15] French Locale Added --- .../Customer/src/Resources/lang/fr/app.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 packages/Webkul/Customer/src/Resources/lang/fr/app.php diff --git a/packages/Webkul/Customer/src/Resources/lang/fr/app.php b/packages/Webkul/Customer/src/Resources/lang/fr/app.php new file mode 100755 index 000000000..c176be7df --- /dev/null +++ b/packages/Webkul/Customer/src/Resources/lang/fr/app.php @@ -0,0 +1,35 @@ + [ + 'success' => 'Article ajouté avec succès à la liste de souhaits', + 'failure' => 'L\'article ne peut pas être ajouté à la liste de souhaits', + 'already' => 'Article déjà présent dans votre liste de souhaits', + 'removed' => 'Article supprimé avec succès de la liste de souhaits', + 'remove-fail' => 'L\'article ne peut pas être supprimé de la liste de souhaits', + 'empty' => 'Vous n\'avez aucun article dans votre liste de souhaits', + 'select-options' => 'Besoin de sélectionner des options avant d\'ajouter à la liste de souhaits', + 'remove-all-success' => 'Tous les articles de votre liste de souhaits ont été supprimés', + ], + + 'reviews' => [ + 'empty' => 'Vous n\'avez pas encore évalué de produit', + ], + + 'forget_password' => [ + 'reset_link_sent' => 'Nous avons envoyé par e-mail votre lien de réinitialisation de mot de passe.', + 'email_not_exist' => 'Nous ne pouvons pas trouver un utilisateur avec cette adresse e-mail', + ], + + 'admin' => [ + 'system' => [ + 'captcha' => [ + 'title' => 'Captcha', + 'credentials' => 'Crédits', + 'site-key' => 'Clé du site', + 'secret-key' => 'Clef secrète', + 'status' => 'Statut', + ], + ], + ], +]; From 4d763250b3fdd29b11d400f494da59026ba10404 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 28 Jun 2021 10:44:03 +0530 Subject: [PATCH 08/15] Customer Request Added To API Also --- .../Http/Controllers/Shop/CustomerController.php | 13 ++++--------- .../Http/Controllers/Shop/SessionController.php | 14 ++++++-------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/Webkul/API/Http/Controllers/Shop/CustomerController.php b/packages/Webkul/API/Http/Controllers/Shop/CustomerController.php index 7fb6b796b..fce2b50b8 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/CustomerController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/CustomerController.php @@ -2,11 +2,11 @@ namespace Webkul\API\Http\Controllers\Shop; -use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Event; -use Webkul\Customer\Repositories\CustomerRepository; +use Webkul\Customer\Http\Requests\CustomerRegistrationRequest; use Webkul\Customer\Repositories\CustomerGroupRepository; +use Webkul\Customer\Repositories\CustomerRepository; class CustomerController extends Controller { @@ -70,14 +70,9 @@ class CustomerController extends Controller * * @return \Illuminate\Http\Response */ - public function create(Request $request) + public function create(CustomerRegistrationRequest $request) { - $this->validate($request, [ - 'first_name' => 'required', - 'last_name' => 'required', - 'email' => 'email|required|unique:customers,email', - 'password' => 'confirmed|min:6|required', - ]); + $request->validated(); $data = [ 'first_name' => $request->get('first_name'), diff --git a/packages/Webkul/API/Http/Controllers/Shop/SessionController.php b/packages/Webkul/API/Http/Controllers/Shop/SessionController.php index b84f3694d..5b6b4a45f 100644 --- a/packages/Webkul/API/Http/Controllers/Shop/SessionController.php +++ b/packages/Webkul/API/Http/Controllers/Shop/SessionController.php @@ -3,8 +3,9 @@ namespace Webkul\API\Http\Controllers\Shop; use Illuminate\Support\Facades\Event; -use Webkul\Customer\Repositories\CustomerRepository; use Webkul\API\Http\Resources\Customer\Customer as CustomerResource; +use Webkul\Customer\Http\Requests\CustomerLoginRequest; +use Webkul\Customer\Repositories\CustomerRepository; class SessionController extends Controller { @@ -45,22 +46,19 @@ class SessionController extends Controller * * @return \Illuminate\Http\Response */ - public function create() + public function create(CustomerLoginRequest $request) { - request()->validate([ - 'email' => 'required|email', - 'password' => 'required', - ]); + $request->validated(); $jwtToken = null; - if (! $jwtToken = auth()->guard($this->guard)->attempt(request()->only('email', 'password'))) { + if (! $jwtToken = auth()->guard($this->guard)->attempt($request->only(['email', 'password']))) { return response()->json([ 'error' => 'Invalid Email or Password', ], 401); } - Event::dispatch('customer.after.login', request('email')); + Event::dispatch('customer.after.login', $request->get('email')); $customer = auth($this->guard)->user(); From f5c50726a730b020dbd2a03d3382d99b7ae71d23 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Mon, 28 Jun 2021 11:07:39 +0530 Subject: [PATCH 09/15] Endpoint Get Through Method --- packages/Webkul/Customer/src/Captcha.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/Webkul/Customer/src/Captcha.php b/packages/Webkul/Customer/src/Captcha.php index 1d9fca522..a0aa84685 100644 --- a/packages/Webkul/Customer/src/Captcha.php +++ b/packages/Webkul/Customer/src/Captcha.php @@ -117,7 +117,7 @@ class Captcha implements CaptchaContract { $client = new \GuzzleHttp\Client(); - $response = $client->post(static::SITE_VERIFY_ENDPOINT, [ + $response = $client->post($this->getSiteVerifyEndpoint(), [ 'query' => [ 'secret' => $this->secretKey, 'response' => $response From 320b00ac4f66171465471ab2185af6ef8251412f Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 2 Jul 2021 09:59:34 +0530 Subject: [PATCH 10/15] Validation Message Added --- packages/Webkul/Customer/src/Captcha.php | 32 ++++++++++++++++--- .../Http/Requests/CustomerLoginRequest.php | 12 +++++++ .../Requests/CustomerRegistrationRequest.php | 12 +++++++ .../src/Providers/CustomerServiceProvider.php | 4 ++- .../Resources/views/captcha/scripts.blade.php | 1 + .../Resources/views/captcha/view.blade.php | 7 ++++ .../shop/customers/session/index.blade.php | 6 +++- 7 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 packages/Webkul/Customer/src/Resources/views/captcha/scripts.blade.php create mode 100644 packages/Webkul/Customer/src/Resources/views/captcha/view.blade.php diff --git a/packages/Webkul/Customer/src/Captcha.php b/packages/Webkul/Customer/src/Captcha.php index a0aa84685..350c21b1c 100644 --- a/packages/Webkul/Customer/src/Captcha.php +++ b/packages/Webkul/Customer/src/Captcha.php @@ -90,7 +90,7 @@ class Captcha implements CaptchaContract public function renderJS(): string { return $this->isActive() - ? '' + ? $this->getCaptchaJSView() : ''; } @@ -101,10 +101,8 @@ class Captcha implements CaptchaContract */ public function render(): string { - $htmlAttributes = $this->buildHTMLAttributes($this->getAttributes()); - return $this->isActive() - ? "
" + ? $this->getCaptchaView() : ''; } @@ -158,4 +156,30 @@ class Captcha implements CaptchaContract ? implode(' ', $htmlAttributes) : ''; } + + /** + * Get captcha view. + * + * @return string + */ + protected function getCaptchaView() + { + $htmlAttributes = $this->buildHTMLAttributes($this->getAttributes()); + + return view('customer::captcha.view', [ + 'htmlAttributes' => $htmlAttributes + ])->render(); + } + + /** + * Get captcha script view. + * + * @return string + */ + protected function getCaptchaJSView() + { + return view('customer::captcha.scripts', [ + 'clientEndPoint' => $this->getClientEndpoint() + ])->render(); + } } diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php index 9a79295c1..9a48cc574 100644 --- a/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php @@ -38,4 +38,16 @@ class CustomerLoginRequest extends FormRequest ? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha']) : $this->rules; } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'g-recaptcha-response.required' => 'Please select CAPTCHA' + ]; + } } diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php index 4a7369901..35074c9c7 100644 --- a/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php @@ -40,4 +40,16 @@ class CustomerRegistrationRequest extends FormRequest ? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha']) : $this->rules; } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'g-recaptcha-response.required' => 'Please select CAPTCHA' + ]; + } } diff --git a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php index 8b7f1fd02..a482df188 100755 --- a/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php +++ b/packages/Webkul/Customer/src/Providers/CustomerServiceProvider.php @@ -19,9 +19,11 @@ class CustomerServiceProvider extends ServiceProvider { $router->aliasMiddleware('customer', RedirectIfNotCustomer::class); + $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'customer'); - $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); + $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'customer'); $this->app['validator']->extend('captcha', function ($attribute, $value, $parameters) { return $this->app['captcha']->validateResponse($value); diff --git a/packages/Webkul/Customer/src/Resources/views/captcha/scripts.blade.php b/packages/Webkul/Customer/src/Resources/views/captcha/scripts.blade.php new file mode 100644 index 000000000..e8f54e6ff --- /dev/null +++ b/packages/Webkul/Customer/src/Resources/views/captcha/scripts.blade.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/Webkul/Customer/src/Resources/views/captcha/view.blade.php b/packages/Webkul/Customer/src/Resources/views/captcha/view.blade.php new file mode 100644 index 000000000..be3d72df2 --- /dev/null +++ b/packages/Webkul/Customer/src/Resources/views/captcha/view.blade.php @@ -0,0 +1,7 @@ +
+ +@if ($errors->has('g-recaptcha-response')) + + {{ $errors->first('g-recaptcha-response') }} + +@endif \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php index e992da641..4c15d8ee7 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/session/index.blade.php @@ -91,7 +91,11 @@ - {!! Captcha::render() !!} +
+ + {!! Captcha::render() !!} + +
{!! view_render_event('bagisto.shop.customers.login_form_controls.after') !!} From 9b20f007297ab86f03d851c11d021c6084eac7fc Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 2 Jul 2021 10:11:21 +0530 Subject: [PATCH 11/15] Translations Added~ --- .../Customer/src/Http/Requests/CustomerLoginRequest.php | 2 +- .../src/Http/Requests/CustomerRegistrationRequest.php | 2 +- packages/Webkul/Customer/src/Resources/lang/ar/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/de/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/en/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/es/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/fr/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/it/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/nl/app.php | 4 ++++ packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php | 4 ++++ 10 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php index 9a48cc574..ee74a874f 100644 --- a/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerLoginRequest.php @@ -47,7 +47,7 @@ class CustomerLoginRequest extends FormRequest public function messages() { return [ - 'g-recaptcha-response.required' => 'Please select CAPTCHA' + 'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required') ]; } } diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php index 35074c9c7..9e96d17e3 100644 --- a/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerRegistrationRequest.php @@ -49,7 +49,7 @@ class CustomerRegistrationRequest extends FormRequest public function messages() { return [ - 'g-recaptcha-response.required' => 'Please select CAPTCHA' + 'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required') ]; } } diff --git a/packages/Webkul/Customer/src/Resources/lang/ar/app.php b/packages/Webkul/Customer/src/Resources/lang/ar/app.php index 680223f85..440e817df 100644 --- a/packages/Webkul/Customer/src/Resources/lang/ar/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/ar/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'مفتاح الموقع', 'secret-key' => 'المفتاح السري', 'status' => 'حالة', + + 'validations' => [ + 'required' => 'الرجاء اختيار CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/de/app.php b/packages/Webkul/Customer/src/Resources/lang/de/app.php index ea88c025f..7d2991d7c 100755 --- a/packages/Webkul/Customer/src/Resources/lang/de/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/de/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Site-Schlüssel', 'secret-key' => 'Geheimer Schlüssel', 'status' => 'Status', + + 'validations' => [ + 'required' => 'Bitte wählen Sie CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/en/app.php b/packages/Webkul/Customer/src/Resources/lang/en/app.php index d55b6ebb8..2c8cd3254 100755 --- a/packages/Webkul/Customer/src/Resources/lang/en/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/en/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Site Key', 'secret-key' => 'Secret Key', 'status' => 'Status', + + 'validations' => [ + 'required' => 'Please select CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/es/app.php b/packages/Webkul/Customer/src/Resources/lang/es/app.php index a0b51e666..87dfc954b 100755 --- a/packages/Webkul/Customer/src/Resources/lang/es/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/es/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Clave del sitio', 'secret-key' => 'Llave secreta', 'status' => 'Estado', + + 'validations' => [ + 'required' => 'Seleccione CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/fr/app.php b/packages/Webkul/Customer/src/Resources/lang/fr/app.php index c176be7df..4ecbbabaf 100755 --- a/packages/Webkul/Customer/src/Resources/lang/fr/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/fr/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Clé du site', 'secret-key' => 'Clef secrète', 'status' => 'Statut', + + 'validations' => [ + 'required' => 'Veuillez sélectionner CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/it/app.php b/packages/Webkul/Customer/src/Resources/lang/it/app.php index cb8e7c951..70505aab0 100644 --- a/packages/Webkul/Customer/src/Resources/lang/it/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/it/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Chiave del sito', 'secret-key' => 'Chiave segreta', 'status' => 'Stato', + + 'validations' => [ + 'required' => 'Seleziona CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/nl/app.php b/packages/Webkul/Customer/src/Resources/lang/nl/app.php index f1af80033..26bacbc69 100755 --- a/packages/Webkul/Customer/src/Resources/lang/nl/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/nl/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Sitesleutel', 'secret-key' => 'Geheime sleutel', 'status' => 'Toestand', + + 'validations' => [ + 'required' => 'Selecteer CAPTCHA' + ] ], ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php index cfe908918..e06a47abf 100755 --- a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php @@ -29,6 +29,10 @@ return [ 'site-key' => 'Chave do Site', 'secret-key' => 'Chave secreta', 'status' => 'Status', + + 'validations' => [ + 'required' => 'Selecione CAPTCHA' + ] ], ], ], From 63f4d88deef3614b0aae99809ce76b20de6c67cd Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Fri, 2 Jul 2021 10:44:15 +0530 Subject: [PATCH 12/15] Captcha Added In Forgot Password Feature --- .../Controllers/ForgotPasswordController.php | 22 ++++---- .../CustomerForgotPasswordRequest.php | 53 +++++++++++++++++++ .../Customer/src/Resources/lang/ar/app.php | 3 +- .../Customer/src/Resources/lang/de/app.php | 3 +- .../Customer/src/Resources/lang/en/app.php | 3 +- .../Customer/src/Resources/lang/es/app.php | 3 +- .../Customer/src/Resources/lang/fr/app.php | 3 +- .../Customer/src/Resources/lang/it/app.php | 3 +- .../Customer/src/Resources/lang/nl/app.php | 3 +- .../Customer/src/Resources/lang/pt_BR/app.php | 3 +- .../signup/forgot-password.blade.php | 12 +++++ 11 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 packages/Webkul/Customer/src/Http/Requests/CustomerForgotPasswordRequest.php diff --git a/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php b/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php index eef822637..df66d8ce3 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/ForgotPasswordController.php @@ -4,13 +4,14 @@ namespace Webkul\Customer\Http\Controllers; use Illuminate\Foundation\Auth\SendsPasswordResetEmails; use Illuminate\Support\Facades\Password; +use Webkul\Customer\Http\Requests\CustomerForgotPasswordRequest; class ForgotPasswordController extends Controller { use SendsPasswordResetEmails; - + /** - * Contains route related configuration + * Contains route related configuration. * * @var array */ @@ -41,16 +42,12 @@ class ForgotPasswordController extends Controller * * @return \Illuminate\Http\Response */ - public function store() + public function store(CustomerForgotPasswordRequest $request) { - try { - $this->validate(request(), [ - 'email' => 'required|email', - ]); + $request->validated(); - $response = $this->broker()->sendResetLink( - request(['email']) - ); + try { + $response = $this->broker()->sendResetLink($request->only(['email'])); if ($response == Password::RESET_LINK_SENT) { session()->flash('success', trans('customer::app.forget_password.reset_link_sent')); @@ -59,7 +56,7 @@ class ForgotPasswordController extends Controller } return back() - ->withInput(request(['email'])) + ->withInput($request->only(['email'])) ->withErrors([ 'email' => trans('customer::app.forget_password.email_not_exist'), ]); @@ -69,6 +66,7 @@ class ForgotPasswordController extends Controller return redirect()->back(); } catch (\Exception $e) { report($e); + session()->flash('error', trans($e->getMessage())); return redirect()->back(); @@ -84,4 +82,4 @@ class ForgotPasswordController extends Controller { return Password::broker('customers'); } -} \ No newline at end of file +} diff --git a/packages/Webkul/Customer/src/Http/Requests/CustomerForgotPasswordRequest.php b/packages/Webkul/Customer/src/Http/Requests/CustomerForgotPasswordRequest.php new file mode 100644 index 000000000..da57091ea --- /dev/null +++ b/packages/Webkul/Customer/src/Http/Requests/CustomerForgotPasswordRequest.php @@ -0,0 +1,53 @@ + 'required|email', + ]; + + /** + * Determine if the user is authorized to make this request. + * + * @return bool + */ + public function authorize() + { + return true; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return Captcha::isActive() + ? array_merge($this->rules, ['g-recaptcha-response' => 'required|captcha']) + : $this->rules; + } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'g-recaptcha-response.required' => __('customer::app.admin.system.captcha.validations.required'), + 'g-recaptcha-response.captcha' => __('customer::app.admin.system.captcha.validations.captcha') + ]; + } +} diff --git a/packages/Webkul/Customer/src/Resources/lang/ar/app.php b/packages/Webkul/Customer/src/Resources/lang/ar/app.php index 440e817df..d083a78a2 100644 --- a/packages/Webkul/Customer/src/Resources/lang/ar/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/ar/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'حالة', 'validations' => [ - 'required' => 'الرجاء اختيار CAPTCHA' + 'required' => 'الرجاء اختيار CAPTCHA', + 'captcha' => 'هناك خطأ ما! حاول مرة اخرى.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/de/app.php b/packages/Webkul/Customer/src/Resources/lang/de/app.php index 7d2991d7c..783124e4d 100755 --- a/packages/Webkul/Customer/src/Resources/lang/de/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/de/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Status', 'validations' => [ - 'required' => 'Bitte wählen Sie CAPTCHA' + 'required' => 'Bitte wählen Sie CAPTCHA', + 'captcha' => 'Etwas ist schief gelaufen! Bitte versuche es erneut.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/en/app.php b/packages/Webkul/Customer/src/Resources/lang/en/app.php index 2c8cd3254..7108bc25c 100755 --- a/packages/Webkul/Customer/src/Resources/lang/en/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/en/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Status', 'validations' => [ - 'required' => 'Please select CAPTCHA' + 'required' => 'Please select CAPTCHA', + 'captcha' => 'Something went wrong! Please try again.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/es/app.php b/packages/Webkul/Customer/src/Resources/lang/es/app.php index 87dfc954b..af560c4c4 100755 --- a/packages/Webkul/Customer/src/Resources/lang/es/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/es/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Estado', 'validations' => [ - 'required' => 'Seleccione CAPTCHA' + 'required' => 'Seleccione CAPTCHA', + 'captcha' => '¡Algo salió mal! Inténtalo de nuevo.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/fr/app.php b/packages/Webkul/Customer/src/Resources/lang/fr/app.php index 4ecbbabaf..5d4760cbf 100755 --- a/packages/Webkul/Customer/src/Resources/lang/fr/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/fr/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Statut', 'validations' => [ - 'required' => 'Veuillez sélectionner CAPTCHA' + 'required' => 'Veuillez sélectionner CAPTCHA', + 'captcha' => 'Quelque chose s\'est mal passé ! Veuillez réessayer.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/it/app.php b/packages/Webkul/Customer/src/Resources/lang/it/app.php index 70505aab0..fa7d02fa6 100644 --- a/packages/Webkul/Customer/src/Resources/lang/it/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/it/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Stato', 'validations' => [ - 'required' => 'Seleziona CAPTCHA' + 'required' => 'Seleziona CAPTCHA', + 'captcha' => 'Qualcosa è andato storto! Per favore riprova.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/nl/app.php b/packages/Webkul/Customer/src/Resources/lang/nl/app.php index 26bacbc69..7d01b9b87 100755 --- a/packages/Webkul/Customer/src/Resources/lang/nl/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/nl/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Toestand', 'validations' => [ - 'required' => 'Selecteer CAPTCHA' + 'required' => 'Selecteer CAPTCHA', + 'captcha' => 'Er is iets fout gegaan! Probeer het opnieuw.', ] ], ], diff --git a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php index e06a47abf..580176677 100755 --- a/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php +++ b/packages/Webkul/Customer/src/Resources/lang/pt_BR/app.php @@ -31,7 +31,8 @@ return [ 'status' => 'Status', 'validations' => [ - 'required' => 'Selecione CAPTCHA' + 'required' => 'Selecione CAPTCHA', + 'captcha' => 'Algo deu errado! Por favor, tente novamente.', ] ], ], diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/signup/forgot-password.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/signup/forgot-password.blade.php index bf4e8c14e..3bb1c2ced 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/customers/signup/forgot-password.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/signup/forgot-password.blade.php @@ -56,6 +56,12 @@ +
+ + {!! Captcha::render() !!} + +
+ {!! view_render_event('bagisto.shop.customers.forget_password_form_controls.after') !!}