- def self.authenticate(email, passwd, active = true)
- find(:first, :conditions => [ "email = ? AND pass_crypt = ? AND active = ?", email, Digest::MD5.hexdigest(passwd), active])
- end
-
- def self.authenticate_token(token)
- find(:first, :conditions => [ "token = ? ", token])
- end
-
- def self.make_token(length=30)
- chars = 'abcdefghijklmnopqrtuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
- confirmstring = ''
+ def self.authenticate(options)
+ if options[:username] and options[:password]
+ user = find(:first, :conditions => ["email = ? OR display_name = ?", options[:username], options[:username]])
+ 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]])
+ user = token.user if token
+ end