Sha256: 905b3aa866b66ba392f2ee2437d19425ffc14c5923658d572ae0beb4df0af657

Contents?: true

Size: 803 Bytes

Versions: 17

Compression:

Stored size: 803 Bytes

Contents

module Ecom
  module Core
    class User < ApplicationRecord
      has_secure_password

      has_and_belongs_to_many :user_roles, join_table: 'ecom_core_users_user_roles'

      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
      validates :first_name, :last_name, :active, presence: true
      validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }
      validates :password, presence: true, length: { minimum: 6 }, confirmation: true, if: :password

      scope :active, -> { where(active: true) }

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

      def roles_for_module(code)
        user_roles.joins(:application_module).where('ecom_core_application_modules.code = ?', code)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ecom_core-1.1.17 app/models/ecom/core/user.rb
ecom_core-1.1.16 app/models/ecom/core/user.rb
ecom_core-1.1.15 app/models/ecom/core/user.rb
ecom_core-1.1.14 app/models/ecom/core/user.rb
ecom_core-1.1.13 app/models/ecom/core/user.rb
ecom_core-1.1.12 app/models/ecom/core/user.rb
ecom_core-1.1.11 app/models/ecom/core/user.rb
ecom_core-1.1.10 app/models/ecom/core/user.rb
ecom_core-1.1.9 app/models/ecom/core/user.rb
ecom_core-1.1.8 app/models/ecom/core/user.rb
ecom_core-1.1.7 app/models/ecom/core/user.rb
ecom_core-1.1.6 app/models/ecom/core/user.rb
ecom_core-1.1.5 app/models/ecom/core/user.rb
ecom_core-1.1.4 app/models/ecom/core/user.rb
ecom_core-1.1.3 app/models/ecom/core/user.rb
ecom_core-1.1.2 app/models/ecom/core/user.rb
ecom_core-1.1.1 app/models/ecom/core/user.rb