Module: AuthlogicOauth::ActsAsAuthentic::Methods

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OauthProcess

#generate_access_token

Class Method Details

.included(klass) ⇒ Object

Set up some simple validations



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 36

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_secretObject



83
84
85
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 83

def oauth_secret 
  read_attribute(oauth_secret_field)
end

#oauth_secret=(value) ⇒ Object



87
88
89
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 87

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

#oauth_tokenObject

accessors for oauth fields



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

def oauth_token
  read_attribute(oauth_token_field)
end

#oauth_token=(value) ⇒ Object



79
80
81
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 79

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

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

Yields:

  • (result)


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/authlogic_oauth/acts_as_authentic.rb', line 61

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