diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-19 10:47:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-07-19 10:47:19 +0000 |
commit | eb1d969237a9ed1bb41c6e10d5a9eb073f297e95 (patch) | |
tree | 53f88db3c4e26b74979f3d16626ed066cb7f77ae /app/models | |
parent | 93201e7386eb8bb2c69f110d934f04feb81ffe93 (diff) | |
download | redmine-eb1d969237a9ed1bb41c6e10d5a9eb073f297e95.tar.gz redmine-eb1d969237a9ed1bb41c6e10d5a9eb073f297e95.zip |
Improved on-the-fly account creation. If some attributes are missing (eg. not present in the LDAP) or are invalid, the registration form is displayed so that the user is able to fill or fix these attributes.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1678 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/auth_source.rb | 5 | ||||
-rw-r--r-- | app/models/auth_source_ldap.rb | 5 | ||||
-rw-r--r-- | app/models/user.rb | 15 |
3 files changed, 11 insertions, 14 deletions
diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb index 47c121a13..a0a2cdc5f 100644 --- a/app/models/auth_source.rb +++ b/app/models/auth_source.rb @@ -20,10 +20,7 @@ class AuthSource < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name - validates_length_of :name, :host, :maximum => 60 - validates_length_of :account_password, :maximum => 60, :allow_nil => true - validates_length_of :account, :base_dn, :maximum => 255 - validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30 + validates_length_of :name, :maximum => 60 def authenticate(login, password) end diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb index a438bd3c7..655ffd6d5 100644 --- a/app/models/auth_source_ldap.rb +++ b/app/models/auth_source_ldap.rb @@ -20,7 +20,10 @@ require 'iconv' class AuthSourceLdap < AuthSource validates_presence_of :host, :port, :attr_login - validates_presence_of :attr_firstname, :attr_lastname, :attr_mail, :if => Proc.new { |a| a.onthefly_register? } + validates_length_of :name, :host, :account_password, :maximum => 60, :allow_nil => true + validates_length_of :account, :base_dn, :maximum => 255, :allow_nil => true + validates_length_of :attr_login, :attr_firstname, :attr_lastname, :attr_mail, :maximum => 30, :allow_nil => true + validates_numericality_of :port, :only_integer => true def after_initialize self.port = 389 if self.port == 0 diff --git a/app/models/user.rb b/app/models/user.rb index 55fe3ac0d..5a839721c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -103,19 +103,16 @@ class User < ActiveRecord::Base # user is not yet registered, try to authenticate with available sources attrs = AuthSource.authenticate(login, password) if attrs - onthefly = new(*attrs) - onthefly.login = login - onthefly.language = Setting.default_language - if onthefly.save - user = find(:first, :conditions => ["login=?", login]) + user = new(*attrs) + user.login = login + user.language = Setting.default_language + if user.save + user.reload 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.update_attribute(:last_login_on, Time.now) if user && !user.new_record? user rescue => text raise text |