From f1d04d1390ac0e755e6ac4778927bf06c86e9ba3 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 15 Dec 2024 15:10:05 +0000 Subject: Refactor user session handling and UI enhancements. Updated logout redirection with a success notice and improved UI feedback on the home page. Enhanced navbar logic to reflect user authentication state, modified page titles, and adjusted access permissions for various controllers. Fixed admin access control for PDF resources index action. --- app/controllers/pages_controller.rb | 2 ++ app/controllers/pdfresources_controller.rb | 2 +- app/controllers/sessions_controller.rb | 2 +- app/views/layouts/_navbar.html.erb | 11 ++++++----- app/views/pages/home.html.erb | 5 +++++ app/views/pages/more_info.html.erb | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 58c0ee7..309fb05 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -1,4 +1,6 @@ class PagesController < ApplicationController + allow_unauthenticated_access only: %i[ home about more_info faq contact terms ] + def home end diff --git a/app/controllers/pdfresources_controller.rb b/app/controllers/pdfresources_controller.rb index a710404..3ea6503 100644 --- a/app/controllers/pdfresources_controller.rb +++ b/app/controllers/pdfresources_controller.rb @@ -1,6 +1,6 @@ class PdfresourcesController < ApplicationController before_action :set_pdfresource, only: %i[ show edit update destroy ] - before_action :require_admin, only: %i[ new create update destroy ] + before_action :require_admin, only: %i[ index new create update destroy ] # GET /pdfresources or /pdfresources.json def index diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 9785c92..185dfeb 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -16,6 +16,6 @@ class SessionsController < ApplicationController def destroy terminate_session - redirect_to new_session_path + redirect_to root_path, notice: "Logged out successfully." end end diff --git a/app/views/layouts/_navbar.html.erb b/app/views/layouts/_navbar.html.erb index af7a0e4..952e291 100644 --- a/app/views/layouts/_navbar.html.erb +++ b/app/views/layouts/_navbar.html.erb @@ -15,16 +15,17 @@ About
  • - Services -
  • -
  • - Pricing + FAQ
  • Contact
  • - <%= link_to "Log out", Current.session, class: "block py-2 px-3", data: { turbo_method: :delete }%> + <% if Current.user %> + <%= link_to "Log out", Current.session, class: "block py-2 px-3", data: { turbo_method: :delete } %> + <% else %> + <%= link_to "Log in", new_session_path, class: "block py-2 px-3" %> + <% end %>
  • diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index 48d6433..e3dba04 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -1,4 +1,9 @@
    + <% if notice.present? %> +
    +

    <%= notice %>

    +
    + <% end %>
    diff --git a/app/views/pages/more_info.html.erb b/app/views/pages/more_info.html.erb index cba5373..9665410 100644 --- a/app/views/pages/more_info.html.erb +++ b/app/views/pages/more_info.html.erb @@ -1,7 +1,7 @@

    - More Information + Benefits of registering now

    -- cgit v1.2.3