Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix variable scopes for better capsulization #367

Merged
merged 4 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 40 deletions.
  1. +40 −40 lib/sorcery/controller/submodules/external.rb
View
80 lib/sorcery/controller/submodules/external.rb
@@ -31,29 +31,29 @@ module InstanceMethods
# sends user to authenticate at the provider's website.
# after authentication the user is redirected to the callback defined in the provider config
- def login_at(provider, args = {})
- @provider = Config.send(provider)
- if @provider.callback_url.present? && @provider.callback_url[0] == '/'
+ def login_at(provider_name, args = {})
+ provider = Config.send(provider_name)
+ if provider.callback_url.present? && provider.callback_url[0] == '/'
uri = URI.parse(request.url.gsub(/\?.*$/,''))
uri.path = ''
uri.query = nil
uri.scheme = 'https' if(request.env['HTTP_X_FORWARDED_PROTO'] == 'https')
host = uri.to_s
- @provider.callback_url = "#{host}#{@provider.callback_url}"
+ provider.callback_url = "#{host}#{provider.callback_url}"
end
- if @provider.has_callback?
- redirect_to @provider.login_url(params,session)
+ if provider.has_callback?
+ redirect_to provider.login_url(params,session)
else
- #@provider.login(args)
+ #provider.login(args)
end
end
# tries to login the user from provider's callback
- def login_from(provider)
- @provider = Config.send(provider)
- @provider.process_callback(params,session)
- @user_hash = @provider.get_user_hash
- if user = user_class.load_from_provider(provider,@user_hash[:uid].to_s)
+ def login_from(provider_name)
+ provider = Config.send(provider_name)
+ provider.process_callback(params,session)
+ user_hash = provider.get_user_hash
+ if user = user_class.load_from_provider(provider_name,user_hash[:uid].to_s)
return_to_url = session[:return_to_url]
reset_session
session[:return_to_url] = return_to_url
@@ -64,22 +64,22 @@ def login_from(provider)
end
# get provider access account
- def access_token(provider)
- @provider = Config.send(provider)
- @provider.access_token
+ def access_token(provider_name)
+ provider = Config.send(provider_name)
+ provider.access_token
end
# If user is logged, he can add all available providers into his account
- def add_provider_to_user(provider)
- provider_name = provider.to_sym
- @provider = Config.send(provider_name)
- @provider.process_callback(params,session)
- @user_hash = @provider.get_user_hash
+ def add_provider_to_user(provider_name)
+ provider_name = provider_name.to_sym
+ provider = Config.send(provider_name)
+ provider.process_callback(params,session)
+ user_hash = provider.get_user_hash
config = user_class.sorcery_config
# first check to see if user has a particular authentication already
- unless (current_user.send(config.authentications_class.to_s.downcase.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}", provider, @user_hash[:uid].to_s))
- user = current_user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name.to_s)
+ unless (current_user.send(config.authentications_class.to_s.downcase.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}", provider_name, user_hash[:uid].to_s))
+ user = current_user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name.to_s)
user.save(:validate => false)
else
user = false
@@ -91,19 +91,19 @@ def add_provider_to_user(provider)
# Initialize new user from provider informations.
# If a provider doesn't give required informations or username/email is already taken,
# we store provider/user infos into a session and can be rendered into registration form
- def create_and_validate_from(provider)
- provider = provider.to_sym
- @provider = Config.send(provider)
- @user_hash = @provider.get_user_hash
+ def create_and_validate_from(provider_name)
+ provider_name = provider_name.to_sym
+ provider = Config.send(provider_name)
+ user_hash = provider.get_user_hash
config = user_class.sorcery_config
- attrs = user_attrs(@provider.user_info_mapping, @user_hash)
+ attrs = user_attrs(provider.user_info_mapping, user_hash)
user = user_class.new(attrs)
- user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider)
+ user.send(config.authentications_class.to_s.downcase.pluralize).build(config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name)
session[:incomplete_user] = {
- :provider => {config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider},
+ :provider => {config.provider_uid_attribute_name => user_hash[:uid], config.provider_attribute_name => provider_name},
:user_hash => attrs
} unless user.save
@@ -126,28 +126,28 @@ def create_and_validate_from(provider)
#
# create_from(provider) {|user| user.some_check }
#
- def create_from(provider)
- provider = provider.to_sym
- @provider = Config.send(provider)
- @user_hash = @provider.get_user_hash
+ def create_from(provider_name)
+ provider_name = provider_name.to_sym
+ provider = Config.send(provider_name)
+ user_hash = provider.get_user_hash
config = user_class.sorcery_config
- attrs = user_attrs(@provider.user_info_mapping, @user_hash)
+ attrs = user_attrs(provider.user_info_mapping, user_hash)
user_class.transaction do
- @user = user_class.new()
+ user = user_class.new()
attrs.each do |k,v|
- @user.send(:"#{k}=", v)
+ user.send(:"#{k}=", v)
end
if block_given?
- return false unless yield @user
+ return false unless yield user
end
- @user.save(:validate => false)
- user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider, config.provider_uid_attribute_name => @user_hash[:uid]})
+ user.save(:validate => false)
+ user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => user.id, config.provider_attribute_name => provider_name, config.provider_uid_attribute_name => user_hash[:uid]})
end
- @user
+ user
end
def user_attrs(user_info_mapping, user_hash)
Something went wrong with that request. Please try again.