Module: AuthlogicRpx::ActsAsAuthentic::Methods

Defined in:
lib/authlogic_rpx/acts_as_authentic.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

Set up some simple validations



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 84

def self.included(klass)
  klass.class_eval do

    case
    when using_no_mapping?
      alias_method :using_rpx?, :using_rpx__nomap?
      alias_method :add_rpx_identifier, :add_rpx_identifier__nomap
      alias_method :identified_by?, :identified_by__nomap?
      alias_method :merge_user_id, :merge_user_id__nomap

      # Uses default find_by_rpx_identifier class method

      # Add an rpx_identifier collection method
      def rpx_identifiers
        [{ :identifier => rpx_identifier, :provider_name => "Unknown" }]
      end

    when using_internal_mapping?
      alias_method :using_rpx?, :using_rpx__internal?
      alias_method :add_rpx_identifier, :add_rpx_identifier__internal
      alias_method :identified_by?, :identified_by__internal?
      alias_method :merge_user_id, :merge_user_id__internal
      has_many :rpx_identifiers, :class_name => 'RPXIdentifier', :validate => false, :dependent => :destroy

      # Add custom find_by_rpx_identifier class method
      #
      def self.find_by_rpx_identifier(id)
        if identifier = RPXIdentifier.find_by_identifier(id)
          identifier.send(self.model_name.downcase )
        elsif self.column_names.include? 'rpx_identifier'
          # check for authentication using <=1.0.4, migrate identifier to rpx_identifiers table
          if user = self.find( :first, :conditions => [ "rpx_identifier = ?", id ] )
            user.add_rpx_identifier( id, 'Unknown' )
          end
          user
        end
      end

    else
      raise AuthlogicRpx::ActsAsAuthentic::ConfigurationError.new( "invalid or unsupported account_mapping_mode" )
    end

    validates_length_of_password_field_options validates_length_of_password_field_options.merge(:if => :validate_password_with_rpx?)
    validates_confirmation_of_password_field_options validates_confirmation_of_password_field_options.merge(:if => :validate_password_with_rpx?)
    validates_length_of_password_confirmation_field_options validates_length_of_password_confirmation_field_options.merge(:if => :validate_password_with_rpx?)

    before_validation :adding_rpx_identifier
  end

  # add relations and validation to RPXIdentifier based on the actual user model class name used
  #
  RPXIdentifier.class_eval do
    belongs_to klass.name.downcase.to_sym
    validates_presence_of "#{klass.name.downcase}_id".to_sym
  end
end

Instance Method Details

#add_rpx_identifier__internal(rpx_id, rpx_provider_name) ⇒ Object

TODO: make rpx_provider_name a std param?



162
163
164
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 162

def add_rpx_identifier__internal( rpx_id, rpx_provider_name )
  self.rpx_identifiers.build(:identifier => rpx_id, :provider_name => rpx_provider_name )
end

#add_rpx_identifier__nomap(rpx_id, rpx_provider_name) ⇒ Object

adds RPX identification to the instance. Abstracts how the RPX identifier is added to allow for multiplicity of underlying implementations aliased to add_rpx_identifier based on authlogic_rpx configuration mode



158
159
160
161
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 158

def add_rpx_identifier__nomap( rpx_id, rpx_provider_name )
  self.rpx_identifier = rpx_id
  #TODO: make rpx_provider_name a std param?
end

#identified_by__internal?(id) ⇒ Boolean

Returns:

  • (Boolean)


171
172
173
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 171

def identified_by__internal?( id )
  self.rpx_identifiers.find_by_identifier( id )
end

#identified_by__nomap?(id) ⇒ Boolean

Checks if given identifier is an identity for this account aliased to identified_by based on authlogic_rpx configuration mode

Returns:

  • (Boolean)


168
169
170
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 168

def identified_by__nomap?( id )
  self.rpx_identifier == id
end

#using_password?Boolean

test if account it using normal password authentication

Returns:

  • (Boolean)


151
152
153
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 151

def using_password?
  !send(crypted_password_field).blank?
end

#using_rpx__internal?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 146

def using_rpx__internal?
  !rpx_identifiers.empty?
end

#using_rpx__nomap?Boolean

test if account it using RPX authentication aliased to using_rpx based on authlogic_rpx configuration mode

Returns:

  • (Boolean)


143
144
145
# File 'lib/authlogic_rpx/acts_as_authentic.rb', line 143

def using_rpx__nomap?
  !rpx_identifier.blank?
end