From db01cf108985bd176e1885a3c85450020d4bcc45 Mon Sep 17 00:00:00 2001 From: Tim Assmann Date: Wed, 16 May 2012 19:02:02 +0200 Subject: [PATCH 1/2] add a little fix to authlogic, as in documentation stated, the I18n message should be inside a lambda. Otherwise it will be always the default I18n language and will not be evaluation on request time --- lib/authlogic/acts_as_authentic/email.rb | 4 ++-- lib/authlogic/acts_as_authentic/login.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/authlogic/acts_as_authentic/email.rb b/lib/authlogic/acts_as_authentic/email.rb index 053f585a..bbbc3966 100644 --- a/lib/authlogic/acts_as_authentic/email.rb +++ b/lib/authlogic/acts_as_authentic/email.rb @@ -65,7 +65,7 @@ def merge_validates_length_of_email_field_options(options = {}) # * Default: {:with => Authlogic::Regex.email, :message => lambda {I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}} # * Accepts: Hash of options accepted by validates_format_of def validates_format_of_email_field_options(value = nil) - rw_config(:validates_format_of_email_field_options, value, {:with => Authlogic::Regex.email, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}) + rw_config(:validates_format_of_email_field_options, value, {:with => Authlogic::Regex.email, :message => lambda {I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}}) end alias_method :validates_format_of_email_field_options=, :validates_format_of_email_field_options @@ -107,4 +107,4 @@ def self.included(klass) end end end -end \ No newline at end of file +end diff --git a/lib/authlogic/acts_as_authentic/login.rb b/lib/authlogic/acts_as_authentic/login.rb index 7ea87a13..68702567 100644 --- a/lib/authlogic/acts_as_authentic/login.rb +++ b/lib/authlogic/acts_as_authentic/login.rb @@ -62,7 +62,7 @@ def merge_validates_length_of_login_field_options(options = {}) # * Default: {:with => Authlogic::Regex.login, :message => lambda {I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}} # * Accepts: Hash of options accepted by validates_format_of def validates_format_of_login_field_options(value = nil) - rw_config(:validates_format_of_login_field_options, value, {:with => Authlogic::Regex.login, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}) + rw_config(:validates_format_of_login_field_options, value, {:with => Authlogic::Regex.login, :message => lambda {I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}}) end alias_method :validates_format_of_login_field_options=, :validates_format_of_login_field_options From 6eb0cbee97e7634ed0cf358b3cbf429e5bd1a458 Mon Sep 17 00:00:00 2001 From: Egor Homakov Date: Fri, 18 May 2012 16:55:35 +0400 Subject: [PATCH 2/2] Update lib/authlogic/regex.rb --- lib/authlogic/regex.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/authlogic/regex.rb b/lib/authlogic/regex.rb index 1ef35c0c..85e55068 100644 --- a/lib/authlogic/regex.rb +++ b/lib/authlogic/regex.rb @@ -9,17 +9,18 @@ module Regex # by reading this website: http://www.regular-expressions.info/email.html, which is an excellent resource # for regular expressions. def self.email - return @email_regex if @email_regex - email_name_regex = '[A-Z0-9_\.%\+\-\']+' - domain_head_regex = '(?:[A-Z0-9\-]+\.)+' - domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)' - @email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i + @email_regex ||= begin + email_name_regex = '[A-Z0-9_\.%\+\-\']+' + domain_head_regex = '(?:[A-Z0-9\-]+\.)+' + domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)' + /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i + end end # A simple regular expression that only allows for letters, numbers, spaces, and .-_@. Just a standard login / username # regular expression. def self.login - /\A\w[\w\.+\-_@ ]+$/ + /\A\w[\w\.+\-_@ ]+\z/ end end end