Module: AuthlogicConnect::Common::User::InstanceMethods

Defined in:
lib/authlogic_connect/common/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/authlogic_connect/common/user.rb', line 15

def self.included(base)
  base.class_eval do
    has_many :tokens, :class_name => "Token", :dependent => :destroy
    belongs_to :active_token, :class_name => "Token", :dependent => :destroy
    accepts_nested_attributes_for :tokens, :active_token
  end
end

Instance Method Details

#authenticated_withObject



23
24
25
# File 'lib/authlogic_connect/common/user.rb', line 23

def authenticated_with
  @authenticated_with ||= self.tokens.collect{|t| t.service_name.to_s}
end

#authenticated_with?(service) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/authlogic_connect/common/user.rb', line 27

def authenticated_with?(service)
  self.tokens.detect{|t| t.service_name.to_s == service.to_s}
end

#cleanup_auth_sessionObject

it only reaches this point once it has returned, or you have manually skipped the redirect and save was called directly.



79
80
81
82
# File 'lib/authlogic_connect/common/user.rb', line 79

def cleanup_auth_session
  cleanup_oauth_session
  cleanup_openid_session
end

#debug_user_save_postObject



105
106
107
108
109
110
111
# File 'lib/authlogic_connect/common/user.rb', line 105

def debug_user_save_post
  puts "ERRORS: #{errors.full_messages}"
  puts "using_oauth? #{using_oauth?.to_s}"
  puts "using_openid? #{using_openid?.to_s}"
  puts "validate_password_with_oauth? #{validate_password_with_oauth?.to_s}"
  puts "validate_password_with_openid? #{validate_password_with_openid?.to_s}"
end

#debug_user_save_pre(options = {}, &block) ⇒ Object

test methods for dev/debugging, commented out by default



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/authlogic_connect/common/user.rb', line 93

def debug_user_save_pre(options = {}, &block)
  puts "USER SAVE "
  puts "block_given? #{block_given?.to_s}"
  puts "using_oauth? #{using_oauth?.to_s}"
  puts "using_openid? #{using_openid?.to_s}"
  puts "authenticating_with_oauth? #{authenticating_with_oauth?.to_s}"
  puts "authenticating_with_openid? #{authenticating_with_openid?.to_s}"
  puts "validate_password_with_oauth? #{validate_password_with_oauth?.to_s}"
  puts "validate_password_with_openid? #{validate_password_with_openid?.to_s}"
  puts "!using_openid? && require_password? #{(!using_openid? && require_password?).to_s}"
end

#get_token(service_name) ⇒ Object



40
41
42
# File 'lib/authlogic_connect/common/user.rb', line 40

def get_token(service_name)
  self.tokens.detect {|i| i.service_name.to_s == service_name.to_s}
end

#has_token?(service_name) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/authlogic_connect/common/user.rb', line 36

def has_token?(service_name)
  !get_token(service_name).nil?
end

#remotely_authenticating?(&block) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/authlogic_connect/common/user.rb', line 71

def remotely_authenticating?(&block)
  return redirecting_to_oauth_server? if using_oauth? && block_given?
  return redirecting_to_openid_server? if using_openid?
  return false
end

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

core save method coordinating how to save the user. we dont’ want to ru validations based on the authentication mission we are trying to accomplish. instead, we just return save as false. the next time around, when we recieve the callback, we will run the validations

Yields:

  • (result)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/authlogic_connect/common/user.rb', line 50

def save(options = {}, &block)
  # debug_user_save_pre(options, &block)
  options = {} if options == false
  unless options[:skip_redirect] == true
    return false if remotely_authenticating?(&block)
  end
  # forces you to validate, maybe get rid of if needed,
  # but everything depends on this
  if ActiveRecord::VERSION::MAJOR < 3
    result = super(true) # validate!
  else
    result = super(options.merge(:validate => true))
  end
  # debug_user_save_post
  yield(result) if block_given? # give back to controller
  
  cleanup_auth_session if result && !(options.has_key?(:keep_session) && options[:keep_session])
  
  result
end

#update_attributes(attributes, &block) ⇒ Object



31
32
33
34
# File 'lib/authlogic_connect/common/user.rb', line 31

def update_attributes(attributes, &block)
  self.attributes = attributes
  save(:validate => true, &block)
end

#validate_password_with_oauth?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/authlogic_connect/common/user.rb', line 84

def validate_password_with_oauth?
  !using_openid? && super
end

#validate_password_with_openid?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/authlogic_connect/common/user.rb', line 88

def validate_password_with_openid?
  !using_oauth? && super
end