X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/c8f9387420233bd7e845cb205c3b68ede1f90024..0638eefe22586b9e9f20448e99bfe9a37f3b1540:/app/models/user.rb diff --git a/app/models/user.rb b/app/models/user.rb index 589546e2d..c0468f8b0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) @@ -27,13 +27,16 @@ class User < ActiveRecord::Base def self.authenticate(email, passwd) find_first([ "email = ? AND pass_crypt =?", email, Digest::MD5.hexdigest(passwd) ]) end + + def self.authenticate_token(token) + find_first([ "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