Sha256: 527e2a5a2700f9e49dbe21bbc6a46932df63381ab11add37bc12138058323357

Contents?: true

Size: 1.08 KB

Versions: 8

Compression:

Stored size: 1.08 KB

Contents

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def instagram
    generic_callback( 'instagram' )
  end
  def facebook
    generic_callback( 'facebook' )
  end


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

    @user = @identity.user || current_user
    if @user.nil?
      @user = User.create( email: @identity.email || "" )
      @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 )
      # This is because we've created the user manually, and Device expects a
      # FormUser class (with the validations)
      @user = FormUser.find @user.id
      sign_in_and_redirect @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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
happy_seed-0.0.19 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.18 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.17 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.16 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.15 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.14 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.13 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb
happy_seed-0.0.12 lib/generators/happy_seed/omniauth/templates/app/controllers/omniauth_callbacks_controller.rb