Only show openid options if providers are set in User model.
This commit is contained in:
parent
609f2fd564
commit
be468be5d7
6 changed files with 32 additions and 25 deletions
|
|
@ -2,7 +2,7 @@ module Users
|
||||||
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||||
skip_before_filter :verify_authenticity_token
|
skip_before_filter :verify_authenticity_token
|
||||||
|
|
||||||
[:novell, :google, :facebook, :twitter].each do |provider|
|
User.omniauth_providers.each do |provider|
|
||||||
define_method(provider) { handle(provider) }
|
define_method(provider) { handle(provider) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,13 @@
|
||||||
%br
|
%br
|
||||||
= f.inputs name: 'OpenID' do
|
= f.inputs name: 'OpenID' do
|
||||||
%h4
|
%h4
|
||||||
Currently using the following openIDs:
|
Currently the following openIDs are associated with your account
|
||||||
- @openids.each do |openid|
|
- @openids.each do |openid|
|
||||||
= openid.provider
|
%li= openid.provider + ': ' + openid.email
|
||||||
= openid.email
|
|
||||||
%br
|
%br
|
||||||
|
- if User.omniauth_providers.present?
|
||||||
%h4
|
%h4
|
||||||
To add an openID to your account using a different email address, sign in with your
|
To add an openID with a different email address to your account, sign in with your
|
||||||
openID while logged in to OSEM
|
openID while logged in to OSEM
|
||||||
= render 'devise/shared/openid'
|
= render 'devise/shared/openid'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
%br
|
%br
|
||||||
%h4 Already have an account?
|
%h4 Already have an account?
|
||||||
= render 'devise/shared/links'
|
= render 'devise/shared/links'
|
||||||
|
- if resource_class.omniauth_providers.present?
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.well
|
.well
|
||||||
%h4 Or use your openID
|
%h4 Or use your openID
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
%br
|
%br
|
||||||
= render "devise/shared/links"
|
= render "devise/shared/links"
|
||||||
|
|
||||||
|
- if resource_class.omniauth_providers.present?
|
||||||
.col-md-4
|
.col-md-4
|
||||||
.well
|
.well
|
||||||
%h4 Or use your openID
|
%h4 Or use your openID
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ Devise.setup do |config|
|
||||||
# ==> openIDs configuration
|
# ==> openIDs configuration
|
||||||
# Define the available openID providers that can be used to log in
|
# Define the available openID providers that can be used to log in
|
||||||
# Pass each provider to User model in :omniauth_providers (for open_id providers use their name)
|
# Pass each provider to User model in :omniauth_providers (for open_id providers use their name)
|
||||||
# Include provider in users/omniauth_callbacks_controller.rb
|
|
||||||
|
|
||||||
config.omniauth :open_id, name: 'novell', identifier: 'http://www.opensuse.org/openid/user'
|
config.omniauth :open_id, name: 'novell', identifier: 'http://www.opensuse.org/openid/user'
|
||||||
config.omniauth :google_oauth2, Rails.application.secrets.google_key, Rails.application.secrets.google_secret, {
|
config.omniauth :google_oauth2, Rails.application.secrets.google_key, Rails.application.secrets.google_secret, {
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,15 @@ feature Openid do
|
||||||
let!(:participant_role) { create(:participant_role) }
|
let!(:participant_role) { create(:participant_role) }
|
||||||
let!(:admin_role) { create(:admin_role) }
|
let!(:admin_role) { create(:admin_role) }
|
||||||
|
|
||||||
describe 'sign in with openid' do
|
shared_examples 'sign in with openid' do
|
||||||
|
|
||||||
it 'has option to log in with Google account' do
|
scenario 'has option to log in with Google account' do
|
||||||
visit '/accounts/sign_in'
|
visit '/accounts/sign_in'
|
||||||
expect(page.has_content?('Or use your openID')).to be true
|
expect(page.has_content?('Or use your openID')).to be true
|
||||||
expect(page.has_content?('google')).to be true
|
expect(page.has_content?('google')).to be true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'signs in *new* user with Google account' do
|
scenario 'signs in *new* user with Google account' do
|
||||||
expected_count_openid = Openid.count + 1
|
expected_count_openid = Openid.count + 1
|
||||||
expected_count_user = User.count + 1
|
expected_count_user = User.count + 1
|
||||||
visit '/accounts/sign_in'
|
visit '/accounts/sign_in'
|
||||||
|
|
@ -24,7 +24,7 @@ feature Openid do
|
||||||
expect(User.count).to eq(expected_count_user)
|
expect(User.count).to eq(expected_count_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'signs in an existing user' do
|
scenario 'signs in an existing user' do
|
||||||
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
|
||||||
|
|
@ -37,7 +37,7 @@ feature Openid do
|
||||||
expect(User.count).to eq(expected_count_user)
|
expect(User.count).to eq(expected_count_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can handle authentication error' do
|
scenario 'can handle authentication error' do
|
||||||
OmniAuth.config.mock_auth[:google] = :invalid_credentials
|
OmniAuth.config.mock_auth[:google] = :invalid_credentials
|
||||||
visit '/accounts/sign_in'
|
visit '/accounts/sign_in'
|
||||||
expect(page.has_content?('Or use your openID')).to be true
|
expect(page.has_content?('Or use your openID')).to be true
|
||||||
|
|
@ -45,7 +45,7 @@ feature Openid do
|
||||||
expect(flash).to eq("Could not authenticate you from Google because \"Invalid credentials\".")
|
expect(flash).to eq("Could not authenticate you from Google because \"Invalid credentials\".")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds openid to existing user' do
|
scenario 'adds openid to existing user' do
|
||||||
# Sign in user
|
# Sign in user
|
||||||
user = create(:participant, email: 'test-participant-1@google.com')
|
user = create(:participant, email: 'test-participant-1@google.com')
|
||||||
sign_in user
|
sign_in user
|
||||||
|
|
@ -63,7 +63,7 @@ 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
|
scenario 'signs in with openID using the same email as another associated openid' do
|
||||||
# Sign in user
|
# Sign in 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
|
||||||
|
|
@ -105,4 +105,10 @@ feature Openid do
|
||||||
expect(last_openid.email).to eq('test-1@gmail.com')
|
expect(last_openid.email).to eq('test-1@gmail.com')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'omniauth' do
|
||||||
|
if User.omniauth_providers.present?
|
||||||
|
it_behaves_like 'sign in with openid'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue