Sha256: ec20e23eb05a1a80c28c6d2406f50725cc789a1a13c3f30902c025b14408ba30
Contents?: true
Size: 1.17 KB
Versions: 2
Compression:
Stored size: 1.17 KB
Contents
module DalliCaptcha class KeyHandler def initialize(captcha_key) @dalli = DalliCaptcha.dalli @captcha_key = captcha_key @options = DalliCaptcha.options @string_key = "#{@options[:dalli_scope]}:#{@captcha_key}:string" #@locked_times_key = "#{@options[:dalli_scope]}:#{@captcha_key}:locked_times" end #set string in memcache def set(string) string = @options[:case_sensitive] ? string : string.downcase @dalli.set(@string_key,string,@options[:expired_time]) #locked_times = @dalli.get(@locked_times_key).to_i #@dalli.incrby(@locked_times_key, 1) #@dalli.expire(@locked_times_key, @options[:locked_time]) if locked_times == 0 end def delete @dalli.delete(@string_key) #@dalli.del(@locked_times_key) end def locked? locked_times = @dalli.get(@locked_times_key).to_i @captcha_key.blank? || (locked_times >= @options[:locked_times]) end def valid?(captcha) string = @dalli.get(@string_key) if captcha.blank? || string.blank? return false else string == (@options[:case_sensitive] ? captcha : captcha.downcase) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dalli_captcha-0.1.0 | lib/dalli_captcha/key_handler.rb |
dalli_captcha-0.0.3 | lib/dalli_captcha/key_handler.rb |