RedisCaptcha
RedisCaptcha is a captcha engine base on Redis for Rails 3.2. It provides simple captcha that can be read by human.
Features
- RedisCaptcha is easy to setup, easy to use.
- RedisCaptcha provides simple captcha that can be read by human.
- You don't have to manage image files because they will be removed by Tempfile.
- You can set option
locked_times
and locked_time
to avoid someone who want to attack. - The Captcha will be Expired automatically by setting
expired_time
. - ......
Requirements
- Ruby >= 1.9
- Rails > 3.2
- Redis > 2.4
- ImageMagick
I haven't tried lower version yet.
Getting started
1. Add RedisCaptcha to your gemfile
gem 'redis_captcha'
2. Generate initializer
rails g redis_captcha:install
It'll generate config/initializers/redis_captcha.rb
, and you can configure all options here.
3. Mount RedisCaptcha::Engine in your router.rb
mount RedisCaptcha::Engine => '/captcha', :as => :captcha
4. Add before_filter to your controller
class PostsController < ApplicationController
before_filter :generate_captcha_key, :only => [:new, :edit]
......
end
4. Add module to your model
class Post < ActiveRecord::Base
include RedisCaptcha::Model
end
if you set config.active_record.whitelist_attributes = true
in config/application.rb
, remember to add attr_accessible to your model:
attr_accessible :captcha, :captcha_key
to your model.
5. Use RedisCaptcha in your view
<%= image_tag(captcha_path(:timestamp => Time.now.to_i), :alt => "captcha") %>
<%= f.text_field :captcha %>
<%= f.hidden_field :captcha_key, :value => session[:captcha_key] %>
6. Use RedisCaptcha in your controller
@post = Post.new(:title => "test")
@post.valid?
@post.save
@post.valid_without_captcha?
@post.save_without_captcha
Enjoy it!
Todo list
- To add a simple site
- To write tests
History
0.8.0
First Version
Author
License
This project rocks and uses MIT-LICENSE.