Sha256: 214938ca1eb497693d772314efffce99a2d51bda0d36a59705cdf44ef4753eeb

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ffcrm_cloudfuji-0.1.1 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb
ffcrm_cloudfuji-0.1.0 lib/fat_free_crm/cloudfuji/event_observers/user_observer.rb