Sha256: 74fa7e6a6193f1a9cc9d8c8ce0e8bdc73f8a829cd9f12a1f981e8b57651e6da3

Contents?: true

Size: 1.26 KB

Versions: 34

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 rescue 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

34 entries across 34 versions & 1 rubygems

Version Path
thecore_ui_commons-3.0.10 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.9 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.8 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.7 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.6 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.5 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.4 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.3 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-3.0.0 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.5.2 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.5.1 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.5.0 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.10 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.9 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.8 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.7 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.6 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.5 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.4 lib/concerns/thecore_ui_commons_user.rb
thecore_ui_commons-2.4.3 lib/concerns/thecore_ui_commons_user.rb