Project

kapchonka

0.0
No commit activity in last 3 years
No release in over 3 years
Simple captcha
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 4.1.8
>= 0
 Project Readme

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.