Sha256: 16d7b5374d928685564483235f3d5f1a528e9a722cf72469c34a3e4570ed532a
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
require 'digest/sha1' module SimpleCaptcha #:nodoc module Utils #:nodoc # Execute command with params and return output if exit status equal expected_outcodes def self.run(cmd, params = "", expected_outcodes = 0) command = %Q[#{cmd} #{params}].gsub(/\s+/, " ") command = "#{command} 2>&1" unless (image_magick_path = SimpleCaptcha.image_magick_path).blank? command = File.join(image_magick_path, command) end output = `#{command}` unless [expected_outcodes].flatten.include?($?.exitstatus) raise ::StandardError, "Error while running #{cmd}: #{output}" end output end def self.simple_captcha_value(key) #:nodoc SimpleCaptchaData.get_data(key).value rescue nil end def self.simple_captcha_new_value(key) #:nodoc begin # very unsafe to display same code over and over value = '' # SimpleCaptcha.length.times{value << (48 + rand(10)).chr} SimpleCaptcha.length.times{value << (65 + rand(26)).chr} d = SimpleCaptchaData.get_data(key) d.value = value d.save! value rescue nil end end def self.simple_captcha_passed!(key) #:nodoc SimpleCaptchaData.remove_data(key) end def self.generate_key(*args) args << Time.now.to_s Digest::SHA1.hexdigest(args.join) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
glebtv-simple_captcha-0.3.1 | lib/simple_captcha/utils.rb |