Sha256: a7d4f91911b65f6df9f955583de23fbcaebbaa9cc805c2309ec9a7b6d08d6604

Contents?: true

Size: 1.79 KB

Versions: 8

Compression:

Stored size: 1.79 KB

Contents

module Alchemy
  class User < ActiveRecord::Base

    model_stamper
    stampable(:stamper_class_name => 'Alchemy::User')
    acts_as_authentic do |c|
      c.transition_from_restful_authentication = true
      c.logged_in_timeout = Config.get(:auto_logout_time).minutes
    end
    acts_as_taggable

    attr_accessible(
      :firstname,
      :lastname,
      :login,
      :email,
      :gender,
      :role,
      :language,
      :password,
      :password_confirmation,
      :tag_list
    )

    has_many :folded_pages

    before_destroy :unlock_pages

    scope :admins, where(:role => 'admin')

    ROLES = Config.get(:user_roles)

    def role_symbols
      [role.to_sym]
    end

    def is_admin?
      self.role == "admin"
    end
    alias_method :admin?, :is_admin?

    def unlock_pages
      for page in pages_locked_by_me
        page.unlock
      end
    end

    def pages_locked_by_me
      Page.where(:locked => true).where(:locked_by => self.id).order(:updated_at)
    end

    # Returns the firstname and lastname as a string
    # If both are blank, returns the login
    # options
    #   :flipped=false  : returns "lastname, firstname"
    def fullname(options = {})
      unless (self.lastname.blank? && self.firstname.blank?)
        options = (default_options = {:flipped => false}.merge(options))
        options[:flipped] ? "#{self.lastname}, #{self.firstname}".squeeze(" ") : "#{self.firstname} #{self.lastname}".squeeze(" ")
      else
        self.login
      end
    end

    alias :name :fullname

    def human_role_name
      self.class.human_rolename(self.role)
    end

    def self.human_rolename(role)
      I18n.t("user_roles.#{role}")
    end

    def self.genders_for_select
      [
        [I18n.t('male'), 'male'],
        [I18n.t('female'), 'female']
      ]
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alchemy_cms-2.5.0.b9 app/models/alchemy/user.rb
alchemy_cms-2.4.1 app/models/alchemy/user.rb
alchemy_cms-2.5.0.b5 app/models/alchemy/user.rb
alchemy_cms-2.5.0.b2 app/models/alchemy/user.rb
alchemy_cms-2.4.0 app/models/alchemy/user.rb
alchemy_cms-2.4.rc4 app/models/alchemy/user.rb
alchemy_cms-2.4.rc2 app/models/alchemy/user.rb
alchemy_cms-2.4.rc1 app/models/alchemy/user.rb