- 浏览: 47672 次
- 性别:
- 来自: 杭州
最新评论
https://github.com/kares/simple_captcha
rails plugin install git://github.com/kares/simple_captcha.git
--这个版本已经支持rails3.x
Installation
ruby script/plugin install git://github.com/kares/simple_captcha.git
Setup
After installation, follow these simple steps to setup the plugin. The setup will depend on the version of rails your application is using.
STEP 1
for Rails 3.x :
rails generate simple_captcha
STEP 2
rake db:migrate
STEP 3 (Optional)
configure simple_captcha e.g. in app/config/initializers/simple_captcha.rb
SimpleCaptcha.backend = :quick_magick # default is :RMagick
SimpleCaptcha.image_options = {
:image_color => 'white',
:image_size => '110x30',
:text_color => 'black',
:text_font => 'arial',
:text_size => 22
} # these are the defaults
Usage
Controller Based
Include SimpleCaptcha::ControllerValidation into Your captcha validating controller or put the include into app/controllers/application.rb
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerValidation
end
in the view file within the form tags add this code
<%= show_simple_captcha %>
and in the controller's action authenticate it as
if simple_captcha_valid?
do this
else
do that
end
Model Based
In the view file within the form tags write this code
<%= show_simple_captcha(:object=>"user") %>
and in the model class include SimpleCaptcha::ModelValidation and setup the validation
class User < ActiveRecord::Base
include SimpleCaptcha::ModelValidation
validates_captcha : o n => :create, :message => 'invalid captcha'
end
or if You prefer the old version which doesn't trigger the captcha validation on save (one have to call save_with_captcha)
class User < ActiveRecord::Base
include SimpleCaptcha::ModelValidation
apply_simple_captcha :message => :'invalid_captcha'
end
Options & Examples
View Options
==========================================================================
:label
--------------------------------------------------------------------------
provides the custom text b/w the image and the text field,
the default is "type the code from the image"
:image_style
--------------------------------------------------------------------------
Provides the specific image style for the captcha image.
There are eight different styles available with the plugin as...
1) simply_blue
2) simply_red
3) simply_green
4) charcoal_grey
5) embosed_silver
6) all_black
7) distorted_black
a lmost_invisible
See the included samples <http://github.com/kares/simple_captcha/samples>.
You can also specify 'random' to select the random image style.
:distortion
--------------------------------------------------------------------------
Handles the complexity of the image. The :distortion can be set to 'low',
'medium' or 'high'. Default is 'low'.
:object
--------------------------------------------------------------------------
the name of the object of the model class, to implement the model based
captcha.
How to change the CSS for SimpleCaptcha DOM elements ?
-----------------------------------------------------
You can change the CSS of the SimpleCaptcha DOM elements as per your need
in this file.
For Rails >= 2.0 the file wiil reside as...
"/app/views/simple_captcha/_simple_captcha.erb"
For Rails < 2.0 the file will reside as...
"/app/views/simple_captcha/_simple_captcha.rhtml"
View's Examples
==========================================================================
Controller Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:label => "human authentication") %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'embosed_silver') %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'simply_red',
:distortion => 'medium') %>
Model Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:object => 'user',
:label => "human authentication") %>
Model Options
==========================================================================
:message
--------------------------------------------------------------------------
provides the custom message on failure of captcha authentication
the default is "Secret Code did not match with the Image"
:add_to_base
--------------------------------------------------------------------------
if set to true, appends the error message to the base.
Model's Example
==========================================================================
example
-------
class User < ActiveRecord::Base
apply_simple_captcha # the "old" way using save_with_captcha
end
example
-------
class User < ActiveRecord::Base
validates_captcha :message => "Are you a bot?", :add_to_base => true
end
To disable the validations in test mode, You should now state it explicitly:
class User < ActiveRecord::Base
validates_captcha :unless => lambda { Rails.env.test? }
end
NOTE: This will validate captcha every-time You do a user.save !
There's an API that allows You to (temporary) disable captcha validation for classes, individual instances or even blocks :
User.captcha_validation = false # disables validation globally
user = User.new
...
# force captcha validation for the given instance and block
user.captcha_validation(true) do
user.save!
end
...
# enable captcha validation for the given instance
user.captcha_validation(true)
user.save
...
# reset captcha validation - fallback to the class setting
user.captcha_validation(nil)
user.save # validates captcha if User.captcha_validation?
rails plugin install git://github.com/kares/simple_captcha.git
--这个版本已经支持rails3.x
Installation
ruby script/plugin install git://github.com/kares/simple_captcha.git
Setup
After installation, follow these simple steps to setup the plugin. The setup will depend on the version of rails your application is using.
STEP 1
for Rails 3.x :
rails generate simple_captcha
STEP 2
rake db:migrate
STEP 3 (Optional)
configure simple_captcha e.g. in app/config/initializers/simple_captcha.rb
SimpleCaptcha.backend = :quick_magick # default is :RMagick
SimpleCaptcha.image_options = {
:image_color => 'white',
:image_size => '110x30',
:text_color => 'black',
:text_font => 'arial',
:text_size => 22
} # these are the defaults
Usage
Controller Based
Include SimpleCaptcha::ControllerValidation into Your captcha validating controller or put the include into app/controllers/application.rb
ApplicationController < ActionController::Base
include SimpleCaptcha::ControllerValidation
end
in the view file within the form tags add this code
<%= show_simple_captcha %>
and in the controller's action authenticate it as
if simple_captcha_valid?
do this
else
do that
end
Model Based
In the view file within the form tags write this code
<%= show_simple_captcha(:object=>"user") %>
and in the model class include SimpleCaptcha::ModelValidation and setup the validation
class User < ActiveRecord::Base
include SimpleCaptcha::ModelValidation
validates_captcha : o n => :create, :message => 'invalid captcha'
end
or if You prefer the old version which doesn't trigger the captcha validation on save (one have to call save_with_captcha)
class User < ActiveRecord::Base
include SimpleCaptcha::ModelValidation
apply_simple_captcha :message => :'invalid_captcha'
end
Options & Examples
View Options
==========================================================================
:label
--------------------------------------------------------------------------
provides the custom text b/w the image and the text field,
the default is "type the code from the image"
:image_style
--------------------------------------------------------------------------
Provides the specific image style for the captcha image.
There are eight different styles available with the plugin as...
1) simply_blue
2) simply_red
3) simply_green
4) charcoal_grey
5) embosed_silver
6) all_black
7) distorted_black
a lmost_invisible
See the included samples <http://github.com/kares/simple_captcha/samples>.
You can also specify 'random' to select the random image style.
:distortion
--------------------------------------------------------------------------
Handles the complexity of the image. The :distortion can be set to 'low',
'medium' or 'high'. Default is 'low'.
:object
--------------------------------------------------------------------------
the name of the object of the model class, to implement the model based
captcha.
How to change the CSS for SimpleCaptcha DOM elements ?
-----------------------------------------------------
You can change the CSS of the SimpleCaptcha DOM elements as per your need
in this file.
For Rails >= 2.0 the file wiil reside as...
"/app/views/simple_captcha/_simple_captcha.erb"
For Rails < 2.0 the file will reside as...
"/app/views/simple_captcha/_simple_captcha.rhtml"
View's Examples
==========================================================================
Controller Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:label => "human authentication") %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'embosed_silver') %>
example
-------
<%= show_simple_captcha(:label => "human authentication",
:image_style => 'simply_red',
:distortion => 'medium') %>
Model Based Example
--------------------------------------------------------------------------
example
-------
<%= show_simple_captcha(:object => 'user',
:label => "human authentication") %>
Model Options
==========================================================================
:message
--------------------------------------------------------------------------
provides the custom message on failure of captcha authentication
the default is "Secret Code did not match with the Image"
:add_to_base
--------------------------------------------------------------------------
if set to true, appends the error message to the base.
Model's Example
==========================================================================
example
-------
class User < ActiveRecord::Base
apply_simple_captcha # the "old" way using save_with_captcha
end
example
-------
class User < ActiveRecord::Base
validates_captcha :message => "Are you a bot?", :add_to_base => true
end
To disable the validations in test mode, You should now state it explicitly:
class User < ActiveRecord::Base
validates_captcha :unless => lambda { Rails.env.test? }
end
NOTE: This will validate captcha every-time You do a user.save !
There's an API that allows You to (temporary) disable captcha validation for classes, individual instances or even blocks :
User.captcha_validation = false # disables validation globally
user = User.new
...
# force captcha validation for the given instance and block
user.captcha_validation(true) do
user.save!
end
...
# enable captcha validation for the given instance
user.captcha_validation(true)
user.save
...
# reset captcha validation - fallback to the class setting
user.captcha_validation(nil)
user.save # validates captcha if User.captcha_validation?
- simple_captcha.tar.gz (30.5 KB)
- 下载次数: 15
发表评论
-
fonts in ubuntu
2010-11-17 22:41 1055You can install various fonts i ... -
`require': no such file to load -- readline (LoadError)
2010-11-17 16:56 1782When I type rails console, I ge ... -
RMagick
2010-11-17 01:00 17061,安装必要的LIB sudo apt ... -
备份ruby-1.9.2-p0.tar.bz2
2010-11-16 18:16 919每次下载都很慢,备份下,有需要的朋友可以直接下载 -
开发环境从windows转到linux
2010-11-15 23:46 913开发工具用gedit 下载附件,里面的文件解压缩到root目录 ... -
will_paginate
2010-11-09 17:22 963#will_paginat 中文化 application_ ... -
rails3测试相关
2010-11-07 16:04 1016rake db:create:all --建立test,dev ... -
ubuntu10.10 ruby1.9.2 rails3.0 mysql 架设过程
2010-11-06 19:07 1611ubuntu10.10 ruby1.9.2 rails3.0 ... -
以AJAX发送查询条件给服务器并用partial显示查询结果
2010-10-23 00:44 1097经验证rails3.0.1下 用不了form_remote_t ... -
启用MYSQL后原有程序乱码
2010-10-21 04:43 733发现换了ruby1.9.2和MYSQL以后,原来好好的程序都出 ... -
rails3.0.1数据库从sqlite3迁移到mysql
2010-10-21 03:40 1724rails3.0.1数据库从sqlite3迁移到mysql时出 ... -
rails 创建简单应用
2010-10-20 01:43 1056开始rails之旅 1,创建应用 D:\ror>rail ... -
ruby1.9.2和rails3.0.1 环境部署
2010-10-20 01:10 1093ruby1.9.2和rails3.0.1已经发布,window ...
相关推荐
gem 'simple_captcha_audio' 然后执行: $ bundle 或将其自己安装为: $ gem install simple_captcha_audio 用法 该扩展程序将另一个参数添加到图像生成URL,以促进针对同一验证码的音频文件的生成。 假设...
这是流行的Rubygem simple_captcha一个分支,被遗弃了。 ##特征 零FileSystem使用率(将秘密代码移至db-store并删除了图像存储)。 提供各种图像样式。 提供三个级别的图像复杂性。 在分布式环境中绝对可以...
这是流行的 Rubygem simple_captcha一个分支,它被废弃了。 ##特征 零文件系统使用(秘密代码移至 db-store 并删除图像存储)。 提供各种图像样式。 提供三个级别的图像复杂度。 在分布式环境中工作得很好...
用法示例import me.brennan.captcha.ImageGenerator ;import javax.imageio.ImageIO ;import java.io.FileOutputStream ;public class Test { public static void main ( String [] args ) throws Exception { var ...
simple-captcha-solver, 在 python 中,简单的CAPTCHA解算器 python 中简单的解算器免责声明这是一个很简单的解决方案,非常具体和easy-to-solve验证,像这里建议的 。 用力量找到更复杂的东西。这个想法在本例中,...
**Django Simple Captcha** 是一个专为Django框架设计的轻量级验证码应用,它提供了方便的方法将验证码功能集成到你的Django项目中。这个应用的特色在于其简洁的实现和高度的自定义能力,使得开发者可以根据项目需求...
`wagtail-django-simple-captcha` 是一个专为Wagtail CMS设计的插件,旨在为Wagtail表单页面提供简单的验证码功能。这个插件结合了Django Simple Captcha库,帮助网站管理员防止自动化机器人或恶意用户进行垃圾邮件...
Django Rest验证码django-simple-captcha轻量级版本,可与django-rest-framework 。特征速度:使用cache代替数据库安全性:用于...key,captcha_value) 为了提供此字段,客户端(js代码)应生成密钥: > curl -X PO
**PyPI官网下载 | django-simple-captcha-0.3.6.zip** 这个压缩包文件包含的是`django-simple-captcha`的0.3.6版本,它是一个基于Python和Django框架的简单验证码应用。在Python的开发环境中,尤其是涉及到Web应用...
在文件名"simple_captcha"中,我们可以推测这可能包含了一些简单的验证码图像,可能是为了教学目的或者作为训练数据集的一部分。这些图像可能被用来演示Microsoft Captcha Decoder的工作原理,或者供学习者实践...
SimpleCaptcha生成图形验证码-附件资源
安装这两个库后,在`settings.py`中添加它们到`INSTALLED_APPS`列表,并配置`MULTI_CAPTCHA_ADMIN`以指定使用的验证码引擎。接着,在`urls.py`中引入验证码相关的URL配置,使验证码服务可用。 在前端展示方面,由于...
# 这里假设我们已经有一个渲染验证码图片的方法,如create_captcha_image(captcha_code) image = create_captcha_image(session['captcha_code']) return HttpResponse(image, content_type='image/png') ``` 3...
资源分类:Python库 所属语言:Python 资源全名:django-simple-captcha-0.5.5.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
captcha, simple captcha for golang (go验证码生成器)
在这个案例中,我们关注的是一个名为“wagtail-simple-math-captcha”的库,版本为0.1.1。 描述中提到的“资源来自pypi官网”,意味着这个zip文件是直接从PyPI下载的,确保了来源的可信性和最新性。"wagtail-simple...
在探讨“Eclipse中Android源代码—点击系统封装的方法可以看到源代码”这一主题时,我们首先需要理解几个关键概念:Eclipse集成开发环境(IDE)、Android操作系统、源代码以及系统封装的方法。 ...
Java图形验证码,支持gif、中英文、算术
博文链接:https://magicgod.iteye.com/blog/164507
Django Simple Captcha Django Simple Captcha是一个非常简单但高度可定制的Django应用程序,用于将Captcha图像添加到任何Django表单中。 功能非常易于设置和部署,但也很容易配置Django Simple Captcha Django ...