Class: OmniauthCallbacksController

Inherits:
Devise::OmniauthCallbacksController
  • Object
show all
Defined in:
lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#generic_callback(provider) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb', line 2

def generic_callback( provider )
  @identity = Identity.find_for_oauth request.env["omniauth.auth"]

  @user = @identity.user || current_user

  if @user.nil?
    @user = User.create( email: @identity.email, oauth_callback: true )
    @identity.update_attribute( :user_id, @user.id )
  end

  if @user.email.blank? && @identity.email
    @user.update_attribute( :email, @identity.email)
  end

  if @user.persisted?
    @identity.update_attribute( :user_id, @user.id )
     @user, event: :authentication
    set_flash_message(:notice, :success, kind: provider.capitalize) if is_navigational_format?
  else
    session["devise.#{provider}_data"] = env["omniauth.auth"]
    redirect_to new_user_registration_url
  end
end