module AuthlogicOauth::ActsAsAuthentic::Methods

Public Class Methods

included(klass) click to toggle source

Set up some simple validations

# File lib/authlogic_oauth/acts_as_authentic.rb, line 34
def self.included(klass)
  klass.class_eval do
    alias_method "#{oauth_token_field.to_s}=".to_sym, :oauth_token=
    alias_method "#{oauth_secret_field.to_s}=".to_sym, :oauth_secret=
  end

  return if !klass.column_names.include?(klass.oauth_token_field.to_s)

  klass.class_eval do
    validate :validate_by_oauth, :if => :authenticating_with_oauth?

    validates_uniqueness_of klass.oauth_token_field, :scope => validations_scope, :if => :using_oauth?
    validates_presence_of klass.oauth_secret_field, :scope => validations_scope, :if => :using_oauth?

    validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_oauth?)
    validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_oauth?)
    validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_oauth?)
    validates_length_of_login_field_options validates_length_of_login_field_options.merge(:if => :validate_password_with_oauth?)
    validates_format_of_login_field_options validates_format_of_login_field_options.merge(:if => :validate_password_with_oauth?)
  end

  # email needs to be optional for oauth
  klass.validate_email_field = false
end

Public Instance Methods

oauth_secret=(value) click to toggle source
# File lib/authlogic_oauth/acts_as_authentic.rb, line 77
def oauth_secret=(value)
  write_attribute(oauth_secret_field, value.blank? ? nil : value)
end
oauth_token=(value) click to toggle source

Set the oauth fields

# File lib/authlogic_oauth/acts_as_authentic.rb, line 73
def oauth_token=(value)
  write_attribute(oauth_token_field, value.blank? ? nil : value)
end
save(perform_validation = true) { |result| ... } click to toggle source
# File lib/authlogic_oauth/acts_as_authentic.rb, line 59
def save(perform_validation = true, &block)
  if perform_validation && block_given? && redirecting_to_oauth_server?
    # Save attributes so they aren't lost during the authentication with the oauth server
    session_class.controller.session[:authlogic_oauth_attributes] = attributes.reject!{|k, v| v.blank?}
    redirect_to_oauth
    return false
  end

  result = super
  yield(result) if block_given?
  result
end