Sha256: 4e2c503dc2f24b33f9989311490cf9af98beb455da79923ac5f2845a6342c01d

Contents?: true

Size: 1.81 KB

Versions: 22

Compression:

Stored size: 1.81 KB

Contents

module AuthlogicConnect::Openid
  # This module is responsible for adding all of the OpenID goodness to the Authlogic::Session::Base class.
  module Session
    # Add a simple openid_identifier attribute and some validations for the field.
    def self.included(klass)
      klass.class_eval do
        include InstanceMethods
      end
    end
    
    module InstanceMethods
      include AuthlogicConnect::Openid::Process
      
      def self.included(klass)
        klass.class_eval do
          validate :validate_by_openid, :if => :authenticating_with_openid?
        end
      end
      
      # Hooks into credentials so that you can pass an :openid_identifier key.
      def credentials=(value)
        super
        values = value.is_a?(Array) ? value : [value]
        hash = values.first.is_a?(Hash) ? values.first.with_indifferent_access : nil
      end
      
      private
        
        def auto_register?
          false
        end
        
        def complete_openid_transaction(result, openid_identifier)
          if result.unsuccessful?
            errors.add_to_base(result.message)
          end
          
          token = AccessToken.find_by_key(openid_identifier.normalize_identifier, :include => [:user])
          
          self.attempted_record = token.user if token
          
          if !attempted_record
            if auto_register?
              self.attempted_record = klass.new
              self.attempted_record.access_tokens << OpenidToken.new(:key => openid_identifier.normalize_identifier)
              self.attempted_record.save
            else
              auth_session[:openid_identifier] = openid_identifier
              errors.add(:user, "Could not find user in our database, have you registered with your openid account?")
            end
          end
        end
        
    end
  end
end

Version data entries

22 entries across 22 versions & 7 rubygems

Version Path
robdimarco-authlogic-connect-0.0.6 lib/authlogic_connect/openid/session.rb
anideo-authlogic-connect-0.0.6 lib/authlogic_connect/openid/session.rb
jspooner-authlogic-connect-0.0.20 lib/authlogic_connect/openid/session.rb
jspooner-authlogic-connect-0.0.19 lib/authlogic_connect/openid/session.rb
foreverman-authlogic-connect-0.0.4 lib/authlogic_connect/openid/session.rb
foreverman-authlogic-connect-0.0.3 lib/authlogic_connect/openid/session.rb
foreverman-authlogic-connect-0.0.2 lib/authlogic_connect/openid/session.rb
foreverman-authlogic-connect-0.0.1 lib/authlogic_connect/openid/session.rb
foreverman-authlogic-connect-0.0.6 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.7 lib/authlogic_connect/openid/session.rb
authlogic-connect-0.0.6 lib/authlogic_connect/openid/session.rb
authlogic-connect-0.0.5.1 lib/authlogic_connect/openid/session.rb
authlogic-connect-0.0.5 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.6 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.5 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.4 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.2 lib/authlogic_connect/openid/session.rb
authlogic-connect-andrewacove-0.5.0 lib/authlogic_connect/openid/session.rb
authlogic-connect-0.0.4.06 lib/authlogic_connect/openid/session.rb
authlogic-connect-x-0.0.4.05x lib/authlogic_connect/openid/session.rb