I found this doc to integrate rails gem recaptcha3 with device registration.
https://github.com/heartcombo/devise/wiki/How-To:-Use-Recaptcha-with-Devise
So ... I add this to register form for device:
<%= recaptcha_v3(action: 'signup') %>
Then add this to controller:
class Users::RegistrationsController < Devise::RegistrationsController
prepend_before_action :check_captcha, only: [:create] # Change this to be any
actions you want to protect.
private
def check_captcha
return if !verify_recaptcha # verify_recaptcha(action: 'signup') for v3
self.resource = resource_class.new sign_up_params
resource.validate # Look for any other validation errors besides reCAPTCHA
set_minimum_password_length
respond_with_navigational(resource) do
flash.discard(:recaptcha_error) # We need to discard flash to avoid showing it
on the next page reload
render :new
end
end
end
Then I check gem documentation and add:
# config/initializers/recaptcha.rb
Recaptcha.configure do |config|
config.site_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
config.secret_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# Uncomment the following line if you are using a proxy server:
# config.proxy = 'http://myproxy.com.au:8080'
# Uncomment the following lines if you are using the Enterprise API:
# config.enterprise = true
# config.enterprise_api_key = 'AIzvFyE3TU-g4K_Kozr9F1smEzZSGBVOfLKyupA'
# config.enterprise_project_id = 'my-project'
end
And what now? recaptcha is invisible because in V3 version it only save some scores. Does it work yet?
I do not find any tutorial or help for recaptcha v3 for device / rails.
Maybe someone do it already ?
我已经在 Rails 6 应用程序中使用了它,并带有设计检查此代码https://github.com/Shaher-11/udzilla/commit/8220527e79eb49fa045fe1d7d1593031524de5a0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.