X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/423f5ffbc27d8e1ad2bef7b2abd3aecc227544c0..0dba53c0232385f0fd080266f9a5ce3665426293:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index 0b2a902df..80dad87b5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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