YinXiangMa CAPTCHA

Author

SouthWolf

Copyright

Copyright © 2011 SouthWolf, Yinxiangma Inc.

License

MIT

Info

github.com/southwolf/yinxiangma

Git

github.com/southwolf/yinxiangma/tree/master

Bugs

github.com/southwolf/yinxiangma/issues

This plugin adds helpers for the YinXiangMa CAPTCHA API. In your views you can use the yinxiangma_tags method to embed the needed javascript, and you can validate in your controllers with yinxiangma_valid.

Beforehand you need to configure YinXiangMa with your custom publisher key. You may find detailed examples below. Exceptions will be raised if you call these methods and the keys can’t be found.

About this gem

This gem tries to introduces a more convenient way to configure YinXiangMa’s settings. The structure & style are inspired by reCAPTCHA gem

Rails Installation

YinXiangMa for Rails, add this to your Gemfile:

gem "yinxiangma", :require => "yinxiangma/rails"

Or, it can be installed as a gem:

config.gem "yinxiangma", :lib => "yinxiangma/rails"

Or, as a standard rails plugin:

script/plugin install git://github.com/southwolf/yinxiangma.git

Setting up your API Keys

There are multiple ways to setup your YinXiangMa API key once you obtain one.

YinXiangMa.configure

You may use the block style configuration. The following code could be placed into a config/initializers/yinxiangma.rb when used in a Rails project.

Yinxiangma.configure do |config|
  config.publisher_key  = 'cb9d0fe8dabdea89019d845be3059973'
  config.mode ='live'
end

This way, you may also set additional options to fit YinXiangMa into your deployment environment.

Shell environment

Or, you can keep your keys out of your code base by exporting the following environment variables. You might do this in the .profile/rc, or equivalent for the user running your application:

export YINXIANGMA_PUBLISHER_KEY  = 'cb9d0fe8dabdea89019d845be3059973'

Per call

You can also pass in your keys as options at runtime, for example:

yinxiangma_tags :publisher_key  => 'cb9d0fe8dabdea89019d845be3059973'

This option might be useful, if the same code base is used for multiple YinXiangMa setups.

To use ‘YinXiangMa’

Add yinxiangma_tags to each form you want to protect.

And, add yinxiangma_valid logic to each form action that you’ve protected.

yinxiangma_tags

This method generate HTML tag including YinXiangMa widget.

yinxiangma_valid

This method returns true or false after processing the parameters from the YinXiangMa widget.

TODO

  • Validation Error handlings

  • Better documentation

  • Switch back to local CAPTCHA or reCAPTHA when YinXiangMa is unavailable

印象码 动态验证码

印象码是目前中国国内推出的第一款视频广告验证码云服务平台,不仅提供了安全的基于云计算的视频验证码服务,为网站提供了良好的验证码用户体验,并且提出了新一代的基于用户反馈的广告计费商业模式概念。

本gem提供了Rails下的印象码功能,配置简单。

首先请注册印象码服务,获取API key 建立config/initializers/yinxiangma.rb 内容如下(请将publisher_key替换成您的key)

Yinxiangma.configure do |config|
  config.publisher_key  = 'cb9d0fe8dabdea89019d845be3059973'
  config.mode ='live'
end

在Gemfile添加

gem "yinxiangma", :require => "yinxiangma/rails"

建立

在View中插入<%= yinxiangma_tags %>, 在View中需要进行验证处插入yinxiangma_valid() 即可