Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Checks email if no identity match

  • Loading branch information...
commit bf7dd07729b7151b9486414b8433078d5a3e9f7c 1 parent c8087f5
Mohammad El-Abid authored
4 Gemfile
@@ -2,6 +2,4 @@ source "http://rubygems.org"
2 2
3 3 gem "rspec", ">= 2.0.0.beta.22"
4 4 gem "rails", "3.0.0"
5   -gem "ruby-debug"
6   -gem "jeweler"
7   -
  5 +gem "jeweler"
1  README.textile
Source Rendered
@@ -145,6 +145,7 @@ h2. Contributors
145 145 * "Michael Bumann":http://github.com/bumi
146 146 * "Arek Flinik":http://github.com/blax
147 147 * "Nader Akhnoukh":http://github.com/iamnader
  148 +* "Mohammad El-Abid":http://github.com/TheEmpty
148 149
149 150 h2. Thanks
150 151
4 devise_rpx_connectable.gemspec
@@ -5,7 +5,7 @@
5 5
6 6 Gem::Specification.new do |s|
7 7 s.name = %q{devise_rpx_connectable}
8   - s.version = "0.2.2"
  8 + s.version = "0.2.3"
9 9
10 10 s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11 11 s.authors = ["Nicolas Blanco"]
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26 26 "lib/devise_rpx_connectable/strategy.rb",
27 27 "lib/devise_rpx_connectable/version.rb",
28 28 "lib/devise_rpx_connectable/view_helpers.rb",
29   - "rails/init.rb"
  29 + "init.rb"
30 30 ]
31 31 s.homepage = %q{http://github.com/slainer68/devise_rpx_connectable}
32 32 s.rdoc_options = ["--charset=UTF-8"]
15 lib/devise_rpx_connectable/model.rb
@@ -135,8 +135,19 @@ def rpx_auto_create_account?
135 135 # Authenticate a user based on RPX Identifier.
136 136 #
137 137 def authenticate_with_rpx(attributes = {})
138   - if attributes[:identifier].present?
139   - self.find_for_rpx(attributes[:identifier])
  138 + begin
  139 + if attributes[:identifier].present?
  140 + user = self.find_for_rpx(attributes[:identifier])
  141 + end
  142 +
  143 + if !user and attributes[:email]
  144 + user = self.find_by_email(attributes[:email])
  145 + end
  146 +
  147 + return user
  148 +
  149 + rescue
  150 + raise StandardError, "Oi! error in authenticate_with_rpx()"
140 151 end
141 152 end
142 153
28 lib/devise_rpx_connectable/strategy.rb
@@ -18,28 +18,32 @@ def valid?
18 18 def authenticate!
19 19 klass = mapping.to
20 20 raise StandardError, "RPXNow API key is not defined, please see the documentation of RPXNow gem to setup it." unless RPXNow.api_key.present?
21   - begin
22   - rpx_user = (RPXNow.user_data(params[:token], :extended => klass.rpx_extended_user_data, :additional => klass.rpx_additional_user_data) rescue nil)
23   - fail!(:rpx_invalid) and return unless rpx_user
24 21
25   - if user = klass.authenticate_with_rpx(:identifier => rpx_user["identifier"])
26   - user.on_before_rpx_success(rpx_user)
27   - success!(user)
28   - return
29   - end
  22 + rpx_data = (RPXNow.user_data(params[:token], :extended => klass.rpx_extended_user_data, :additional => klass.rpx_additional_user_data) rescue nil)
  23 + fail!(:rpx_invalid) and return unless rpx_data
  24 +
  25 + if user = klass.authenticate_with_rpx(rpx_data)
  26 + user.on_before_rpx_success(rpx_data)
  27 + success!(user)
  28 + return
  29 + else
  30 + fail!(:unable_to_authenticate) and return
  31 + end
  32 +
  33 + begin
30 34
31 35 fail!(:rpx_invalid) and return unless klass.rpx_auto_create_account?
32 36
33 37 user = klass.new
34   - user.store_rpx_credentials!(rpx_user)
35   - user.on_before_rpx_auto_create(rpx_user)
  38 + user.store_rpx_credentials!(rpx_data)
  39 + user.on_before_rpx_auto_create(rpx_data)
36 40
37 41 user.save(:validate => false)
38   - user.on_before_rpx_success(rpx_user)
  42 + user.on_before_rpx_success(rpx_data)
39 43 success!(user)
40 44
41 45 rescue
42   - fail!(:rpx_invalid)
  46 + fail!(:email_taken)
43 47 end
44 48 end
45 49
2  rails/init.rb
... ... @@ -1,2 +0,0 @@
1   -# encoding: utf-8
2   -require 'devise_rpx_connectable'

0 comments on commit bf7dd07

Please sign in to comment.
Something went wrong with that request. Please try again.