Module: Devise::Models::G5Authenticatable::ClassMethods

Defined in:
lib/devise_g5_authenticatable/models/g5_authenticatable.rb

Overview

Finders and creation methods based on auth user data

Instance Method Summary collapse

Instance Method Details

#find_and_update_for_g5_oauth(auth_data) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 108

def find_and_update_for_g5_oauth(auth_data)
  resource = find_for_g5_oauth(auth_data)
  if resource
    resource.update_from_auth(auth_data)
    without_auth_callback { resource.save! }
  end
  resource
end

#find_for_g5_oauth(oauth_data) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 100

def find_for_g5_oauth(oauth_data)
  found_user = find_by_provider_and_uid(oauth_data.provider.to_s,
                                        oauth_data.uid.to_s)
  return found_user if found_user.present?
  find_by_email_and_provider(oauth_data.info.email,
                             oauth_data.provider.to_s)
end

#new_with_session(params, session) ⇒ Object



117
118
119
120
121
122
123
124
125
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 117

def new_with_session(params, session)
  auth_data = session && session['omniauth.auth']

  resource = new
  resource.update_from_auth(auth_data) if auth_data.present?
  resource.assign_attributes(params) unless params.empty?

  resource
end