]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/user.rb
API 0.4 Updates - work on traces pages + pagination, edit tab, some API testing
[rails.git] / app / models / user.rb
index 1a12790420a899473de6c4c56fc890a0874e0fd5..4c7a26473712f9ad29691e9394637e6b2e89445a 100644 (file)
@@ -13,7 +13,7 @@ class User < ActiveRecord::Base
   def set_defaults
     self.creation_time = Time.now
     self.timeout = Time.now
-    self.token = make_token()
+    self.token = User.make_token()
   end
   
   def pass_crypt=(str) 
@@ -24,18 +24,19 @@ class User < ActiveRecord::Base
     write_attribute("pass_crypt_confirm", Digest::MD5.hexdigest(str)) 
   end 
 
-  def self.authenticate(email, passwd) 
-    find_first([ "email = ? AND pass_crypt =?", 
-               email, 
-               Digest::MD5.hexdigest(passwd) ]) 
+  def self.authenticate(email, passwd) \r
+    find(:first, :conditions => [ "email = ? AND pass_crypt = ?", email, Digest::MD5.hexdigest(passwd)])\r
+  end 
+
+  def self.authenticate_token(token) 
+    find(:first, :conditions => [ "token = ? ", token])
   end 
   
-  private
-  def make_token
+  def self.make_token(length=30)
     chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
     confirmstring = ''
 
-    30.times do
+    length.times do
       confirmstring += chars[(rand * chars.length).to_i].chr
     end