Sha256: fee2fa5a69c05eff688c799dd772892d5bb2d78a9c8cb196c1cbe26e47d1edaf

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

require 'active_support/concern'

module ThecoreUiCommonsUser
    extend ActiveSupport::Concern
    
    included do
        devise :database_authenticatable, :trackable, :validatable, :rememberable, :timeoutable, timeout_in: 30.minutes, authentication_keys: [:login]
        validates :username, uniqueness: { case_sensitive: false }, presence: true, length: { in: 4..15 }
        validates_format_of :username, with: /\A[a-zA-Z0-9]*\z/, on: :create, message: "can only contain letters and digits"
        
        attr_writer :login
        
        def login
            @login || self.username || self.email
        end
        # Use login
        def self.find_first_by_auth_conditions(warden_conditions)
            conditions = warden_conditions.dup
            if login = conditions.delete(:login)
                where(conditions.to_h).where(["lower(username) = :value OR lower(email) = :value", { :value => login.downcase }]).first
            elsif conditions.has_key?(:username) || conditions.has_key?(:email)
                # Case insensitive login
                conditions[:email].downcase! if conditions[:email]
                conditions[:username].downcase! if conditions[:username]
                where(conditions.to_h).first
            end
        end
    end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
thecore_ui_commons-2.2.9 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.8 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.7 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.6 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.5 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.4 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.3 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.1 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.2.0 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.14 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.13 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.12 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.11 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.10 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.1.9 lib/concerns/thecore_ui_commons_user.rb