prevent the creation of users with empty string email addresses

This commit is contained in:
albert 2011-09-11 17:48:30 -04:00
parent b92c312605
commit 72bfac3d90
2 changed files with 16 additions and 5 deletions

View File

@ -24,6 +24,7 @@ class User < ActiveRecord::Base
validates_confirmation_of :password
validates_presence_of :email, :if => lambda {|rec| rec.new_record? && Danbooru.config.enable_email_verification?}
validate :validate_ip_addr_is_not_banned, :on => :create
before_validation :convert_blank_email_to_null
before_save :encrypt_password
after_save :update_cache
before_create :promote_to_admin_if_first_user
@ -218,7 +219,7 @@ class User < ActiveRecord::Base
end
end
module EmailVerificationMethods
module EmailMethods
def is_verified?
email_verification_key.blank?
end
@ -234,6 +235,12 @@ class User < ActiveRecord::Base
raise User::Error.new("Verification key does not match")
end
end
def convert_blank_email_to_null
if email.blank?
self.email = nil
end
end
end
module BlacklistMethods
@ -332,7 +339,7 @@ class User < ActiveRecord::Base
extend AuthenticationMethods
include FavoriteMethods
include LevelMethods
include EmailVerificationMethods
include EmailMethods
include BlacklistMethods
include ForumMethods
include LimitMethods

View File

@ -45,7 +45,7 @@ end
if Comment.count == 0
puts "Creating comments"
Post.all.each do |post|
20.times do
rand(30).times do
Comment.create(:post_id => post.id, :body => rand(1_000_000).to_s)
end
end
@ -56,8 +56,12 @@ end
if Note.count == 0
puts "Creating notes"
Post.all.each do |post|
3.times do
Note.create(:post_id => post.id, :x => 0, :y => 0, :width => 100, :height => 100, :body => rand(1_000_000).to_s)
rand(10).times do
note = Note.create(:post_id => post.id, :x => 0, :y => 0, :width => 100, :height => 100, :body => rand(1_000_000).to_s)
rand(30).times do |i|
note.update_attributes(:body => (i * i).to_s)
end
end
end
else