Skip to content

Commit

Permalink
Checks email if no identity match
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEmpty committed Nov 3, 2010
1 parent c8087f5 commit bf7dd07
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
4 changes: 1 addition & 3 deletions Gemfile
Expand Up @@ -2,6 +2,4 @@ source "http://rubygems.org"

gem "rspec", ">= 2.0.0.beta.22"
gem "rails", "3.0.0"
gem "ruby-debug"
gem "jeweler"

gem "jeweler"
1 change: 1 addition & 0 deletions README.textile
Expand Up @@ -145,6 +145,7 @@ h2. Contributors
* "Michael Bumann":http://github.com/bumi
* "Arek Flinik":http://github.com/blax
* "Nader Akhnoukh":http://github.com/iamnader
* "Mohammad El-Abid":http://github.com/TheEmpty

h2. Thanks

Expand Down
4 changes: 2 additions & 2 deletions devise_rpx_connectable.gemspec
Expand Up @@ -5,7 +5,7 @@

Gem::Specification.new do |s|
s.name = %q{devise_rpx_connectable}
s.version = "0.2.2"
s.version = "0.2.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Nicolas Blanco"]
Expand All @@ -26,7 +26,7 @@ Gem::Specification.new do |s|
"lib/devise_rpx_connectable/strategy.rb",
"lib/devise_rpx_connectable/version.rb",
"lib/devise_rpx_connectable/view_helpers.rb",
"rails/init.rb"
"init.rb"
]
s.homepage = %q{http://github.com/slainer68/devise_rpx_connectable}
s.rdoc_options = ["--charset=UTF-8"]
Expand Down
15 changes: 13 additions & 2 deletions lib/devise_rpx_connectable/model.rb
Expand Up @@ -135,8 +135,19 @@ def rpx_auto_create_account?
# Authenticate a user based on RPX Identifier.
#
def authenticate_with_rpx(attributes = {})
if attributes[:identifier].present?
self.find_for_rpx(attributes[:identifier])
begin
if attributes[:identifier].present?
user = self.find_for_rpx(attributes[:identifier])
end

if !user and attributes[:email]
user = self.find_by_email(attributes[:email])
end

return user

rescue
raise StandardError, "Oi! error in authenticate_with_rpx()"
end
end

Expand Down
28 changes: 16 additions & 12 deletions lib/devise_rpx_connectable/strategy.rb
Expand Up @@ -18,28 +18,32 @@ def valid?
def authenticate!
klass = mapping.to
raise StandardError, "RPXNow API key is not defined, please see the documentation of RPXNow gem to setup it." unless RPXNow.api_key.present?
begin
rpx_user = (RPXNow.user_data(params[:token], :extended => klass.rpx_extended_user_data, :additional => klass.rpx_additional_user_data) rescue nil)
fail!(:rpx_invalid) and return unless rpx_user

if user = klass.authenticate_with_rpx(:identifier => rpx_user["identifier"])
user.on_before_rpx_success(rpx_user)
success!(user)
return
end
rpx_data = (RPXNow.user_data(params[:token], :extended => klass.rpx_extended_user_data, :additional => klass.rpx_additional_user_data) rescue nil)
fail!(:rpx_invalid) and return unless rpx_data

if user = klass.authenticate_with_rpx(rpx_data)
user.on_before_rpx_success(rpx_data)
success!(user)
return
else
fail!(:unable_to_authenticate) and return
end

begin

fail!(:rpx_invalid) and return unless klass.rpx_auto_create_account?

user = klass.new
user.store_rpx_credentials!(rpx_user)
user.on_before_rpx_auto_create(rpx_user)
user.store_rpx_credentials!(rpx_data)
user.on_before_rpx_auto_create(rpx_data)

user.save(:validate => false)
user.on_before_rpx_success(rpx_user)
user.on_before_rpx_success(rpx_data)
success!(user)

rescue
fail!(:rpx_invalid)
fail!(:email_taken)
end
end

Expand Down
2 changes: 0 additions & 2 deletions rails/init.rb

This file was deleted.

0 comments on commit bf7dd07

Please sign in to comment.