web_app_controller_concern.rb 890 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. module WebAppControllerConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. vary_by 'Accept, Accept-Language, Cookie'
  6. before_action :redirect_unauthenticated_to_permalinks!
  7. before_action :set_app_body_class
  8. end
  9. def skip_csrf_meta_tags?
  10. !(ENV['ONE_CLICK_SSO_LOGIN'] == 'true' && ENV['OMNIAUTH_ONLY'] == 'true' && Devise.omniauth_providers.length == 1) && current_user.nil?
  11. end
  12. def set_app_body_class
  13. @body_classes = 'app-body'
  14. end
  15. def redirect_unauthenticated_to_permalinks!
  16. return if user_signed_in? && current_account.moved_to_account_id.nil?
  17. redirect_path = PermalinkRedirector.new(request.path).redirect_path
  18. return if redirect_path.blank?
  19. expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in?
  20. redirect_to(redirect_path)
  21. end
  22. end