Guest User

Untitled

a guest
Mar 10th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2.  
  3. # Include default devise modules. Others available are:
  4. # :confirmable, :lockable, :timeoutable and :omniauthable
  5. devise :database_authenticatable, :registerable,
  6. :recoverable, :rememberable, :trackable, :validatable,
  7. :omniauthable
  8.  
  9. before_save { self.email = email.downcase }
  10. validates :fullname, presence: true, length: {maximum: 50}
  11. VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  12. validates :email, presence: true, length: { maximum: 255 },
  13. format: { with: VALID_EMAIL_REGEX },
  14. uniqueness: { case_sensitive: false }
  15.  
  16.  
  17.  
  18. has_many :nannies
  19. has_many :nannymizers
  20. has_many :bookings
  21. has_many :reviews
  22.  
  23. def self.from_omniauth(auth)
  24. user = User.where(email: auth.info.email).first
  25.  
  26. if user
  27. return user
  28. else
  29. where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  30. user.fullname = auth.info.name
  31. user.provider = auth.provider
  32. user.uid = auth.uid
  33. user.email = auth.info.email
  34. user.password = Devise.friendly_token[0,20]
  35. end
  36. end
  37. end
  38.  
  39. end
Add Comment
Please, Sign In to add comment