class User < ActiveRecord::Base

  has_many :recipes, dependent: :nullify
  has_many :ingredients, dependent: :nullify

  has_secure_password

  validates :username, presence: true, uniqueness: { case_sensitive: false }

  def self.authenticate(username, password)
    find_by_username(username).try(:authenticate, password)
  end

  def display_name
    self.full_name.present? ? self.full_name : self.username
  end

end
