class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  validates :password, presence: false, on: :facebook_login

  def self.from_omniauth(auth)
      # emailの提供は必須とする
      user = User.where('email = ?', auth.info.email).first
    if user.blank?
      user = User.new
    end
  user.id   = auth.uid
  user.nickname  = auth.info.name
  user.email = auth.info.email
  # user.icon  = auth.info.image
  user.oauth_token      = auth.credentials.token
  # user.oauth_expires_at = Time.at(auth.credentials.expires_at)
  user
  end
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  has_many :hospis
end
