Sha256: cfb977b2574896248b04a6b666fe6358a312ab69a2ab745b8f4e9efa426888a5

Contents?: true

Size: 1.25 KB

Versions: 29

Compression:

Stored size: 1.25 KB

Contents

class Caboose::User < ActiveRecord::Base
  self.table_name = "users"  
  #has_and_belongs_to_many :roles
  has_many :role_memberships
  has_many :roles, :through => :role_memberships  
  attr_accessible :email, :first_name, :last_name, :username, :token, :password, :phone

  before_save do
    self.email = self.email.downcase if self.email
  end
  
  def self.logged_out_user
    return self.where('username' => 'elo').first
  end
  
  def self.logged_out_user_id
    return self.where('username' => 'elo').limit(1).pluck(:id)[0]
  end
  
  def is_allowed(resource, action)
    for role in roles
      if role.is_allowed(resource, action)
        return true
      end
    end
    return false;
  end
  
  def self.validate_token(token)
    user = self.where('token' => token).first
    return user 
  end
  
  def add_to_role_with_name(role_name)
    r = Caboose::Role.where(:name => role_name).first
    return false if r.nil?
    return add_to_role(r.id)
  end
  
  def add_to_role(role_id)
    r = Caboose::Role.find(role_id)
    return false if r.nil?
    
    if (!is_member?(r.id))
      roles.push r
      save
    end
    return true
  end
  
  def is_member?(role_id)
    roles.each do |r|
      return true if (r.id == role_id)
    end
    return false
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
caboose-cms-0.3.32 app/models/caboose/user.rb
caboose-cms-0.3.31 app/models/caboose/user.rb
caboose-cms-0.3.30 app/models/caboose/user.rb
caboose-cms-0.3.29 app/models/caboose/user.rb
caboose-cms-0.3.28 app/models/caboose/user.rb
caboose-cms-0.3.27 app/models/caboose/user.rb
caboose-cms-0.3.26 app/models/caboose/user.rb
caboose-cms-0.3.25 app/models/caboose/user.rb
caboose-cms-0.3.24 app/models/caboose/user.rb
caboose-cms-0.3.23 app/models/caboose/user.rb
caboose-cms-0.3.22 app/models/caboose/user.rb
caboose-cms-0.3.20 app/models/caboose/user.rb
caboose-cms-0.3.19 app/models/caboose/user.rb
caboose-cms-0.3.17 app/models/caboose/user.rb
caboose-cms-0.3.16 app/models/caboose/user.rb
caboose-cms-0.3.15 app/models/caboose/user.rb
caboose-cms-0.3.14 app/models/caboose/user.rb
caboose-cms-0.3.13 app/models/caboose/user.rb
caboose-cms-0.3.12 app/models/caboose/user.rb
caboose-cms-0.3.11 app/models/caboose/user.rb