app/models/user.rb
531ecd5f
 class User
5fa8b94d
 	include Mongoid::Document
 
ca631758
     embeds_many :accounts
     accepts_nested_attributes_for :accounts
 
     index({ 'accounts.jid' => 1 })
10098bcb
 
     def update_pass(jid, pass)
ca631758
         account_credentials = accounts.detect do |f|
0c651ead
             f[:jid] == jid || f['jid'] == jid
10098bcb
         end
 
         account_credentials[:pass] = pass
         save
     end
 
     def self.existing_jid(jid)
ca631758
         where('accounts.jid' => jid).only(:accounts).first
10098bcb
     end
 
     def self.create_jid(jid)
ca631758
         new_user = new()
         new_user.add_account(jid)
10098bcb
         new_user.save
         new_user
     end
 
ca631758
     def add_account(another_jid, password = nil)
         accounts << Account.new(jid: another_jid, pass: password)
10098bcb
         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
 
ca631758
         user = where(id: user_id).only(:accounts).first
         return user ? user.accounts : []
     end
 
     def self.can_save_conversation(my_jid, friend_jid, chat_id = nil)
 
0c651ead
     end
5fa8b94d
 end