openid fixes

This commit is contained in:
Stella Rouzi 2014-06-18 17:09:14 +03:00
parent 600adde6ba
commit de58ddde50
4 changed files with 14 additions and 14 deletions

View file

@ -1,13 +1,14 @@
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
module Users
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
[:novell, :google, :facebook, :twitter].each do |provider|
define_method(provider) { handle(provider) }
end
[:novell, :google, :facebook, :twitter].each do |provider|
define_method(provider) { handle(provider) }
end
private
private
def handle(provider)
auth_hash = request.env['omniauth.auth']
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,
@ -29,4 +30,5 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
redirect_back_or_to new_user_registration_path, alert: 'Failed' + e.message
end
end
end
end
end

View file

@ -37,4 +37,4 @@ class DatatableSupporters < Datatable
def columns
["name", "email", "name", "name", "name"]
end
end
end

View file

@ -1,6 +1,6 @@
class Openid < ActiveRecord::Base
belongs_to :user
validates :provider, :uid, :presence => true
validates :provider, :uid, presence: true
# Searches for openid based on provider and uid.
# Returns found openid or a new openid.
@ -16,7 +16,5 @@ class Openid < ActiveRecord::Base
end
end
openid
end
end

View file

@ -63,9 +63,9 @@ feature Openid do
expect(Openid.where(email: 'test-1@gmail.com').first.nil?).to eq(false)
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
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_user = User.count
visit '/accounts/sign_in'