Skip to content

edgarMeinart/rb-kapchonka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kapchonka

Simple match captcha for Rails 4

Live preview: http://kapchonka.meinart.ninja

Rails Installation

Add this to your Gemfile:

     gem 'kapchonka'

Run the following command to install it:

    bundle install

Run the generator:

    rails generate kapchonka

Gem tested only on Rails 4

Recaptcha.configure

    Kapchonka.setup do |k|
        k.store = :session
    
        # k.image_width = 180
        # k.image_height = 90
        # k.font_family = 'Arial'
        # k.font_size = 24
        # k.font_size = 24
        # k.font_color = 'black'
        # k.stroke_width = 0
        # k.stroke_color = 'transparent'
        # k.operand = %w(+ - *)
        # k.operant_max_number = 10
    end

To use 'Kaptchonka'

View

Add captcha tag to each form you want to protect.

    = simple_form_for @post, url: posts_path do |form|
        = render 'form', form: form
        hr
        = show_kapchonka
        hr
        = form.submit 'Create', class: 'btn btn-primary'

Kapchonka will generates a partial '_kapchonka_partial.slim' in 'views/shared/'

scss:
  .kapchonka {
    width: 30%; min-width: 300px;
  }

.kapchonka
  .kapchonka-image
    img  src="data:image/png;base64,#{image_data}"
  .kapchonka-input.form-group
    input.form-control type="number" name="#{input_name}" placeholder="#{I18n.t 'kapchonka.placeholder'}" required="required"
  .kapchonka-label
    = I18n.t 'kapchonka.label'
Controller
class PostsController < ApplicationController
  include Kapchonka::ControllerHelper
  
  before_action :generate_kapchonka, only: [ :new ]
  before_action :wrong_captcha, only: [ :create ], unless: :kapchonka_valid?
end

Redis

Kapchonka also support redis!

Add redis gem to gemfile:

  gem 'redis'

update initilizer:

redis = Redis.new host: '127.0.0.1', port: 6379

Kapchonka.setup do |k|
  k.store = :redis
  k.redis = redis
end

Memcached

update initilizer:

 memcache = Memcached.new("localhost:11211")
 Kapchonka.setup do |k|
   k.store = :memcache
   k.driver = memcache
 end

I18n:

en:
  kapchonka:
    placeholder: 'Answer of equation'
    label: 'Solve equation and type answer!'

Bug reports

If you discover any bugs, feel free to create an issue on GitHub.

About

A simple math captcha for rails.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages