Sha256: ac9a329a7be47b628dc3e38daed1b87c4347f3bd61749b3e86806fbb998e38a3

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Cas
  class User < ApplicationRecord
    ROLES = %w[admin editor writer].freeze

    before_save { self.email = email.to_s.downcase }
    validates :name, presence: true, length: { maximum: 50 }
    validates :email, presence: true, length: { maximum: 255 },
                           uniqueness: { case_sensitive: false }
    validates :password, presence: true, length: { minimum: 6 }, on: :create, allow_blank: true

    devise :database_authenticatable, #:recoverable,
           :rememberable, :trackable, :validatable

    has_many :contents
    has_many :files, class_name: Cas::MediaFile, as: :attachable

    def self.find_for_database_authentication(warden_conditions)
      conditions = warden_conditions.dup
      sql = where(["lower(login) = :value OR lower(email) = :value", {
        value: conditions[:email].downcase
      }])
      sql.first
    end

    def admin?
      roles.include?("admin")
    end

    def editor?
      roles.include?("editor")
    end

    private

    def email_required?
      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cas-cms-0.1.0 app/models/cas/user.rb