lib/generators/aai/templates/user.rb in omniauth-aai-0.5.2 vs lib/generators/aai/templates/user.rb in omniauth-aai-0.6.3
- old
+ new
@@ -1,10 +1,34 @@
class User <%= options[:persist] ? "< ActiveRecord::Base" : "" %>
<% if options[:persist] %>
- attr_accessible :uid
+ # attr_accessible :uid
attr_accessor :aai
PERSISTENT = true
+
+ def self.update_or_create_with_omniauth_aai(omniauth_aai)
+ user = find_or_build_with_uid(omniauth_aai['uid'])
+ user.attributes = {
+ unique_id: omniauth_aai.info.unique_id,
+ persistent_id: omniauth_aai.info.persistent_id,
+ email: omniauth_aai.info.email,
+ first_name: omniauth_aai.info.first_name,
+ last_name: omniauth_aai.info.last_name,
+ home_organization: omniauth_aai.info.home_organization,
+ # affiliation: omniauth_aai.info.affiliation,
+ raw_data: omniauth_aai.respond_to?(:to_hash) ? omniauth_aai.to_hash : omniauth_aai.inspect
+ }
+ user.save
+ user
+ end
+
+ def self.find_or_build_with_uid(aai_uid)
+ if aai_uid.present?
+ where(uid: aai_uid).first || new(uid: aai_uid)
+ else
+ new
+ end
+ end
<% else %>
attr_accessor :aai, :uid
PERSISTENT = false
<% end %>
@@ -19,11 +43,10 @@
rescue
nil
end
<% if options[:persist] %>
-
def marshal
self.uid
end
def self.unmarshal(session_data)
@@ -31,11 +54,10 @@
end
def unmarshal(session_data)
self.reload
end
-
<% else %>
def marshal
{
id: self.uid,
aai: aai.present? ? aai[:info] : {}
@@ -50,13 +72,7 @@
def unmarshal(session_data)
self.uid = session_data[:id]
self.aai = session_data[:aai]
end
-
<% end %>
-
- #def shib_session_id
- # aai["extra"]["raw_info"]['Shib-Session-ID']
- #end
- #
end