From a340d8c957bb05b60a9b58ccfdfbcfd6015ea9fa Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 13 Apr 2008 09:12:43 +0000 Subject: [PATCH] Better error message and AR errors in log for failed LDAP on-the-fly user creation (closes #932, #1042). git-svn-id: http://redmine.rubyforge.org/svn/trunk@1345 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/account_controller.rb | 2 ++ app/models/user.rb | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index e719e8c9b..b9224c158 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -56,6 +56,8 @@ class AccountController < ApplicationController flash.now[:error] = l(:notice_account_invalid_creditentials) end end + rescue User::OnTheFlyCreationFailure + flash.now[:error] = 'Redmine could not retrieve the required information from the LDAP to create your account. Please, contact your Redmine administrator.' end # Log out current user and redirect to welcome page diff --git a/app/models/user.rb b/app/models/user.rb index e0b1e238c..a67a08567 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -18,6 +18,9 @@ require "digest/sha1" class User < ActiveRecord::Base + + class OnTheFlyCreationFailure < Exception; end + # Account statuses STATUS_ANONYMOUS = 0 STATUS_ACTIVE = 1 @@ -105,15 +108,17 @@ class User < ActiveRecord::Base onthefly.language = Setting.default_language if onthefly.save user = find(:first, :conditions => ["login=?", login]) - logger.info("User '#{user.login}' created on the fly.") if logger + logger.info("User '#{user.login}' created from the LDAP") if logger + else + logger.error("User '#{onthefly.login}' found in LDAP but could not be created (#{onthefly.errors.full_messages.join(', ')})") if logger + raise OnTheFlyCreationFailure.new end end end user.update_attribute(:last_login_on, Time.now) if user user - - rescue => text - raise text + rescue => text + raise text end # Return user's full name for display -- 2.39.5