我正在使用Devise进行身份验证,并希望在注册表单中添加验证码,我读过有关recaptcha的内容,有人可以告诉我们如何整合这两种情况吗?
答案 0 :(得分:2)
快速谷歌在设计维基上显示了一个页面 - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
你看过那个吗?答案 1 :(得分:2)
<%= recaptcha_tags %>
添加到您的视图(views/devise/registrations/new
)创建文件(在config/initializers
中)recaptcha.rb并添加以下代码:
Recaptcha.configure do |config|
config.public_key = 'Your public key'
config.private_key = 'Your private key'
end
在控制器中创建:registrations_controller.rb
并添加此代码
class RegistrationsController < Devise::RegistrationsController
def create
if verify_recaptcha
super
else
build_resource(sign_up_params)
clean_up_passwords(resource)
flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code."
flash.delete :recaptcha_error
render :new
end
end
end
更新您的设计路线:
devise_for :users, controllers: { registrations: 'registrations' }