app/models/user.rb
531ecd5f
 class User
5fa8b94d
 	include Mongoid::Document
 
10098bcb
 	field :jids, type: Array
 
     def update_pass(jid, pass)
         account_credentials = jids.detect do |f|
0c651ead
             f[:jid] == jid || f['jid'] == jid
10098bcb
         end
 
         account_credentials[:pass] = pass
         save
     end
 
     def self.existing_jid(jid)
0c651ead
         where('jids.jid' => jid).only(:jids).first
10098bcb
     end
 
     def self.create_jid(jid)
         new_user = new(jids: [ {jid: jid} ])
         new_user.save
         new_user
     end
 
     def add_account(another_jid, password)
         jids << {jid: another_jid, pass: password}
         save
     end
0c651ead
 
     def self.crendentials_for_token(token)
         found = Token.where(token: token).only(:user_id).limit(1).first
         if found
             user_id = found.user_id
         else
             return []
         end
 
         user = find(user_id)
         return user ? user.jids : []
     end
5fa8b94d
 end