`
fireflyman
  • 浏览: 119568 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论

验证码生成插件simple_captcha

    博客分类:
  • ROR
阅读更多
插件地址:https://github.com/eshopworks/simple_captcha

(1)入门篇:
安装插件-->
script/plugin install git://github.com/eshopworks/simple_captcha.git


执行-->
rake simple_captcha:setup


在routes.rb中添加-->
map.simple_captcha '/simple_captcha/:action', :controller => 'simple_captcha'


你还需要在application_controller.rb中加入-->
ApplicationController < ActionController::Base
  include SimpleCaptcha::ControllerHelpers
end


根据我的项目,需要在app/views/events/new.html.erb的form中加上-->
 <p>
    <%= show_simple_captcha(:object => 'event') %>
 </p>


在app/models/event.rb中添加-->

class Event < ActiveRecord::Base
  apply_simple_captcha
end


将app/controllers/events_controller.rb中的create action-->
if @event.save


改为-->
if @event.save_with_captcha


(2)进阶篇
在插件下载的Wiki里,有一个链接,是关于此插件的详细用法的,如下-->
Simple Captcha:http://expressica.com/simple_captcha/

如需要进阶使用,可以根据里面的说明进行相关修改,如->
引用
:label
provides the custom below the image, 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…

    * simply_blue
    * simply_red
    * simply_green
    * embosed_silver
    * all_black
    * distorted_black
    * charcoal_grey
    * almost_invisible

Default is ’simply_blye’
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’.

:code_type
Handles the text of the captcha image. Available options are ‘numeric’ or ‘alphabetic’.
Default is ‘alphabetic’.

:object
the name of the object of the model class, to implement the model based captcha.


看看我的应用-->
在user.rb中
apply_simple_captcha :message => "image and text were different", :add_to_base => true


在对应的new.html.erb里
<p>验证码</p>
<%= show_simple_captcha(:object => 'user', :code_type => 'numeric', :image_style => 'all_black', :distortion => 'low',:label => "(请正确输入图片中的数字?)") %>


因此它看起来应该是这样的-->


(3)实操篇:
从上图可以看到,这种样式其实是很丑的.而且也没有刷新验证码的按钮.反正就是不顺眼.废话不说了,看看netfork兄的文章吧.
验证码生成换成simple_captcha了:http://netfork.iteye.com/blog/434099

以上东东只供记录.
分享到:
评论
1 楼 luopeng_sg 2011-12-28  
请问LZ这用的是JRuby还是CRuby呢?

相关推荐

    给Django Admin添加验证码和多次登录尝试限制的实现

    这是一个Django应用,能够轻松集成到项目中,提供自定义的图像验证码生成。我们还需要`multi_captcha_admin`库来将验证码整合到Admin的登录表单中。安装这两个库后,在`settings.py`中添加它们到`INSTALLED_APPS`...

    wagtail-django-simple-captcha:用于Wagtail表单页面的简单Captcha字段

    `wagtail-django-simple-captcha` 是一个专为Wagtail CMS设计的插件,旨在为Wagtail表单页面提供简单的验证码功能。这个插件结合了Django Simple Captcha库,帮助网站管理员防止自动化机器人或恶意用户进行垃圾邮件...

    cf-simple-captcha:一个简单的基于数学的验证码字段,用于破火山口表单

    【cf-simple-captcha】是一个专为破火山口(CForm)框架设计的简单数学验证码插件。这个插件的核心目标是提供一种安全、有效的方法,防止自动机器人和恶意软件对表单提交的滥用,尤其是那些可能包含敏感信息的表单。...

    PHP网站验证码

    - **Simple CAPTCHA**:PHP的轻量级验证码库,易于集成和自定义。 - **No-CAPTCHA reCAPTCHA**:Google的最新版本,采用人工智能判断,对用户友好,但同样有效防止机器人。 7. **优化用户体验** - **清晰可读**...

    maven:maven项目练手,《maven实战》里的例子,验证码的生成和测试

    在这个 Maven 实战的例子中,我们可能涉及到了验证码生成的相关技术,比如 Java 中的图像处理库(如 Java2D)或第三方库(如 JCaptcha 或 Simple Captcha)来创建随机的、难以自动识别的图像验证码。验证码的测试...

    用于 WordPress 的7个反垃圾工具 管理资料.doc

    Simple CAPTCHA是一款简单易用的验证码插件,它在你的评论表单中添加了一个验证码区域,要求用户输入显示的图像中的字符。这样可以防止自动化程序无休止地发送垃圾评论,因为它需要人类的视觉识别能力才能通过验证。...

    基于jquery 的图形验证

    "s3capcha"可能是该图形验证插件或库的名称,它可能使用Amazon S3(Simple Storage Service)作为后端存储验证码图片。S3是亚马逊提供的云存储服务,可以安全地存储和分发大量数据。 8. **前端验证与后端验证**: ...

    基于Django的网站平台系统源码

    Django可以集成第三方库如django-simple-captcha来生成和验证随机图片验证码,防止机器人自动提交表单,增强网站安全性。 7. **前端分页**: 使用Django的分页器(paginator)功能,可以轻松实现数据集的分页显示...

    Python 学习资源集合

    - django-simple-captcha:高度可定制的Django验证码应用。 - django-simple-spam-blocker:简单的Django垃圾邮件阻止器。 4. **资产管理**: - django-compressor:将CSS和JS压缩到单个文件中。 - django-...

Global site tag (gtag.js) - Google Analytics