Sha256: f7a891337e3451cc1baf15afd9c32a609290596d5d973438cefdaa9e74c13755

Contents?: true

Size: 951 Bytes

Versions: 28

Compression:

Stored size: 951 Bytes

Contents

class User < ActiveRecord::Base
  include Authorizable
  # Include default devise modules. Others available are:
  # :registerable, :confirmable, :lockable and :omniauthable

  # Virtual attribute for authenticating by either username or email
  attr_accessor :login

  devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,
         :timeoutable, :omniauthable

  validates :username, presence: true, uniqueness: { scope: :provider, case_sensitive: false }

  def display_name
    fullname.presence || username
  end

  # Devise method overridden to allow sign in with email or username
  def self.find_for_database_authentication(warden_conditions)
    conditions = warden_conditions.dup
    login = conditions.delete(:login)
    if login
      where(conditions).where(['lower(username) = :value OR lower(email) = :value', { value: login.downcase }]).first
    else
      where(conditions).first
    end
  end

end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
chaltron-0.2.11 app/models/user.rb
chaltron-1.0.10 app/models/user.rb
chaltron-0.2.10 app/models/user.rb
chaltron-1.0.9 app/models/user.rb
chaltron-1.0.8 app/models/user.rb
chaltron-1.0.7 app/models/user.rb
chaltron-0.2.9 app/models/user.rb
chaltron-1.0.6 app/models/user.rb
chaltron-1.0.5 app/models/user.rb
chaltron-1.0.4 app/models/user.rb
chaltron-0.2.8 app/models/user.rb
chaltron-0.2.7 app/models/user.rb
chaltron-1.0.3 app/models/user.rb
chaltron-1.0.2 app/models/user.rb
chaltron-1.0.1 app/models/user.rb
chaltron-0.2.6 app/models/user.rb
chaltron-1.0.0 app/models/user.rb
chaltron-0.2.5 app/models/user.rb
chaltron-0.2.4 app/models/user.rb
chaltron-0.2.3 app/models/user.rb