Sha256: a74e264192f4464bf649ec5b308bdb066e1a82288d1f8183ae5cabd641fef739

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 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 has_role?(role)
    case role
    when :admin
      self.admin?
    when :designer
      self.designer?
    when :content_editor
      self.content_editor?  
    else
      false
    end
  end

  def admin?
    self.admin
  end

  def designer?
    self.designer
  end

  def content_editor?
    self.content_editor
  end

  def locale 
    'en'
  end

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

  def password_required?
    return false if skip_password_validation
    super
  end

  def password_complexity
    # Regexp extracted from https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
    return 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

4 entries across 4 versions & 1 rubygems

Version Path
trusty-cms-3.8.4 app/models/user.rb
trusty-cms-3.8.3 app/models/user.rb
trusty-cms-3.8.2 app/models/user.rb
trusty-cms-3.8.1 app/models/user.rb