Module: AuthlogicOauth::ActsAsAuthentic::Methods

Includes:
OauthProcess
Defined in:
lib/authlogic_oauth/acts_as_authentic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Set up some simple validations



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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?)
     .merge(:if => :validate_password_with_oauth?)
     .merge(:if => :validate_password_with_oauth?)
  end
  
  # email needs to be optional for oauth
  klass.validate_email_field = false
end

Instance Method Details

#oauth_secret=(value) ⇒ Object



75
76
77
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 75

def oauth_secret=(value)
  write_attribute(oauth_secret_field, value.blank? ? nil : value)
end

#oauth_token=(value) ⇒ Object

Set the oauth fields



71
72
73
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 71

def oauth_token=(value)
  write_attribute(oauth_token_field, value.blank? ? nil : value)
end

#save(perform_validation = true) {|result| ... } ⇒ Object

Yields:

  • (result)


59
60
61
62
63
64
65
66
67
68
# 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?
    redirect_to_oauth
    return false
  end
  
  result = super
  yield(result) if block_given?
  result
end