Module: Oauth::Controllers::ConsumerController

Defined in:
lib/oauth/controllers/consumer_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(controller) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/oauth/controllers/consumer_controller.rb', line 4

def self.included(controller)
  controller.class_eval do  
    before_filter :login_required
    before_filter :load_consumer, :except=>:index
    skip_before_filter :verify_authenticity_token,:only=>:callback
  end
end

Instance Method Details

#callbackObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/oauth/controllers/consumer_controller.rb', line 33

def callback
  @request_token_secret=session[params[:oauth_token]]
  if @request_token_secret
    @token=@consumer.create_from_request_token(current_user,params[:oauth_token],@request_token_secret,params[:oauth_verifier])
    if @token
      flash[:notice] = "#{params[:id].humanize} was successfully connected to your account"
      go_back
    else
      flash[:error] = "An error happened, please try connecting again"
      redirect_to oauth_consumer_url(params[:id])
    end
  end

end

#destroyObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/oauth/controllers/consumer_controller.rb', line 48

def destroy
  throw RecordNotFound unless @token
  @token.destroy
  if params[:commit]=="Reconnect"
    redirect_to oauth_consumer_url(params[:id])
  else
    flash[:notice] = "#{params[:id].humanize} was successfully disconnected from your account"
    
    go_back
  end
end

#indexObject



12
13
14
15
16
# File 'lib/oauth/controllers/consumer_controller.rb', line 12

def index
  @consumer_tokens=ConsumerToken.all :conditions=>{:user_id=>current_user.id}
  # The services the user hasn't already connected to
  @services=OAUTH_CREDENTIALS.keys-@consumer_tokens.collect{|c| c.class.service_name}
end

#showObject

creates request token and redirects on to oauth provider’s auth page If user is already connected it displays a page with an option to disconnect and redo



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/oauth/controllers/consumer_controller.rb', line 21

def show
  unless @token
    @request_token=@consumer.get_request_token(callback_oauth_consumer_url(params[:id]))
    session[@request_token.token]=@request_token.secret
    if @request_token.callback_confirmed?
      redirect_to @request_token.authorize_url
    else
      redirect_to(@request_token.authorize_url + "&oauth_callback=#{callback_oauth_consumer_url(params[:id])}")
    end
  end
end