# frozen_string_literal: true class SettingsController < ApplicationController skip_authorization_check BOOLEAN_COOKIES = [:serve_hidpi, :serve_webm, :webm, :show_comments] VALUE_COOKIES = [:locale] def edit @title = 'Content Settings' end def update set_cookies if current_user.nil? redirect_to edit_settings_path, notice: 'Your settings have been saved!' return end current_user.clear_recent_filters! if params[:clear_recent_filters] if current_user.update(params.require(:user).permit(User::ALLOWED_PARAMETERS)) redirect_to edit_settings_path, notice: 'Your settings have been saved!' else flash[:error] = 'Your settings could not be saved!' render action: 'edit' end end private # store browser-level settings in cookies. this can probably be cleaned up to use a list instead of a map at some point. def set_cookies BOOLEAN_COOKIES.each do |cookie| cookies[cookie] = { value: (params[cookie] == '1'), expires: 25.years.from_now, httponly: false } end VALUE_COOKIES.each do |cookie| cookies[cookie] = { value: params[cookie], expires: 25.years.from_now, httponly: false } end end end