Permalink
Browse files

Version 1.2.1

  • Loading branch information...
1 parent 92355f7 commit 982cfeefeb4e49077852cfb78ee5c0d8b8b1b881 sur committed Jan 6, 2008
View
@@ -1,4 +1,4 @@
-Copyright (c) 2007 [Sur http://expressica.com]
+Copyright (c) 2008 [Sur http://expressica.com]
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
14 README
@@ -1,8 +1,8 @@
-Copyright (c) 2007 [Sur http://expressica.com]
+Copyright (c) 2008 [Sur http://expressica.com]
SimpleCaptcha
=========================================================================================
- Version: 1.2.0
+ Version: 1.2.1
Author: Sur [http://expressica.com]
Plugin Homepage: http://expressica.com/simple_captcha
Contributors: http://vinsol.com/team
@@ -185,12 +185,16 @@ Options & Examples
:message
---------------------------------------------------------------------------------------
provides the custom message on failure of captcha authentication
- the default is "image did not match with text"
-
+ the default is "Secret Code did not match with the Image"
+
+ :add_to_base
+ ---------------------------------------------------------------------------------------
+ if set to true, appends the error message to the base.
+
Model's Example
---------------------------------------------------------------------------------------
class User < ActiveRecord::Base
- apply_simple_captcha :message => " image and text were different"
+ apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true
end
View
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'rake'
require 'rake/testtask'
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
class CreateSimpleCaptchaData < ActiveRecord::Migration
def self.up
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
class CreateSimpleCaptchaData < ActiveRecord::Migration
def self.up
@@ -1,4 +1,4 @@
-<!-- Copyright (c) 2007 [Sur http://expressica.com] -->
+<!-- Copyright (c) 2008 [Sur http://expressica.com] -->
<style type="text/CSS">
#simple_captcha .simple_captcha_image{
View
@@ -1,9 +1,6 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'simple_captcha_config'
require 'simple_captcha_action_view'
require 'simple_captcha_action_controller'
-require 'simple_captcha_active_record'
-
-
-ActionController::Base.view_paths.unshift File.join(directory, 'assets', 'views') if RAILS_GEM_VERSION.to_f >= 2.0
+require 'simple_captcha_active_record'
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'application'
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'action_view'
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'active_record'
@@ -31,15 +31,18 @@ module ModelHelpers #:nodoc
# @user.save # when captcha validation is not required.
module ClassMethods
def apply_simple_captcha(options = {})
+ instance_variable_set(:@add_to_base, options[:add_to_base])
+ instance_variable_set(
+ :@captcha_invalid_message,
+ options[:message] || "Secret Code did not match with the Image"
+ )
module_eval do
include SimpleCaptcha::ConfigTasks
attr_accessor :captcha, :captcha_key, :authenticate_with_captcha
alias_method :valid_without_captcha?, :valid?
alias_method :save_without_captcha, :save
include SimpleCaptcha::ModelHelpers::InstanceMethods
end
- @captcha_invalid_message =
- options[:message] || "image did not match with the code"
end
end
@@ -52,7 +55,9 @@ def valid?
ret = ret && true
else
ret = false
- self.errors.add(:captcha, @captcha_invalid_message)
+ self.class.instance_variable_get(:@add_to_base) == true ?
+ self.errors.add_to_base(self.class.instance_variable_get(:@captcha_invalid_message)) :
+ self.errors.add(:captcha, self.class.instance_variable_get(:@captcha_invalid_message))
end
simple_captcha_passed!(captcha_key) if ret
return ret
@@ -66,14 +71,14 @@ def valid_with_captcha?
self.authenticate_with_captcha = true
ret = self.valid?
self.authenticate_with_captcha = false
- return ret
+ ret
end
def save_with_captcha
self.authenticate_with_captcha = true
ret = self.save_without_captcha
self.authenticate_with_captcha = false
- return ret
+ ret
end
def save(check_validations=true)
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'digest/sha1'
require 'fileutils'
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
class SimpleCaptchaData < ActiveRecord::Base
set_table_name "simple_captcha_data"
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'fileutils'
@@ -11,61 +11,55 @@ namespace :simple_captcha do
puts "================================DONE==========================================="
end
- def source_file(rails='')
- rails == 'old' ?
+ def migration_source_file
+ @rails == 'old' ?
File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data_less_than_2.0.rb") :
File.join(File.dirname(__FILE__), "../assets", "migrate", "create_simple_captcha_data.rb")
end
+ def write_migration_content
+ copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
+ migration_filename =
+ Dir.entries(copy_to_path).collect do |file|
+ number, *name = file.split("_")
+ file if name.join("_") == "create_simple_captcha_data.rb"
+ end.compact.first
+ migration_file = File.join(copy_to_path, migration_filename)
+ File.open(migration_file, "wb"){|f| f.write(File.read(migration_source_file))}
+ end
+
def copy_view_file
- puts "Copying SimpleCaptcha view file(for rails < 2.0)"
+ puts "Copying SimpleCaptcha view file."
mkdir(File.join(RAILS_ROOT, "app/views/simple_captcha")) unless File.exist?(File.join(RAILS_ROOT, "app/views/simple_captcha"))
+ view_file = @rails == 'old' ? '_simple_captcha.rhtml' : '_simple_captcha.erb'
FileUtils.cp_r(
File.join(File.dirname(__FILE__), "../assets/views/simple_captcha/_simple_captcha.erb"),
- File.join(RAILS_ROOT, "app/views/simple_captcha/_simple_captcha.rhtml")
+ File.join(RAILS_ROOT, "app/views/simple_captcha/", view_file)
)
puts "================================DONE==========================================="
end
- desc "Set up the plugin SimpleCaptcha for rails < 2.0"
- task :setup_old do
+ def do_setup
begin
generate_migration
- copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
- migration_filename =
- Dir.entries(copy_to_path).collect do |file|
- number, *name = file.split("_")
- file if name.join("_") == "create_simple_captcha_data.rb"
- end.compact.first
- migration_file = File.join(copy_to_path, migration_filename)
- File.open(migration_file, "wb"){|f| f.write(File.read(source_file('old')))}
+ write_migration_content
copy_view_file
puts "Final Step"
puts "run the task 'rake db:migrate' to migrate the simple_captcha migration into your db."
- puts "============================AND DONE!========================================"
rescue StandardError => e
p e
end
end
+ desc "Set up the plugin SimpleCaptcha for rails < 2.0"
+ task :setup_old do
+ @rails = 'old'
+ do_setup
+ end
+
desc "Set up the plugin SimpleCaptcha for rails >= 2.0"
task :setup do
- begin
- generate_migration
- copy_to_path = File.join(RAILS_ROOT, "db", "migrate")
- migration_filename =
- Dir.entries(copy_to_path).collect do |file|
- number, *name = file.split("_")
- file if name.join("_") == "create_simple_captcha_data.rb"
- end.compact.first
- migration_file = File.join(copy_to_path, migration_filename)
- File.open(migration_file, "wb"){|f| f.write(File.read(source_file))}
- puts "Final Step"
- puts "run the task 'rake db:migrate' to migrate the simple_captcha migration into your db."
- puts "============================AND DONE!========================================"
- rescue StandardError => e
- p e
- end
+ do_setup
end
end
@@ -1,4 +1,4 @@
-# Copyright (c) 2007 [Sur http://expressica.com]
+# Copyright (c) 2008 [Sur http://expressica.com]
require 'test/unit'

0 comments on commit 982cfee

Please sign in to comment.