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,
- :omniauthable
- before_save { self.email = email.downcase }
- validates :fullname, presence: true, length: {maximum: 50}
- VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
- validates :email, presence: true, length: { maximum: 255 },
- format: { with: VALID_EMAIL_REGEX },
- uniqueness: { case_sensitive: false }
- has_many :nannies
- has_many :nannymizers
- has_many :bookings
- has_many :reviews
- def self.from_omniauth(auth)
- user = User.where(email: auth.info.email).first
- 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.password = Devise.friendly_token[0,20]
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment