From 5b5dde3364cad2487a67061026b60582ad0d6cc4 Mon Sep 17 00:00:00 2001 From: Sergio-e <33036058+Sergio-e@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:57:06 -0600 Subject: [PATCH] Handle invalid auth token --- app/controllers/application_controller.rb | 10 +++++++++- config/locales/en.yml | 2 +- lib/tasks/db.rake | 20 -------------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2c2fbf3c..6165f434 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,14 +7,22 @@ class ApplicationController < ActionController::Base helper_method :current_profile, :current_conference, :vapid_public_key + rescue_from ActionController::InvalidAuthenticityToken, + with: :after_invalid_authenticity_token + private def current_profile = current_user&.profile - # TODO: Must change after implementing multi-conference support def current_conference = Conference.last def vapid_public_key Base64.urlsafe_decode64(ENV["VAPID_PUBLIC_KEY"]).bytes.to_json end + + def after_invalid_authenticity_token + path_to_redirect = request.referer + path_to_redirect ||= user_signed_in? ? sessions_path : new_user_session_path + redirect_to path_to_redirect, alert: t("authorization.invalid_auth_token") + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 13af4ee5..eb685092 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -46,6 +46,7 @@ en: submit: "Apply" authorization: unauthorized: "You are not authorized to access this page." + invalid_auth_token: "Your request has expired. Please try again." session_mailer: reminder: subject: "This session is starting soon" @@ -66,4 +67,3 @@ en: one: "1month" other: "%{count}months" x_months: "%{count}months" - diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 3734f7f4..f9327ecc 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -1,6 +1,5 @@ namespace :db do desc "Loading Rails World 2024 conference data." - task :rails_world_2024_seed, [:start_date] => :environment do |t, args| start_date = args[:start_date].present? ? Date.parse(args[:start_date]) : Date.new(2024, 9, 26) month = start_date.month @@ -25,43 +24,24 @@ namespace :db do # Create Tags community = Tag.find_or_create_by!(name: "Community") - security = Tag.find_or_create_by!(name: "Security") - rails_8 = Tag.find_or_create_by!(name: "Rails 8") - productivity = Tag.find_or_create_by!(name: "Productivity") - tools = Tag.find_or_create_by!(name: "Tools") - developer_experience = Tag.find_or_create_by!(name: "Developer Experience") - deployment = Tag.find_or_create_by!(name: "Deployment") - performance = Tag.find_or_create_by!(name: "Performance") - storage_solutions = Tag.find_or_create_by!(name: "Storage Solutions") - refactoring = Tag.find_or_create_by!(name: "Refactoring") - database = Tag.find_or_create_by!(name: "Database") - hotwire = Tag.find_or_create_by!(name: "Hotwire") - ai = Tag.find_or_create_by!(name: "AI") - integrations = Tag.find_or_create_by!(name: "Integrations") - testing = Tag.find_or_create_by!(name: "Testing") - best_practices = Tag.find_or_create_by!(name: "Best Practices") - pwa = Tag.find_or_create_by!(name: "PWA") - insights = Tag.find_or_create_by!(name: "Insights") - background_jobs = Tag.find_or_create_by!(name: "Background Jobs") - rails_internals = Tag.find_or_create_by!(name: "Rails Internals") # Create Speakers