Merge pull request #1145 from opf/fix/disabled_self_registration_error

pull/1148/head
Hagen Schink 11 years ago
commit 1fe20dd89a
  1. 14
      app/controllers/account_controller.rb
  2. 2
      app/controllers/concerns/omniauth_login.rb
  3. 3
      config/locales/de.yml
  4. 3
      config/locales/en.yml
  5. 16
      spec/controllers/account_controller_spec.rb
  6. 4
      spec/controllers/concerns/omniauth_login_spec.rb

@ -98,7 +98,10 @@ class AccountController < ApplicationController
# User self-registration
def register
redirect_to(home_url) && return unless Setting.self_registration? || session[:auth_source_registration]
unless Setting.self_registration? || pending_auth_source_registration?
return self_registration_disabled
end
if request.get?
session[:auth_source_registration] = nil
@user = User.new(:language => Setting.default_language)
@ -245,6 +248,10 @@ class AccountController < ApplicationController
end
end
def pending_auth_source_registration?
session[:auth_source_registration] && !session[:auth_source_registration][:omniauth]
end
def register_and_login_via_authsource(user, session, permitted_params)
@user.attributes = permitted_params.user
@user.activate
@ -357,6 +364,11 @@ class AccountController < ApplicationController
end
end
def self_registration_disabled
flash[:error] = I18n.t('account.error_self_registration_disabled')
redirect_to signin_url
end
def account_pending
flash[:notice] = l(:notice_account_pending)
# Set back_url to make sure user is not redirected to an external login page

@ -29,7 +29,7 @@ module OmniauthLogin
# in our database) will be created using this method.
def create_user_from_omniauth(user, auth_hash)
# Self-registration off
return redirect_to(signin_url) unless Setting.self_registration?
return self_registration_disabled unless Setting.self_registration?
# Create on the fly
fill_user_fields_from_omniauth(user, auth_hash)

@ -42,6 +42,9 @@ de:
login_consequences:
other: "Der Account wird aus dem System entfernt. Der Nutzer wird daher nicht mehr in der Lage sein, sich mit seinem derzeitigen Nutzernamen und Passwort anzumelden. Sofern der Nutzer es wünscht, kann er sich über die von der Anwendung zur Verfügung gestellten Mechanismen einen neuen Account zulegen."
self: "Ihr Account wird aus dem System entfernt. Sie werden daher nicht mehr in der Lage sein, sich mit Ihrem derzeitigen Nutzernamen und Passwort anzumelden. Sofern Sie es wünschen, können Sie sich über die von der Anwendung zur Verfügung gestellten Mechanismen einen neuen Account zulegen."
error_self_registration_disabled: >
Auf diesem System ist die Nutzerregistierung deaktiviert. Bitte fragen Sie einen
Administrator nach einem Nutzerkonto.
actionview_instancetag_blank_option: "Bitte auswählen"

@ -42,6 +42,9 @@ en:
login_consequences:
other: "The account will be deleted from the system. Therefore, the user will no longer be able to log in with his current credentials. He/she can choose to become a user of this application again by the means this application grants."
self: "Your account will be deleted from the system. Therefore, you will no longer be able to log in with your current credentials. If you choose to become a user of this application again, you can do so by using the means this application grants."
error_self_registration_disabled: >
User registration is disabled on this system. Please ask an administrator to create an
account for you.
actionview_instancetag_blank_option: "Please select"

@ -193,8 +193,12 @@ describe AccountController do
get :register
end
it 'redirects to home' do
should redirect_to('/') { home_url }
it 'redirects to signin_path' do
expect(response).to redirect_to signin_path
end
it 'shows the right flash message' do
expect(flash[:error]).to eq(I18n.t('account.error_self_registration_disabled'))
end
end
end
@ -309,8 +313,12 @@ describe AccountController do
}
end
it 'redirects to home' do
should redirect_to('/') { home_url }
it 'redirects to signin_path' do
expect(response).to redirect_to signin_path
end
it 'shows the right flash message' do
expect(flash[:error]).to eq(I18n.t('account.error_self_registration_disabled'))
end
end

@ -167,6 +167,10 @@ describe AccountController do
it 'redirects to signin_path' do
expect(response).to redirect_to signin_path
end
it 'shows the right flash message' do
expect(flash[:error]).to eq(I18n.t('account.error_self_registration_disabled'))
end
end
end

Loading…
Cancel
Save