Rails and Devise: добавление защиты от спама с acts_as_textcaptcha - PullRequest
0 голосов
/ 27 января 2020

Я пытаюсь добавить защиту от спама в мою регистрационную форму Devise, используя acts_as_textcaptcha , но по какой-то причине она не отображается в моей форме.

На основе Как: использовать Recaptcha с Devise . Блог My Rails 6 доступен здесь для клонирования: https://github.com/anonymous-donor/blog-with-textcaptcha

Спасибо!

Gemfile

gem 'acts_as_textcaptcha', '~> 4.5'

models / user.rb

class User < ApplicationRecord
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

  acts_as_textcaptcha
end

controllers / registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController
  def new
    @user = User.new
    @user.textcaptcha
  end

  private
    # https://kakimotonline.com/2014/03/30/extending-devise-registrations-controller/
    def sign_up_params
      allow = [:email, :display_name, :password, :password_confirmation, :textcaptcha]
      params.require(resource_name).permit(allow)
    end
end

config / rout.rb

Rails.application.routes.draw do
  devise_for :users, controllers: {  registrations: "registrations" }
...
end

app / views / devise / registrations / new. html .erb

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
...
  <%= textcaptcha_fields(f) do %>
    <div class="field">
      <%= f.label :textcaptcha_answer, @user.textcaptcha_question %><br/>
      <%= f.text_field :textcaptcha_answer, :value => '' %>
    </div>
  <% end %>
...
<% end %>

config / textcaptcha.yml

development:
  questions:
    - question: 'Is ice hot or cold?'
      answers: 'cold'
    - question: 'what color is an orange?'
      answers: 'orange'
    - question: 'what is two plus 3?'
      answers: '5,five'
    - question: 'what is 5 times two?'
      answers: '10,ten'
    - question: 'How many colors in the list, green, brown, foot and blue?'
      answers: '3,three'
    - question: 'what is Georges name?'
      answers: 'george'
    - question: '11 minus 1?'
      answers: '10,ten'
    - question: 'is boiling water hot or cold?'
      answers: 'hot'
    - question: 'what color is my blue shirt today?'
      answers: 'blue'
    - question: 'what is 16 plus 4?'
      answers: '20,twenty'


Ответы [ 2 ]

0 голосов
/ 02 февраля 2020

Оказалось, мне пришлось установить config.cache_store = :null_store на config.cache_store = :memory_store в config/environments/development.rb, чтобы он работал в режиме разработки.

0 голосов
/ 29 января 2020

Извините, если я ошибаюсь, скажите, пожалуйста, где это gem 'acts_as_textcaptcha', '~> 4.5'? Я не могу найти это по предоставленной вами ссылке: https://github.com/ambethia/recaptcha. Пожалуйста, следуйте этой жемчужине и отправьте ответ, если есть какие-либо проблемы. Вы можете обратиться к той же странице для настройки с помощью devise: https://github.com/heartcombo/devise/wiki/How-To: - Использовать-Recaptcha-with-Devise . Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...