Merge branch 'master' into amiedes-api-dev-PRs-2

This commit is contained in:
kikito
2017-06-14 09:58:17 +02:00
39 changed files with 207 additions and 115 deletions

View File

@@ -3,7 +3,8 @@ class User < ActiveRecord::Base
include Verification
devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable,
:trackable, :validatable, :omniauthable, :async, :password_expirable, :secure_validatable
:trackable, :validatable, :omniauthable, :async, :password_expirable, :secure_validatable,
authentication_keys: [:login]
acts_as_voter
acts_as_paranoid column: :hidden_at
@@ -50,6 +51,7 @@ class User < ActiveRecord::Base
attr_accessor :skip_password_validation
attr_accessor :use_redeemable_code
attr_accessor :login
scope :administrators, -> { joins(:administrators) }
scope :moderators, -> { joins(:moderator) }
@@ -301,6 +303,14 @@ class User < ActiveRecord::Base
public_activity? ? comments : User.none
end
# overwritting of Devise method to allow login using email OR username
def self.find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup
login = conditions.delete(:login)
where(conditions.to_hash).where(["lower(email) = ?", login.downcase]).first ||
where(conditions.to_hash).where(["username = ?", login]).first
end
private
def clean_document_number