Module: Shibboleth::Rails::ModelAdditions::ClassMethods

Defined in:
lib/shibboleth-rails/user_model_additions.rb

Instance Method Summary collapse

Instance Method Details

#find_or_create_from_shibboleth(identity) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/shibboleth-rails/user_model_additions.rb', line 10

def find_or_create_from_shibboleth(identity)
  affiliations    = identity.delete(:affiliations)
  first_name      = identity.delete(:first_name)
  last_name       = identity.delete(:last_name)

  user = find_or_create_by_emplid(identity)

  # names change due to marriage, etc.
  # update_attribute is a NOOP if not different
  user.update_attribute(:name_n, identity[:name_n])
  user.update_attribute(:first_name, first_name) if user.respond_to?(:first_name) && first_name.present?
  user.update_attribute(:last_name, last_name) if user.respond_to?(:last_name) && last_name.present?

  user.update_role(affiliations) if user.respond_to?(:update_role)
  user
end