summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-05 11:50:53 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-02-05 11:50:53 +0000
commita00f04886fac78e489bb030d20414ebdf10841e3 (patch)
tree91d304c1be59bd251afb54143c288eebef2ed1e4 /app
parent1d4ef8964def4ecbe7a11485f72d7fbe61c55724 (diff)
downloadredmine-a00f04886fac78e489bb030d20414ebdf10841e3.tar.gz
redmine-a00f04886fac78e489bb030d20414ebdf10841e3.zip
Increase username length limit from 30 to 60 (#2719).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8778 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/models/mail_handler.rb6
-rw-r--r--app/models/user.rb9
2 files changed, 9 insertions, 6 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 81af7e411..8e8d6568f 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -347,8 +347,8 @@ class MailHandler < ActionMailer::Base
@full_sanitizer ||= HTML::FullSanitizer.new
end
- def self.assign_string_attribute_with_limit(object, attribute, value)
- limit = object.class.columns_hash[attribute.to_s].limit || 255
+ def self.assign_string_attribute_with_limit(object, attribute, value, limit=nil)
+ limit ||= object.class.columns_hash[attribute.to_s].limit || 255
value = value.to_s.slice(0, limit)
object.send("#{attribute}=", value)
end
@@ -359,7 +359,7 @@ class MailHandler < ActionMailer::Base
# Truncating the email address would result in an invalid format
user.mail = email_address
- assign_string_attribute_with_limit(user, 'login', email_address)
+ assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT)
names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split
assign_string_attribute_with_limit(user, 'firstname', names.shift)
diff --git a/app/models/user.rb b/app/models/user.rb
index 9be6143dc..02aecd341 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -71,16 +71,19 @@ class User < Principal
attr_accessor :last_before_login_on
# Prevents unauthorized assignments
attr_protected :login, :admin, :password, :password_confirmation, :hashed_password
-
+
+ LOGIN_LENGTH_LIMIT = 60
+ MAIL_LENGTH_LIMIT = 60
+
validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false
validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }, :case_sensitive => false
# Login must contain lettres, numbers, underscores only
validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
- validates_length_of :login, :maximum => 30
+ validates_length_of :login, :maximum => LOGIN_LENGTH_LIMIT
validates_length_of :firstname, :lastname, :maximum => 30
validates_format_of :mail, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :allow_blank => true
- validates_length_of :mail, :maximum => 60, :allow_nil => true
+ validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true
validates_confirmation_of :password, :allow_nil => true
validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true
validate :validate_password_length