module Devise::Models::G5Authenticatable::ClassMethods

Finders and creation methods based on auth user data

Public Instance Methods

find_and_update_for_g5_oauth(auth_data) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

without_auth_callback() { || ... } click to toggle source
# File lib/devise_g5_authenticatable/models/g5_authenticatable.rb, line 129
def without_auth_callback
  skip_callback :save, :before, :auth_user, raise: false
  yield
  set_callback :save, :before, :auth_user
end