Sha256: 68622777c60d328b548f6bfc549a9fa99a08ea45be2bb2b1da6904c60e89653f

Contents?: true

Size: 1.31 KB

Versions: 51

Compression:

Stored size: 1.31 KB

Contents

class User < ActiveRecord::Base
  has_many :pages, foreign_key: :created_by_id
  self.table_name = 'admins'

  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  alias_attribute :created_by_id, :id

  attr_accessor :skip_password_validation

  validate :password_complexity

  # Default Order
  default_scope { order('last_name') }

  # Associations
  belongs_to :created_by, class_name: 'User'
  belongs_to :updated_by, class_name: 'User'

  def role?(role)
    case role
    when :admin
      admin?
    when :designer
      designer?
    when :content_editor
      content_editor?
    else
      false
    end
  end

  def admin?
    admin
  end

  def designer?
    designer
  end

  def content_editor?
    content_editor
  end

  def locale
    'en'
  end

  def name
    "#{first_name} #{last_name}"
  end

  def password_required?
    return false if skip_password_validation

    super
  end

  def password_complexity
    return false if password.blank? || password =~ /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,70}$/

    errors.add :password, 'Complexity requirement not met. Length should be 12 characters and include: 1 uppercase, 1 lowercase, 1 digit and 1 special character.'
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
trusty-cms-6.0.4 app/models/user.rb
trusty-cms-6.0.3 app/models/user.rb
trusty-cms-6.0.2 app/models/user.rb
trusty-cms-6.0.1 app/models/user.rb
trusty-cms-5.6.1 app/models/user.rb
trusty-cms-6.0.0 app/models/user.rb
trusty-cms-5.6.0 app/models/user.rb
trusty-cms-5.5.9 app/models/user.rb
trusty-cms-5.5.8 app/models/user.rb
trusty-cms-5.5.7 app/models/user.rb
trusty-cms-5.5.6 app/models/user.rb
trusty-cms-5.5.5.1 app/models/user.rb
trusty-cms-5.5.1 app/models/user.rb
trusty-cms-5.5 app/models/user.rb
trusty-cms-5.4.4 app/models/user.rb
trusty-cms-5.4.3 app/models/user.rb
trusty-cms-5.4.2 app/models/user.rb
trusty-cms-5.4.1 app/models/user.rb
trusty-cms-5.4.0 app/models/user.rb
trusty-cms-5.3.9 app/models/user.rb