From 63be05146d1cd05e03a74e4ffc9a8169f23f3a17 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 27 Mar 2019 11:12:39 -0500 Subject: [PATCH] Fix expire for prefs cookie --- src/invidious.cr | 29 +++++++++++++++++++++++++++-- src/invidious/views/template.ecr | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 98f9bc66..64273a17 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1322,7 +1322,19 @@ post "/preferences" do |env| File.write("config/config.yml", config.to_yaml) end else - env.response.cookies["PREFS"] = preferences + if Kemal.config.ssl || config.https_only + secure = true + else + secure = false + end + + if config.domain + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", domain: "#{config.domain}", value: preferences, expires: Time.now + 2.years, + secure: secure, http_only: true) + else + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", value: preferences, expires: Time.now + 2.years, + secure: secure, http_only: true) + end end env.redirect referer @@ -1341,8 +1353,21 @@ get "/toggle_theme" do |env| else preferences = env.get("preferences").as(Preferences) preferences.dark_mode = !preferences.dark_mode + preferences = preferences.to_json - env.response.cookies["PREFS"] = preferences.to_json + if Kemal.config.ssl || config.https_only + secure = true + else + secure = false + end + + if config.domain + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", domain: "#{config.domain}", value: preferences, expires: Time.now + 2.years, + secure: secure, http_only: true) + else + env.response.cookies["PREFS"] = HTTP::Cookie.new(name: "PREFS", value: preferences, expires: Time.now + 2.years, + secure: secure, http_only: true) + end end env.redirect referer diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr index 35e52dcf..01e9c355 100644 --- a/src/invidious/views/template.ecr +++ b/src/invidious/views/template.ecr @@ -77,7 +77,7 @@ <% else %>
" class="pure-menu-heading"> - <% if env.get?("preferences").try &.as(Preferences).dark_mode %> + <% if env.get("preferences").as(Preferences).dark_mode %> <% else %>