forked from ambethia/recaptcha
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[change] validates in model instead of controller
- Loading branch information
Jason Kroll
committed
May 26, 2010
1 parent
754d42e
commit 62799ab
Showing
5 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# reCAPTCHA model validation, based on SimpleCaptcha | ||
# (SimpleCaptcha Copyright (c) 2008 [Sur http://expressica.com]) | ||
|
||
module Recaptcha #:nodoc | ||
module ModelHelpers #:nodoc | ||
# class User < ActiveRecord::Base | ||
# apply_recaptcha :message => "my customized message" | ||
# end | ||
module ClassMethods | ||
def apply_recaptcha(options = {}) | ||
instance_variable_set(:@add_to_base, options[:add_to_base]) | ||
instance_variable_set(:@recaptcha_invalid_message, options[:message] || "The words were not entered correctly") | ||
module_eval do | ||
attr_accessor :remote_ip, :recaptcha_challenge_field, :recaptcha_response_field, :authenticate_with_recaptcha | ||
include Recaptcha::ModelHelpers::InstanceMethods | ||
end | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def save_with_recaptcha | ||
def self.validate | ||
super | ||
verify_recaptcha(:model => self, :attribute => :recaptcha) | ||
end | ||
ret = save | ||
def self.validate | ||
super | ||
end | ||
ret | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Base.module_eval do | ||
extend Recaptcha::ModelHelpers::ClassMethods | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'recaptcha' | ||
|
||
ActionView::Base.send(:include, Recaptcha::ClientHelper) | ||
ActionController::Base.send(:include, Recaptcha::Verify) | ||
ActiveRecord::Base.send(:include, Recaptcha::Verify) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters