matthutchinson / acts_as_textcaptcha

Text-based logic question captcha's for Rails 🚫🤖

Home Page:https://acts-as-textcaptcha.hiddenloop.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you change the captcha timeout? Captchas always fail for me.

ryanbooker opened this issue · comments

Textcaptcha answer was not submitted quickly enough, try another question instead

I always get this. No matter how quickly the form is filled out. Even if it takes just seconds to complete!

See the cache_expiry_minutes option detailed in the README here:

https://github.com/matthutchinson/acts_as_textcaptcha#configuration

The default is 10 min, so it shouldn't be expiring right away.


This gem requires Rails and you should make sure you have a valid cache_store set. Mentioned here:

Finally set a valid cache store (not :null_store) for your environments:

e.g. in each config/environments/*.rb
config.cache_store = :memory_store
You can run rails dev:cache on a modern generated Rails app to enable a memory store cache in the development environment.

It was permitting the :textcaptcha_key and :textcaptcha_answer. Cheers.

I have the same issue, but doesn't :textcaptcha_key and :textcaptcha_answer need to be permitted to avoid:

found unpermitted parameters: :textcaptcha_key, :textcaptcha_answer

Correct, If you see this message in your Rails log for your controller;

found unpermitted parameters: :textcaptcha_key, :textcaptcha_answer

You need to wrap your controller params with a permit. You can see how this is done in the demo application, code here.

This gem isn't concerned with how you choose to write your controller actions. I'll update the README to be clearer on how Rails works with params and what you should do to avoid unpermitted parameters.

Thanks for your reply. Sadly my controller is already set up to permit :textcaptcha_key and :textcaptcha_answer.

It works fine in Production, but in Development where there is just one easy "one plus one" question, I always get this validation error:

Textcaptcha answer was not submitted quickly enough, try another question instead

Our configuration follows, don't suppose you spot anything wrong?

development: &common_settings
  questions:
    - question: "What is one plus one?"
      answers: "2,two"

test:
  <<: *common_settings

staging:
  <<: *common_settings

# In production load questions from textcaptcha.com
production:
  api_key: "ourdomain.com"

This gem requires a Rails cache to be setup. Can you confirm you have that enabled for your development env?

Anything other than a :null_store should work. See the last part of the Installation instructions in the README for details.

Finally set a valid cache store (not :null_store) for your environments:
e.g. in config/environments/development.rb
config.cache_store = :memory_store
You can run rails dev:cache on to enable a memory store cache in the development environment.

You can check what cache store is set in your dev environment by launching rails console locally, and looking at: Rails.cache.class

Thanks. I can see that in Development we disable caching unless some Redis env vars are set:

config/environments/development.rb

# Enable/disable caching. By default caching is disabled, unless REDIS_CACHE_URL or REDIS_TLS_URL or REDIS_URL is set
# Run rails dev:cache to toggle caching.
if ENV['REDIS_CACHE_URL'] || ENV['REDIS_TLS_URL'] || ENV['REDIS_URL']
  # rubocop:disable Rails/Output
  puts 'Redis cache overrides development cache...'
  # rubocop:enable Rails/Output
elsif Rails.root.join('tmp', 'caching-dev.txt').exist?
  config.action_controller.perform_caching = true
  config.action_controller.enable_fragment_cache_logging = true

  config.cache_store = :memory_store
  config.public_file_server.headers = {
    'Cache-Control' => "public, max-age=#{2.days.to_i}"
  }
else
  config.action_controller.perform_caching = false

  config.cache_store = :null_store
end

Not sure if we should be enabling memory cache store in development just for this gem. Or do you think using :memory_store in Development is best practice anyway?