noosfero | 2 new commits pushed to repository
Bráulio Bhavamitra
gitlab at gitlab.com
Sun Feb 22 20:22:34 BRT 2015
Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/a6b5dfe60d1ecd1e4025467ee0cfdcf7886232fe">a6b5dfe6</a> by Braulio Bhavamitra
Normalize email before save
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/e7b637f76b4f598702aa2d3456941e2295752eec">e7b637f7</a> by Bráulio Bhavamitra
Merge branch 'normalize-email' into 'master'
Normalize email before save
Users were saving emails in uppercase
See merge request !413
- - - - -
Changes:
=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -102,6 +102,7 @@ class User < ActiveRecord::Base
validates_length_of :email, :within => 3..100, :if => (lambda {|user| !user.email.blank?})
validates_uniqueness_of :login, :email, :case_sensitive => false, :scope => :environment_id
before_save :encrypt_password
+ before_save :normalize_email
validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?})
validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('{fn} must be checked in order to signup.').fix_i18n
@@ -336,6 +337,11 @@ class User < ActiveRecord::Base
end
protected
+
+ def normalize_email
+ self.email = self.email.squish.downcase
+ end
+
# before filter
def encrypt_password
return if password.blank?
=====================================
db/migrate/20150112233715_normalize_users_email.rb
=====================================
--- /dev/null
+++ b/db/migrate/20150112233715_normalize_users_email.rb
@@ -0,0 +1,11 @@
+class NormalizeUsersEmail < ActiveRecord::Migration
+ def up
+ User.find_each do |u|
+ u.update_column :email, u.send(:normalize_email)
+ end
+ end
+
+ def down
+ say "this migration can't be reverted"
+ end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150222/1fcebd27/attachment.html>
More information about the Noosfero-dev
mailing list