Sha256: 6a8d4140783a51177095a4ce7607d1e30e7c3aaa93b19b879c5f2bae3da5303f
Contents?: true
Size: 1.29 KB
Versions: 5
Compression:
Stored size: 1.29 KB
Contents
class User < ActiveRecord::Base include Ext::DeviseConfiguration include Ext::Integrations::User has_many :shows has_many :orders has_many :imports has_many :discounts has_many :user_memberships has_many :organizations, :through => :user_memberships scope :logged_in_more_than_once, where("users.sign_in_count > 1") def self.generate_password Devise.friendly_token end # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me, :user_agreement, :newsletter_emails def is_in_organization? @is_in_organization ||= user_memberships.any? end def current_organization @current_organization ||= (is_in_organization? ? user_memberships.first.organization : Organization.new) end def membership_in(organization) user_memberships.where(:organization_id => organization.id).limit(1).first end def self.like(query = "") return if query.blank? q = "%#{query}%" self.joins("LEFT OUTER JOIN user_memberships m ON m.user_id = users.id") .joins("LEFT OUTER JOIN organizations o ON o.id = m.organization_id") .includes(:organizations) .where("users.email like ? or o.name like ?", q, q) end def active_for_authentication? super && !suspended? end end
Version data entries
5 entries across 5 versions & 1 rubygems