Sha256: 5b6aa442b835373ef643a33fb4058d1cf50f7324c39cd7608c42c7da79cf0e7d

Contents?: true

Size: 1.07 KB

Versions: 62

Compression:

Stored size: 1.07 KB

Contents

class Caboose::User < ActiveRecord::Base
  self.table_name = "users"
  has_and_belongs_to_many :roles
  attr_accessible :email, :first_name, :last_name, :username, :token, :password
  
  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 = User.where('token' => token).first
    return user 
  end
  
  def add_to_role_with_name(role_name)
    r = 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 = 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

62 entries across 62 versions & 1 rubygems

Version Path
caboose-cms-0.2.43 app/models/caboose/user.rb
caboose-cms-0.2.42 app/models/caboose/user.rb
caboose-cms-0.2.41 app/models/caboose/user.rb
caboose-cms-0.2.40 app/models/caboose/user.rb
caboose-cms-0.2.39 app/models/caboose/user.rb
caboose-cms-0.2.38 app/models/caboose/user.rb
caboose-cms-0.2.37 app/models/caboose/user.rb
caboose-cms-0.2.36 app/models/caboose/user.rb
caboose-cms-0.2.35 app/models/caboose/user.rb
caboose-cms-0.2.34 app/models/caboose/user.rb
caboose-cms-0.2.33 app/models/caboose/user.rb
caboose-cms-0.2.32 app/models/caboose/user.rb
caboose-cms-0.2.31 app/models/caboose/user.rb
caboose-cms-0.2.30 app/models/caboose/user.rb
caboose-cms-0.2.29 app/models/caboose/user.rb
caboose-cms-0.2.28 app/models/caboose/user.rb
caboose-cms-0.2.26 app/models/caboose/user.rb
caboose-cms-0.2.25 app/models/caboose/user.rb
caboose-cms-0.2.24 app/models/caboose/user.rb
caboose-cms-0.2.23 app/models/caboose/user.rb