Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- # Include default devise modules. Others available are:
- # :confirmable, :lockable, :timeoutable and :omniauthable
- devise :database_authenticatable, :registerable,
- :recoverable, :rememberable, :trackable, :validatable
- attr_accessor :signin
- validates :username, :uniqueness => {:case_sensitive => false}
- def self.find_first_by_auth_conditions(warden_conditions)
- puts warden_conditions
- conditions = warden_conditions.dup
- where(conditions).where(["lower(username) = :value OR
- lower(email)= :value", { :value => signin.downcase }]).first
- end
- end
- def self.find_first_by_auth_conditions(warden_conditions)
- conditions = warden_conditions.dup
- if login = conditions.delete(:login)
- if login.start_with?('+')
- where(["phone = :value AND phone_confirm = :phone_confirm", { value: login.downcase, phone_confirm: true }]).first
- else
- where(["lower(email) = :value", { value: login.downcase }]).first
- end
- else
- where(conditions).first
- end
- end
- scope :warden_stuff -> { |conditions| where(conditions) } # which can be omitted
- scope :user_stuff -> do |user|
- where(["lower(username) = :value OR lower(email)= :value",
- { :value => user.downcase }])
- end
- def self.find_first_by_auth_conditions(warden_conditions, user)
- warden_stuff(warden_conditions).user_stuff(user).first
- # or where(warden_conditions).user_stuff(user).first
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement