]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
Cope with MESSAGES_DOMAIN not being defined
[rails.git] / app / models / user.rb
index 0b2a902dfac734f71d18c183cefe5863e579bbe1..b52bcefefb432a001e40da00f84d7b01d6a9b240 100644 (file)
@@ -15,7 +15,7 @@ class User < ActiveRecord::Base
   has_many :client_applications
   has_many :oauth_tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
 
-  has_many :active_blocks, :class_name => "UserBlock", :conditions => ['user_blocks.ends_at > \'#{Time.now.getutc.xmlschema(5)}\' or user_blocks.needs_view']
+  has_many :active_blocks, :class_name => "UserBlock", :conditions => proc { [ "user_blocks.ends_at > :ends_at or user_blocks.needs_view", { :ends_at => Time.now.getutc } ] }
   has_many :roles, :class_name => "UserRole"
 
   validates_presence_of :email, :display_name
@@ -36,21 +36,11 @@ class User < ActiveRecord::Base
   validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
   validates_inclusion_of :preferred_editor, :in => Editors::ALL_EDITORS, :allow_nil => true
 
+  after_initialize :set_creation_time
   before_save :encrypt_password
 
   file_column :image, :magick => { :geometry => "100x100>" }
 
-  def after_initialize
-    self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
-  end
-
-  def encrypt_password
-    if pass_crypt_confirmation
-      self.pass_salt = OSM::make_token(8)
-      self.pass_crypt = OSM::encrypt_password(pass_crypt, pass_salt)
-    end
-  end
-
   def self.authenticate(options)
     if options[:username] and options[:password]
       user = find(:first, :conditions => ["email = ? OR display_name = ?", options[:username], options[:username]])
@@ -210,4 +200,17 @@ class User < ActiveRecord::Base
   def access_token(application_key)
     return ClientApplication.find_by_key(application_key).access_token_for_user(self)
   end
+
+private
+
+  def set_creation_time
+    self.creation_time = Time.now.getutc unless self.attribute_present?(:creation_time)
+  end
+
+  def encrypt_password
+    if pass_crypt_confirmation
+      self.pass_salt = OSM::make_token(8)
+      self.pass_crypt = OSM::encrypt_password(pass_crypt, pass_salt)
+    end
+  end
 end