Sha256: fcbab01d7de7c18b59521938630a430c5e3962a25bf639bed425c63f8363f18e

Contents?: true

Size: 1.55 KB

Versions: 14

Compression:

Stored size: 1.55 KB

Contents

class User < ActiveRecord::Base
  belongs_to :role
  has_many :blogs, :dependent => :destroy
  has_one :profile, :dependent => :destroy
  has_many :galleries, :dependent => :destroy
  has_many :access_control_entries, :dependent=>:destroy

  accepts_nested_attributes_for :profile

  def initialize(*args)
    super(*args)
    build_profile unless profile
  end

  def self.nobody
    User.new(:role=>Role.nobody)
  end

  def self.root
    User.where(:role_id=>Role.root.id)[0]
  end

  def create_profile

    Profile.create(:user=>self) unless self.profile
  end

  def role?(role)
    if role.kind_of?(Role)
      return role==self.role
    elsif role.is_numeric?
      return self.role_id==role
    else
      return self.role.name.underscore==role.underscore
    end
  end

  def role=(role)
    if role.kind_of? Role
      self.role_id = role.id
    else
      role = role.to_s.camelize
      if role.is_numeric?
        self.role_id= role
      else
        self.role_id= Role.find_by_name(role).id
      end
    end
  end

  def confirm!
    self.confirmed_at = DateTime::now
    save
  end
  devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :lockable, :timeoutable

end

class FullyValidatedUser < User
  def class
    User
  end
  attr_accessor :old_password
  validates :email, :presence => true, :email => true
  validates :old_password, :presence=>true  , :password=>true
  validates :password, :presence=>true      , :length=>{:minimum=>6}
  validates :password_confirmation, :equal_to=>{:other=>:password}
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
wheels-0.1.13 app/models/user.rb
wheels-0.1.12 app/models/user.rb
wheels-0.1.10 app/models/user.rb
wheels-0.1.9 app/models/user.rb
wheels-0.1.8 app/models/user.rb
wheels-0.1.7 app/models/user.rb
wheels-0.1.6 app/models/user.rb
wheels-0.1.5 app/models/user.rb
wheels-0.1.4 app/models/user.rb
wheels-0.1.3 app/models/user.rb
wheels-0.1.2 app/models/user.rb
wheels-0.1.1 app/models/user.rb
wheels-0.1.0 app/models/user.rb
wheels-0.0.49 app/models/user.rb