Sha256: 54adec3d8ee3ce6abaad8a05ec776ef0ccf3e95b9b41e18842f9d66b2b603afc

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module Socialite
  class IdentitiesController < ApplicationController
    unloadable

    before_filter :ensure_user, :only => [:destroy]
    respond_to :html, :json

    def create
      auth_hash = request.env['omniauth.auth']
      identity = Identity.find_or_initialize_by_oauth(auth_hash)
      identity.build_user if identity.user.blank?

      if identity.save
        self.current_user ||= identity.user
        flash_message :notice, 'You have logged in successfully.'
      else
        flash_message :error, 'An error occurred. Please try again.'
      end
      respond_with(identity) do |format|
        format.html { redirect_back_or_default }
      end
    end

    def failure
      flash_message :error, 'We had trouble signing you in. Did you make sure to grant access? Please select a service below and try again.'
      respond_with do |format|
        format.html { redirect_back_or_default }
      end
    end

    def destroy
      if identity.destroy
        logout! if identities.count == 0
        flash_message :notice, 'Identity has been unlinked.'
      else
        flash_message :error, 'We had trouble unlinking this service.'
      end
      respond_with(identity) do |format|
        format.html { redirect_back_or_default }
      end
    end

  private

    def identities
      @identities = current_user.identities
    end

    def identity
      @identity ||= current_user.identities.find(params[:id])
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
socialite-0.0.1.beta4 app/controllers/socialite/identities_controller.rb
socialite-0.0.1.beta2 app/controllers/socialite/identities_controller.rb
socialite-0.0.1.beta app/controllers/socialite/identities_controller.rb