class SessionsController < ApplicationController
  ##
  # Render sign in Screen 
  def new
  end
  
  ##
  # Sign in
  def create
    user = Admin::User.find_by(user_id: params[:session][:user_id].downcase)
    if user && user.authenticate(params[:session][:password])
      # authentication successful, you have to maintain a session at here
      sign_in user
      redirect_to root_url
    else
      flash[:error] = 'Invalid user id/password combination'
      render 'new'
    end
  end
  
  ##
  # Sign out
  def destroy
    sign_out
    redirect_to root_url
  end
end
