Sha256: 70d4908b78e1aaea3522d3bd0db6e0607826a7874f92127ac78a7524d0eb03f1

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

module Billfold
  class IdentitiesController < ApplicationController

    before_filter :require_sign_in, :only => [ :index, :destroy ]

    respond_to :html, :json, :xml
    helper_method :identities, :identity

    def index
      respond_to do |format|
        format.html {}
        format.json { render :json => identities }
        format.xml  { render :xml  => identities }
      end
    end

    def update_or_create
      omniauth_hash = request.env['omniauth.auth'] || {}
      identity = Billfold.identity_class.update_or_create!({
        :provider => params[:provider],
        :value    => omniauth_hash['uid'],
        :data     => omniauth_hash['user_info'],
        :user     => current_user
      })
      self.current_user ||= identity.user
      respond_to do |format|
        format.html { redirect_to '/' }
        format.json { head 201 }
        format.xml  { head 201 }
      end
    end

    def destroy
      identity.destroy
      respond_to do |format|
        format.html { redirect_to :index }
        format.json { head 200 }
        format.xml  { head 200 }
      end
    end

    private

    def identities
      @identities ||= current_user.identities
    end

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
billfold-1.0.1 app/controllers/billfold/identities_controller.rb
billfold-1.0.0 app/controllers/billfold/identities_controller.rb