Merge pull request #311 from differentreality/openid

Only show openid options if providers are set in User model.
This commit is contained in:
Artem Chernikov 2014-07-22 23:30:12 +02:00
commit 9a3451af4f
6 changed files with 32 additions and 25 deletions

View file

@ -2,7 +2,7 @@ module Users
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
skip_before_filter :verify_authenticity_token
[:novell, :google, :facebook, :twitter].each do |provider|
User.omniauth_providers.each do |provider|
define_method(provider) { handle(provider) }
end

View file

@ -15,15 +15,15 @@
%br
= f.inputs name: 'OpenID' do
%h4
Currently using the following openIDs:
Currently the following openIDs are associated with your account
- @openids.each do |openid|
= openid.provider
= openid.email
%li= "#{openid.provider}:#{openid.email}"
%br
%h4
To add an openID to your account using a different email address, sign in with your
openID while logged in to OSEM
= render 'devise/shared/openid'
- if User.omniauth_providers.present?
%h4
To add an openID with a different email address to your account, sign in with your
openID while logged in to OSEM
= render 'devise/shared/openid'
= f.inputs name: 'Account' do
= f.input :email, required: false, input_html: {autocomplete: "off"}

View file

@ -13,8 +13,9 @@
%br
%h4 Already have an account?
= render 'devise/shared/links'
.col-md-4
.well
%h4 Or use your openID
- if resource_class.omniauth_providers.present?
.col-md-4
.well
%h4 Or use your openID
= render 'devise/shared/openid'
= render 'devise/shared/openid'

View file

@ -15,7 +15,8 @@
%br
= render "devise/shared/links"
.col-md-4
.well
%h4 Or use your openID
= render 'devise/shared/openid'
- if resource_class.omniauth_providers.present?
.col-md-4
.well
%h4 Or use your openID
= render 'devise/shared/openid'

View file

@ -8,7 +8,6 @@ Devise.setup do |config|
# ==> openIDs configuration
# 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)
# Include provider in users/omniauth_callbacks_controller.rb
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, {
@ -140,7 +139,7 @@ Devise.setup do |config|
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes
# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false

View file

@ -4,15 +4,15 @@ feature Openid do
let!(:participant_role) { create(:participant_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'
expect(page.has_content?('Or use your openID')).to be true
expect(page.has_content?('google')).to be true
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_user = User.count + 1
visit '/accounts/sign_in'
@ -24,7 +24,7 @@ feature Openid do
expect(User.count).to eq(expected_count_user)
end
it 'signs in an existing user' do
scenario 'signs in an existing user' do
create(:participant, email: 'test-participant-1@google.com')
expected_count_openid = Openid.count + 1
expected_count_user = User.count
@ -37,7 +37,7 @@ feature Openid do
expect(User.count).to eq(expected_count_user)
end
it 'can handle authentication error' do
scenario 'can handle authentication error' do
OmniAuth.config.mock_auth[:google] = :invalid_credentials
visit '/accounts/sign_in'
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\".")
end
it 'adds openid to existing user' do
scenario 'adds openid to existing user' do
# Sign in user
user = create(:participant, email: 'test-participant-1@google.com')
sign_in user
@ -63,7 +63,7 @@ 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
scenario 'signs in with openID using the same email as another associated openid' do
# Sign in user
create(:participant, email: 'test-participant-1@google.com')
expected_count_openid = Openid.count + 1
@ -105,4 +105,10 @@ feature Openid do
expect(last_openid.email).to eq('test-1@gmail.com')
end
end
describe 'omniauth' do
if User.omniauth_providers.present?
it_behaves_like 'sign in with openid'
end
end
end