Guest User

Untitled

a guest
Aug 4th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. validates :username, presence: true, length: {maximum: 255}, uniqueness: { case_sensitive: false }, format: { with: /A[a-zA-Z0-9]*z/, :multiline => true, message: "may only contain letters and numbers." }
  2.  
  3. has_many :rooms
  4. has_many :reservations
  5. has_many :reviews
  6. validates :username, presence: true, uniqueness: true, case_sensitive: false,
  7. length: { minimum: 8, maximum: 32 }
  8. validates :email, presence: true, length: { minimum: 5, maximum: 50 }
  9. validates_format_of :email, with: /^.+@.+..+$/, on: :create, :multiline => true
  10.  
  11. scope :landlords, -> { where(type: 'Landlord') }
  12. scope :renters, -> { where(type: 'Renter') }
  13.  
  14. def landlord?
  15. self.type == "Landlord"
  16. end
  17.  
  18. def renter?
  19. self.type == "Renter"
  20. end
  21.  
  22. attr_writer :login
  23.  
  24. def login
  25. @login || self.username || self.email
  26. end
  27.  
  28. def self.from_omniauth(auth)
  29. email = auth[:info][:email] || "#{auth[:uid]}@facebook.com"
  30. user = where(email: email).first_or_initialize
  31.  
  32. if user
  33. return user
  34. else
  35. where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  36. user.fullname = auth.info.name
  37. user.provider = auth.provider
  38. user.uid = auth.uid
  39. user.email = auth.info.email
  40. user.image = auth.info.image
  41. user.password = Devise.friendly_token[0,20]
  42. end
  43. end
  44.  
  45. end
Add Comment
Please, Sign In to add comment