Sha256: 8dd0a6069f8bf2d75ae189db09b7ba174d50c2fd86e0a20cb1ec5694a8cd1961

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

module Omnisocial
  class AuthController < ApplicationController
  
    unloadable
  
    def new
      if current_user?
        flash[:notice] = 'You are already signed in. Please sign out if you want to sign in as a different user.'
        redirect_to(root_path)
      end
    end
  
    def callback    
      @account = case request.env['rack.auth']['provider']
        when 'twitter' then
          Omnisocial::TwitterAccount.find_or_create_from_auth_hash(request.env['rack.auth'])
        when 'facebook' then
          Omnisocial::FacebookAccount.find_or_create_from_auth_hash(request.env['rack.auth'])
      end
      if current_user && @account.user != current_user
        @account.update_attributes(:user => current_user) 
      end
      if @account.user
        self.current_user = @account.user
        flash[:message] = 'You have logged in successfully.'
        redirect_back_or_default(root_path)
      else
        @user = User.new(:display_name => @account.name)
      end
    end
    
    def confirm
      @account = Omnisocial::LoginAccount.find(params[:account_id])
      @user = User.new(params[:omnisocial_user].merge(:picture_url => @account.picture_url))
      if @user.save
        @account.update_attributes(:user => @user)
        self.current_user = @user
        flash[:message] = 'You have logged in successfully.'
        redirect_back_or_default(root_path)
      else
        render :action => "callback"
      end
    end
  
    def failure
      flash[:error] = "We had trouble signing you in. Did you make sure to grant access? Please select a service below and try again."
      render :action => 'new'
    end
  
    def destroy
      logout!
      redirect_to(session['return_to'] || root_path)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cornflakeomnisocial-0.1.2.7 app/controllers/omnisocial/auth_controller.rb
cornflakeomnisocial-0.1.2.6 app/controllers/omnisocial/auth_controller.rb
cornflakeomnisocial-0.1.2.5 app/controllers/omnisocial/auth_controller.rb
cornflakeomnisocial-0.1.2.4 app/controllers/omnisocial/auth_controller.rb