Skip to content

Commit

Permalink
can logout
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenwilkin committed Sep 18, 2009
1 parent f7c4f5d commit 5d78bb0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 28 additions & 0 deletions app/controllers/sessions_controller.rb
@@ -1,5 +1,6 @@
class SessionsController < ApplicationController

# get a request token from twitter
def new
client = TwitterOAuth::Client.new(
:consumer_key => CONSUMER_KEY,
Expand All @@ -11,7 +12,34 @@ def new
redirect_to request_token.authorize_url
end

# callback from twitter after app has been authorized
# exchange the request token for an access token
def auth
client = TwitterOAuth::Client.new(
:consumer_key => CONSUMER_KEY,
:consumer_secret => CONSUMER_SECRET
)
access_token = client.authorize(
session[:request_token],
session[:request_token_key],
:oauth_verifier => params[:oauth_verifier]
)
if client.authorized?
session[:access_token] = access_token.token
session[:access_token_secret] = access_token.secret
session[:user_name] = client.info['name']
end
redirect_to root_url
end

# logout
def destroy
session[:request_token] = nil
session[:request_token_key] = nil
session[:access_token] = nil
session[:access_token_secret] = nil
session[:user_name] = nil
redirect_to root_url
end

end
4 changes: 3 additions & 1 deletion config/routes.rb
Expand Up @@ -32,7 +32,9 @@

map.root :controller => 'pages', :action => 'home'

map.login '/login', :controller => 'sessions', :action => 'new'
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
map.auth '/auth', :controller => 'sessions', :action => 'auth'

# Install the default routes as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should
Expand Down

0 comments on commit 5d78bb0

Please sign in to comment.