class CPanelController < ApplicationController
  layout "cpanel"
  helper_method :current_cpanel_user

  def is_user_authorized?
    redirect_to :cpanel_login if current_cpanel_user.nil?
  end

  def create_cpanel_session(user=nil)
    if !user.nil? and current_cpanel_user.nil?
      session[:cpanel_user_id] = user.id
    end
  end

  def destroy_cpanel_session
    session.delete(:cpanel_user_id)
  end

  def current_cpanel_user
    @current_cpanel_user = CPanelUser.find(session[:cpanel_user_id]) rescue nil
  end
end