Class: UzuUzu::Controller::Login::Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/uzuuzu-core/controller/login/twitter.rb

Instance Method Summary collapse

Instance Method Details

#callbackObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/uzuuzu-core/controller/login/twitter.rb', line 34

def callback
  get_config
  request_token = ::OAuth::RequestToken.new(
    @twitter_consumer,
    session[:twitter_request_token],
    session[:twitter_request_token_secret]
  )
  access_token = request_token.get_access_token(
    {},
    :oauth_token => request.params[:oauth_token],
    :oauth_verifier => request.params[:oauth_verifier]
  )
  session[:twitter_access_token] = access_token.token
  session[:twitter_access_token_secret] = access_token.secret
  session.delete(:twitter_request_token)
  session.delete(:twitter_request_token_secret)
  
  session[:login_user_id] = access_token.params[:user_id]
  session[:login_name] = access_token.params[:screen_name]
  session[:login_domain] = 'twitter'
  
  referrer = session[:referer] || '/'
  session.delete(:referer)
  response.redirect referrer
rescue => e
  logger.debug "twitter_callback_error #{e}"
  response.server_error
end

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/uzuuzu-core/controller/login/twitter.rb', line 15

def index
  get_config
  session[:referer] = session[:referer] || request.referrer || '/'
  
  request_token = @twitter_consumer.get_request_token(
    :oauth_callback => "#{helper.root_uri}#{helper.r(:callback)}"
  )
  session[:twitter_request_token] = request_token.token
  session[:twitter_request_token_secret] = request_token.secret
  
  response.redirect request_token.authorize_url
rescue => e
  logger.debug "twitter_request_error #{e}"
  response.server_error
end