- Update menu labels for cities, countries, and regions - Introduce new entities for states and subregions in Admin Panel - Implement admin authentication for weather art generation - Modify application controller to check for admin user - Refactor view to display admin panel based on user permissions - Update routes to include weather art generation action These changes enhance the admin interface for better management of cities and related entities. The new admin checks ensure that only authorized users can generate weather art, improving security and functionality.
82 lines
2.8 KiB
Ruby
82 lines
2.8 KiB
Ruby
class ApplicationController < ActionController::Base
|
|
include SeoConcern
|
|
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
|
before_action :log_browser_info
|
|
# allow_browser versions: :modern
|
|
# allow_browser versions: :modern,
|
|
# patterns: [
|
|
# # 鸿蒙系统相关
|
|
# /OpenHarmony/, # 鸿蒙系统标识
|
|
# /ArkWeb\/[\d.]+/, # 鸿蒙浏览器内核
|
|
# /Mobile HuaweiBrowser/, # 华为浏览器(新格式)
|
|
# /HuaweiBrowser\/[\d.]+/, # 华为浏览器(旧格式)
|
|
#
|
|
# # 夸克浏览器(更宽松的匹配)
|
|
# /Quark[\s\/][\d.]+/, # 匹配 "Quark/7.4.6.681" 或 "Quark 7.4.6.681"
|
|
#
|
|
# /Mobile Safari/,
|
|
# /Chrome\/[\d.]+/,
|
|
# /Quark\/[\d.]+/,
|
|
# /HuaweiBrowser\/[\d.]+/,
|
|
# /MiuiBrowser\/[\d.]+/,
|
|
# /VivoBrowser\/[\d.]+/,
|
|
# /OppoBrowser\/[\d.]+/,
|
|
# /UCBrowser\/[\d.]+/,
|
|
# /QQBrowser\/[\d.]+/,
|
|
# /MicroMessenger\/[\d.]+/,
|
|
# /Alipay/,
|
|
# /BaiduBoxApp/,
|
|
# /baiduboxapp/i,
|
|
# /SogouMobile/,
|
|
# /Weibo/,
|
|
# /DingTalk/,
|
|
# /ToutiaoMicroApp/,
|
|
# /BytedanceWebview/,
|
|
# /ArkWeb/
|
|
# ],
|
|
# on_failure: ->(browser) {
|
|
# Rails.logger.warn <<~BROWSER_INFO
|
|
# Browser Blocked:
|
|
# User Agent: #{browser.ua}
|
|
# Name: #{browser.name}
|
|
# Version: #{browser.version}
|
|
# Platform: #{browser.platform.name}
|
|
# Device: #{browser.device.name}
|
|
# Mobile: #{browser.mobile?}
|
|
# Modern: #{browser.modern?}
|
|
# Bot: #{browser.bot?}
|
|
# BROWSER_INFO
|
|
# }
|
|
before_action :set_locale
|
|
after_action :track_action
|
|
|
|
def log_browser_info
|
|
# 构建详细的浏览器信息
|
|
Rails.logger.debug "User Agent: #{request.user_agent}"
|
|
|
|
# 如果是被拦截的浏览器,记录额外信息
|
|
# unless browser_allowed?
|
|
# Rails.logger.info "User Agent: #{request.user_agent}"
|
|
# end
|
|
end
|
|
|
|
protected
|
|
|
|
def track_action
|
|
ahoy.track "Viewed Application", request.path_parameters
|
|
end
|
|
|
|
def authenticate_admin_user!
|
|
unless current_user&.admin?
|
|
flash[:alert] = "您没有权限访问该页面。"
|
|
redirect_to root_path
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def set_locale
|
|
I18n.locale = params[:locale] || I18n.default_locale
|
|
end
|
|
end
|