Module: AuthlogicOauth2::ActsAsAuthentic::Methods

Includes:
Oauth2Process
Defined in:
lib/authlogic_oauth2/acts_as_authentic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Set up some simple validations



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 27

def self.included(klass)
  klass.class_eval do
    alias_method "#{oauth2_token_field.to_s}=".to_sym, :oauth2_token=
  end

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

  klass.class_eval do
    validate :validate_by_oauth2, :if => :authenticating_with_oauth2?

    validates_uniqueness_of klass.oauth2_token_field, :scope => validations_scope, :if => :using_oauth2?

    validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
    validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_oauth2?)
    validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_oauth2?)
     .merge(:if => :validate_password_with_oauth2?)
     .merge(:if => :validate_password_with_oauth2?)
    
    validates_format_of_email_field_options(validates_format_of_email_field_options.merge(:unless=>:using_oauth2?))
    validates_length_of_email_field_options(validates_length_of_email_field_options.merge(:unless=>:using_oauth2?))
    validates_uniqueness_of_email_field_options(validates_uniqueness_of_email_field_options.merge(:unless=>:using_oauth2?))
  end
end

Instance Method Details

#oauth2_accessObject

Provides access to an API exposed on the access_token object



86
87
88
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 86

def oauth2_access
  access_token
end

#oauth2_tokenObject

Accessors for oauth2 fields



77
78
79
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 77

def oauth2_token
  read_attribute(oauth2_token_field)
end

#oauth2_token=(value) ⇒ Object



81
82
83
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 81

def oauth2_token=(value)
  write_attribute(oauth2_token_field, value.blank? ? nil : value)
end

#save(perform_validation = true, &block) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/authlogic_oauth2/acts_as_authentic.rb', line 51

def save(perform_validation = true, &block)
  if perform_validation && block_given? && redirecting_to_oauth2_server?
    # Save attributes so they aren't lost during the authentication with the oauth2 server
    session_class.controller.session[:authlogic_oauth2_attributes] = attributes.reject!{|k, v| v.blank?}
    redirect_to_oauth2
    return false
  end

  result = super
  
  # yield(result) if block_given?
  if block_given?
    unless result
      if oauth2_token && (record = self.class.first(:conditions=>["#{oauth2_token_field} = ?", oauth2_token]))
        session_class.create(record)
        result = true
      end
    end

    yield(result)
  end
  
  result
end