From 0f18566c88049f4d3069a3fdb15a96596f3d18ef Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 14 Dec 2018 10:06:04 +0500 Subject: [PATCH] Add reCAPTCHA to Users::RegistrationsController#create --- app/controllers/users/registrations_controller.rb | 11 +++++++++++ app/views/users/registrations/new.html.erb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index b3ebd92..1f8d0f9 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -4,6 +4,8 @@ class Users::RegistrationsController < Devise::RegistrationsController skip_after_action :verify_authorized skip_after_action :verify_policy_scoped + prepend_before_action :check_captcha, only: :create + # before_action :configure_sign_up_params, only: [:create] # before_action :configure_account_update_params, only: [:update] @@ -67,4 +69,13 @@ protected def after_update_path_for(_resource) edit_user_registration_path end + + def check_captcha + return if verify_recaptcha + + self.resource = resource_class.new sign_up_params + resource.validate + set_minimum_password_length + render :new + end end diff --git a/app/views/users/registrations/new.html.erb b/app/views/users/registrations/new.html.erb index 855302f..564751c 100644 --- a/app/views/users/registrations/new.html.erb +++ b/app/views/users/registrations/new.html.erb @@ -16,6 +16,10 @@ <%= f.input :password_confirmation, required: true, input_html: { autocomplete: 'new-password' } %> + +
+ <%= recaptcha_tags %> +