class SessionsController < ApplicationController

  def new
    @user = User.new
  end

  def create
    user = User.find_by(username: params[:user][:username])
    if user && user.authenticate(params[:user][:password])
      session[:user_id] = user.id
      redirect_to root_path
    else
      flash[:notice] = "INCORRECT LOGIN CREDENTIALS"
      redirect_to login_path
    end
  end

  def delete
    session[:user_id] = nil
    redirect_to root_path
  end

end
