0

我正在使用 Devise 进行身份验证并想在注册表单中添加验证码,我已经阅读了关于 recaptcha 的信息,有人能告诉我如何整合两者吗?

4

2 回答 2

6
  1. 获取 reCAPTCHA API 密钥
  2. 安装 gem ReCaptcha
  3. 添加<%= recaptcha_tags %>到您的视图 ( views/devise/registrations/new)
  4. 创建文件(in config/initializers)recaptcha.rb 并添加以下代码:

    Recaptcha.configure do |config|
      config.public_key  = 'Your public key'
      config.private_key = 'Your private key'
    end
    
  5. 在控制器中创建: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
    
  6. 更新您的设计路线:

    devise_for :users, controllers: { registrations: 'registrations' }
    
于 2016-03-27T17:49:14.147 回答
3

一个快速的谷歌在设计维基上显示了一个页面 - https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise

你看过那个吗?

于 2013-09-02T12:46:06.380 回答