Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. # Include default devise modules. Others available are:
  3. # :confirmable, :lockable, :timeoutable and :omniauthable
  4. devise :database_authenticatable, :registerable,
  5. :recoverable, :rememberable, :trackable, :validatable
  6.  
  7. attr_accessor :signin
  8. validates :username, :uniqueness => {:case_sensitive => false}
  9.  
  10. def self.find_first_by_auth_conditions(warden_conditions)
  11. puts warden_conditions
  12. conditions = warden_conditions.dup
  13. where(conditions).where(["lower(username) = :value OR
  14. lower(email)= :value", { :value => signin.downcase }]).first
  15. end
  16.  
  17. end
  18.  
  19. def self.find_first_by_auth_conditions(warden_conditions)
  20. conditions = warden_conditions.dup
  21. if login = conditions.delete(:login)
  22. if login.start_with?('+')
  23. where(["phone = :value AND phone_confirm = :phone_confirm", { value: login.downcase, phone_confirm: true }]).first
  24. else
  25. where(["lower(email) = :value", { value: login.downcase }]).first
  26. end
  27. else
  28. where(conditions).first
  29. end
  30. end
  31.  
  32. scope :warden_stuff -> { |conditions| where(conditions) } # which can be omitted
  33. scope :user_stuff -> do |user|
  34. where(["lower(username) = :value OR lower(email)= :value",
  35. { :value => user.downcase }])
  36. end
  37.  
  38. def self.find_first_by_auth_conditions(warden_conditions, user)
  39. warden_stuff(warden_conditions).user_stuff(user).first
  40. # or where(warden_conditions).user_stuff(user).first
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement