openid fixes
This commit is contained in:
parent
600adde6ba
commit
de58ddde50
4 changed files with 14 additions and 14 deletions
|
|
@ -1,13 +1,14 @@
|
||||||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
module Users
|
||||||
skip_before_filter :verify_authenticity_token
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
|
skip_before_filter :verify_authenticity_token
|
||||||
|
|
||||||
[:novell, :google, :facebook, :twitter].each do |provider|
|
[:novell, :google, :facebook, :twitter].each do |provider|
|
||||||
define_method(provider) { handle(provider) }
|
define_method(provider) { handle(provider) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
private
|
|
||||||
def handle(provider)
|
def handle(provider)
|
||||||
|
|
||||||
auth_hash = request.env['omniauth.auth']
|
auth_hash = request.env['omniauth.auth']
|
||||||
openid = Openid.find_for_oauth(auth_hash) # Get or create openid
|
openid = Openid.find_for_oauth(auth_hash) # Get or create openid
|
||||||
# If openid exists and is associated with a user, sign in with associated user,
|
# If openid exists and is associated with a user, sign in with associated user,
|
||||||
|
|
@ -29,4 +30,5 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
redirect_back_or_to new_user_registration_path, alert: 'Failed' + e.message
|
redirect_back_or_to new_user_registration_path, alert: 'Failed' + e.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class Openid < ActiveRecord::Base
|
class Openid < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
validates :provider, :uid, :presence => true
|
validates :provider, :uid, presence: true
|
||||||
|
|
||||||
# Searches for openid based on provider and uid.
|
# Searches for openid based on provider and uid.
|
||||||
# Returns found openid or a new openid.
|
# Returns found openid or a new openid.
|
||||||
|
|
@ -16,7 +16,5 @@ class Openid < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
openid
|
openid
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,9 @@ feature Openid do
|
||||||
expect(Openid.where(email: 'test-1@gmail.com').first.nil?).to eq(false)
|
expect(Openid.where(email: 'test-1@gmail.com').first.nil?).to eq(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'signs in with openID using the same email as another associated openid' do |user|
|
it 'signs in with openID using the same email as another associated openid' do
|
||||||
# Sign in user
|
# Sign in user
|
||||||
user = create(:participant, email: 'test-participant-1@google.com')
|
create(:participant, email: 'test-participant-1@google.com')
|
||||||
expected_count_openid = Openid.count + 1
|
expected_count_openid = Openid.count + 1
|
||||||
expected_count_user = User.count
|
expected_count_user = User.count
|
||||||
visit '/accounts/sign_in'
|
visit '/accounts/sign_in'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue