如何将recaptcha与设计集成?

时间:2013-09-02 12:00:09

标签: ruby-on-rails ruby-on-rails-3 authentication devise recaptcha

我正在使用Devise进行身份验证,并希望在注册表单中添加验证码,我读过有关recaptcha的内容,有人可以告诉我们如何整合这两种情况吗?

2 个答案:

答案 0 :(得分:2)

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

你看过那个吗?

答案 1 :(得分:2)

  1. obtain a reCAPTCHA API key
  2. Install gem ReCaptcha
  3. <%= recaptcha_tags %>添加到您的视图(views/devise/registrations/new
  4. 创建文件(在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' }