Class: FatFreeCRM::Cloudfuji::EventObservers::AppObserver

Inherits:
Cloudfuji::EventObserver
  • Object
show all
Includes:
Base
Defined in:
lib/fat_free_crm/cloudfuji/event_observers/app_observer.rb

Instance Method Summary collapse

Methods included from Base

#find_lead_by_data, #find_or_create_activity_subject!

Instance Method Details

#app_claimedObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fat_free_crm/cloudfuji/event_observers/app_observer.rb', line 7

def app_claimed
  # Be verbose in development environment
  debug = Rails.env == 'development'

  ido_id = data.try(:[], 'ido_id')

  if user = User.find(:first, :conditions => ["email = ? OR ido_id = ?", data['email'], data['ido_id']])
    puts "Updating #{user.inspect} with incoming data #{params.inspect}" if debug
  else
    user = User.new
    puts "Creating User with incoming data #{params.inspect}" if debug
  end

  puts "Authlogic username column: #{::Authlogic::Cas.cas_username_column}=" if debug
  puts "Setting username to: #{ido_id}" if debug

  user.email      = data['email']
  # Set first and last name from email if both blank
  if user.first_name.blank? && user.last_name.blank?
    user.first_name = user.email.split('@').first
    user.last_name  = user.email.split('@').last
  end
  user.username   = ido_id
  user.deleted_at = nil
  user.admin = true
  user.send("#{::Authlogic::Cas.cas_username_column}=".to_sym, ido_id)

  puts user.inspect if debug
  user.save!
end