Skip to content

Commit

Permalink
configurable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jtoy committed Sep 16, 2010
1 parent 3b10371 commit f780f09
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 10 additions & 0 deletions lib/devise/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ module Twitter
mattr_accessor :scope
@@scope = nil


mattr_accessor :twitter_handle_field
@@twitter_handle_field = "twitter_handle"

mattr_accessor :twitter_oauth_token_field
@@twitter_oauth_token_field = "twitter_oauth_token"

mattr_accessor :twitter_oauth_secret_field
@@twitter_oauth_secret_field = "twitter_oauth_secret"

# Default way to setup Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.
def self.setup
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/twitter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Devise
module Twitter
VERSION = "0.1.2.pre"
VERSION = "0.1.2"
end
end
16 changes: 8 additions & 8 deletions lib/devise/twitter/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

if perform_connect
# Add twitter_handle to current user
already_existing_user = klass.first(:twitter_handle => twitter_handle)
already_existing_user = klass.first(Devise::Twitter.twitter_handle_field => twitter_handle)
if already_existing_user.blank?
# We don't know anyone with this handle, therefore continue with connecting
user = @env['warden'].user
user.login = twitter_handle
user.token = access_token.token
user.secret = access_token.secret
user.send("#{Devise::Twitter.twitter_handle_field}=",twitter_handle)
user.send("#{Devise::Twitter.twitter_oauth_token_field}=", access_token.token)
user.send("#{Devise::Twitter.twitter_oauth_secret_field}=", access_token.secret)
user.save
return user
else
Expand All @@ -23,17 +23,17 @@
previous_user = @env['warden'].user

# Try to find user by token
user = klass.first(:token=> access_token.token, :secret => access_token.secret)
user = klass.first(:Devise::Twitter.twitter_oauth_token_field=> access_token.token, Devise::Twitter.twitter_oauth_secret_field => access_token.secret)

# Since we are logging in a new user we want to make sure the before_logout hook is called
@env['warden'].logout if previous_user.present?

if user.nil?
# Create user if we don't know him yet
user = klass.new
user.login = twitter_handle
user.token = access_token.token
user.secret = access_token.secret
user.send("#{Devise::Twitter.twitter_handle}=",twitter_handle)
user.send("#{Devise::Twitter.twitter_oauth_token}=", access_token.token)
user.send("#{Devise::Twitter.twitter_oauth_secret}=", access_token.secret)
user.save
end

Expand Down

0 comments on commit f780f09

Please sign in to comment.