Raj*_*ngh 0 authentication ruby-on-rails recaptcha devise ruby-on-rails-3
我正在使用 Devise 进行身份验证,并想在注册表中添加验证码,我已经阅读过有关验证码的内容,有人可以告诉我如何集成两者吗?
<%= 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
Run Code Online (Sandbox Code Playgroud)在控制器中创建: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
Run Code Online (Sandbox Code Playgroud)更新您的设计路线:
devise_for :users, controllers: { registrations: 'registrations' }
Run Code Online (Sandbox Code Playgroud)快速谷歌显示了 devise wiki 上的一个页面 - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise
你看过那个吗?
| 归档时间: |
|
| 查看次数: |
4561 次 |
| 最近记录: |