如何将验证码与设备集成?

Raj*_*ngh 0 authentication ruby-on-rails recaptcha devise ruby-on-rails-3

我正在使用 Devise 进行身份验证,并想在注册表中添加验证码,我已经阅读过有关验证码的内容,有人可以告诉我如何集成两者吗?

Gab*_*uin 6

  1. 获取 reCAPTCHA API 密钥
  2. 安装 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
    
    Run Code Online (Sandbox Code Playgroud)
  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
    
    Run Code Online (Sandbox Code Playgroud)
  6. 更新您的设计路线:

    devise_for :users, controllers: { registrations: 'registrations' }
    
    Run Code Online (Sandbox Code Playgroud)


Edw*_*ard 5

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

你看过那个吗?