blob: da1336875882135871673573e467831b4156bfe0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# 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
|