Module: Cul::Omniauth::Users::ClassMethods

Defined in:
app/models/concerns/cul/omniauth/users.rb

Instance Method Summary collapse

Instance Method Details

#find_for_cas(token, resource = nil) ⇒ Object



44
45
46
# File 'app/models/concerns/cul/omniauth/users.rb', line 44

def find_for_cas(token, resource=nil)
  find_for_provider(token, 'cas')
end

#find_for_provider(token, provider) ⇒ Object

token is an omniauth hash



33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/concerns/cul/omniauth/users.rb', line 33

def find_for_provider(token, provider)
  return nil unless token['uid']
  props = {:uid => token['uid'].downcase, provider: provider.downcase}
  user = where(props).first
  # create new user if necessary
  unless user
    user = create!(whitelist(props))
    # can we add groups or roles here?
  end
  user
end

#find_for_saml(token, resource = nil) ⇒ Object



48
49
50
# File 'app/models/concerns/cul/omniauth/users.rb', line 48

def find_for_saml(token, resource=nil)
  find_for_provider(token, 'saml')
end

#find_for_wind(token, resource = nil) ⇒ Object



52
53
54
# File 'app/models/concerns/cul/omniauth/users.rb', line 52

def find_for_wind(token, resource=nil)
  find_for_provider(token, 'wind')
end

#from_omniauth(auth) ⇒ Object



56
57
58
59
60
61
# File 'app/models/concerns/cul/omniauth/users.rb', line 56

def from_omniauth(auth)
  where(provider: token['provider'].downcase, uid: token['uid'].downcase).first_or_create do |user|
    user.email = token['info']['email']
    user.password = Devise.friendly_token[0,20]
  end
end