Sha256: 925c4799252db0ad26e49503d227880e5ee67ca00752c07a1dac219366b3f1db

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

module FatFreeCRM
  module Cloudfuji
    module EventObservers
      class UserObserver < ::Cloudfuji::EventObserver
        def user_added
          puts "Adding a new user with incoming data #{params.inspect}"
          puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="
          puts "Setting username to: #{params['data'].try(:[], 'ido_id')}"

          data = params['data']

          user = User.unscoped.find_or_create_by_ido_id(data['ido_id'])

          user.email      = data['email']
          user.first_name = user.email.split('@').first
          user.last_name  = user.email.split('@').last
          user.username   = data['email']
          user.deleted_at = nil
          user.send("#{::Authlogic::Cas.cas_username_column}=".to_sym, data.try(:[], 'ido_id'))

          puts user.inspect

          user.save!
        end

        def user_removed
          puts "Removing user based on incoming data #{params.inspect}"
          puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="

          user = User.unscoped.find_by_ido_id(params['data']['ido_id'])

          # TODO: Disable the user instead of destroying them (to prevent data loss)
          user.try(:destroy)
        end

        def user_updated
          puts "Updating user based on incoming data #{params.inspect}"
          puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}="

          data = params['data']
          user = User.unscoped.find_by_ido_id(data['ido_id'])

          if user
            # Re-use the CAS login method to set all the extra attributes we
            # care about (first_name, last_name, email, local, timezone,
            # etc.)
            user.cloudfuji_extra_attributes(data)
            user.save
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ffcrm_cloudfuji-0.2.1 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.2.0 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.7 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.6 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.5 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.4 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.3 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb