Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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." }
- has_many :rooms
- has_many :reservations
- has_many :reviews
- validates :username, presence: true, uniqueness: true, case_sensitive: false,
- length: { minimum: 8, maximum: 32 }
- validates :email, presence: true, length: { minimum: 5, maximum: 50 }
- validates_format_of :email, with: /^.+@.+..+$/, on: :create, :multiline => true
- scope :landlords, -> { where(type: 'Landlord') }
- scope :renters, -> { where(type: 'Renter') }
- def landlord?
- self.type == "Landlord"
- end
- def renter?
- self.type == "Renter"
- end
- attr_writer :login
- def login
- @login || self.username || self.email
- end
- def self.from_omniauth(auth)
- email = auth[:info][:email] || "#{auth[:uid]}@facebook.com"
- user = where(email: email).first_or_initialize
- if user
- return user
- else
- where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
- user.fullname = auth.info.name
- user.provider = auth.provider
- user.uid = auth.uid
- user.email = auth.info.email
- user.image = auth.info.image
- user.password = Devise.friendly_token[0,20]
- end
- end
- end
Add Comment
Please, Sign In to add comment