]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
The render method needs to be last, otherwise the error header won't get set. Needs...
[rails.git] / app / models / user.rb
index 0eddb259d01213506df8aa502aa71076b0a669aa..5a277c9b45b3c500cb595d9530c00bea1549a191 100644 (file)
@@ -30,7 +30,7 @@ class User < ActiveRecord::Base
   file_column :image, :magick => { :geometry => "100x100>" }
 
   def after_initialize
-    self.creation_time = Time.now if self.creation_time.nil?
+    self.creation_time = Time.now.getutc if self.creation_time.nil?
   end
 
   def encrypt_password
@@ -42,7 +42,13 @@ class User < ActiveRecord::Base
 
   def self.authenticate(options)
     if options[:username] and options[:password]
-      user = find(:first, :conditions => ["email = ? OR display_name = ?", options[:username], options[:username]])
+      environment = Rails.configuration.environment
+      adapter = Rails.configuration.database_configuration[environment]["adapter"]
+      if adapter == "postgresql"
+        user = find(:first, :conditions => ["email ILIKE ? OR display_name ILIKE ?", options[:username], options[:username]])
+      else
+        user = find(:first, :conditions => ["email = ? OR display_name = ?", options[:username], options[:username]])
+      end
       user = nil if user and user.pass_crypt != OSM::encrypt_password(options[:password], user.pass_salt)
     elsif options[:token]
       token = UserToken.find(:first, :include => :user, :conditions => ["user_tokens.token = ?", options[:token]])
@@ -110,4 +116,17 @@ class User < ActiveRecord::Base
     return self.preferences.find(:first, :conditions => {:k => "gps.trace.public", :v => "default"})
   end
 
+  def delete
+    self.active = false
+    self.display_name = "user_#{self.id}"
+    self.description = nil
+    self.home_lat = nil
+    self.home_lon = nil
+    self.image = nil
+    self.email_valid = false
+    self.new_email = nil
+    self.visible = false
+    self.save
+  end
+
 end