You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

13 years ago
class User < ActiveRecord::Base
12 years ago
include SentientModel
model_stamper
stampable
13 years ago
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :timeoutable and :omniauthable
devise :database_authenticatable,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable,
:confirmable,
:lockable
13 years ago
validates :first_name, :last_name, :presence => true
13 years ago
# Setup accessible (or protected) attributes for your model
13 years ago
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name
13 years ago
has_many :domains, :inverse_of => :user, :dependent => :destroy
has_many :records, :inverse_of => :user, :dependent => :destroy
has_many :permissions, :inverse_of => :user, :dependent => :destroy
has_many :permitted_domains, :through => :permissions, :source => :domain
def name
full_name.blank? ? email : full_name
end
def full_name
13 years ago
"#{first_name} #{last_name}"
end
13 years ago
# domains per user limit for DOS protection
def domains_exceeding?
domains.count >= Settings.max_domains_per_user.to_i
end
# Called by Devise to see if an user can currently be signed in
def active_for_authentication?
active? && super
end
# Called by Devise to get the proper error message when an user cannot be signed in
def inactive_message
!active? ? :deactivated : super
end
delegate :can?, :cannot?, :to => :ability
def ability(options = {:reload => false})
options[:reload] ? _ability : (@ability ||= _ability)
end
12 years ago
def self.do_as(user)
self.current = user
self.stamper = user
yield
self.current = nil
self.reset_stamper
end
protected
def _ability
12 years ago
UserAbility.new(self)
end
end