Sha256: 19faa48be976d9ebb74389c31c9fa7e946188e6e73b46c3aa16321789b54339a

Contents?: true

Size: 1000 Bytes

Versions: 1

Compression:

Stored size: 1000 Bytes

Contents

module Omnisocial
  class User
    include Mongoid::Document
    include Mongoid::Timestamps
    
    field :remember_token
    field :display_name
    field :email_address
    field :picture_url
    
    references_many :login_accounts, :class_name => 'Omnisocial::LoginAccount', :dependent => :destroy

    validates_presence_of :display_name, :email_address
  
    def facebook_account
      login_accounts.select{|account| account.kind_of? FacebookAccount}.first
    end

    def from_facebook?
      !!facebook_account
    end

    def from_twitter?
      !!twitter_account
    end
  
    def twitter_account
      login_accounts.select{|account| account.kind_of? TwitterAccount}.first
    end

    def remember
      update_attributes(:remember_token => ::BCrypt::Password.create("#{Time.now}-#{self.login_accounts.first.type}-#{self.login_accounts.first.login}")) unless new_record?
    end
  
    def forget
      update_attributes(:remember_token => nil) unless new_record?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cornflakeomnisocial-0.1.2.3 app/models/omnisocial/user.rb