Fix settings page for non-logged in users (#1725)
* Update main.js * delete cookies from any domain before creating them * Update settings.jet.html
Cette révision appartient à :
Parent
fdbf06e610
révision
6a03a75d6b
2 fichiers modifiés avec 15 ajouts et 9 suppressions
|
@ -116,9 +116,7 @@ function resetCookies() {
|
|||
if(domain == hostName) {
|
||||
//only execute if cookie are supposed to be shared between nyaa & sukebei, aka on host name without subdomain
|
||||
var cookieValue = getCookieValue(cookieName)
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
|
||||
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
deleteCookie(cookieName)
|
||||
if(cookieName != "session")
|
||||
document.cookie = cookieName + "=" + cookieValue + ";path=/;expires=" + farFutureString + ";domain=" + domain
|
||||
else document.cookie = cookieName + "=" + cookieValue + ";path=/;expires=" + farFutureString
|
||||
|
@ -127,12 +125,12 @@ function resetCookies() {
|
|||
}
|
||||
continue
|
||||
}
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
|
||||
deleteCookie(cookieName)
|
||||
}
|
||||
|
||||
//Set new version in cookie
|
||||
deleteCookie("commit")
|
||||
deleteCookie("version")
|
||||
document.cookie = "commit=" + commitVersion + ";path=/;expires=" + farFutureString + ";domain=" + domain
|
||||
document.cookie = "version=" + websiteVersion + ";path=/;expires=" + farFutureString + ";domain=" + domain
|
||||
|
||||
|
@ -306,4 +304,11 @@ function getCookieValue(cookieName) {
|
|||
return endPos == -1 ? document.cookie.substring(startPos) : document.cookie.substring(startPos, endPos + startPos)
|
||||
}
|
||||
|
||||
function deleteCookie(cookieName) {
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
document.cookie = cookieName + "=;path=/;expires=Thu, 01 Jan 1970 00:00:00 UTC;"
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + window.location.host
|
||||
document.cookie = cookieName + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;domain=" + domain
|
||||
}
|
||||
|
||||
// @license-end
|
||||
|
|
|
@ -69,8 +69,7 @@
|
|||
<script type="text/javascript">
|
||||
var SaveButton = document.querySelector('form[method="POST"] button[type="submit"]')
|
||||
|
||||
//Golang settings.go controller set cookies for the domain variable in config, if we are currently on a mirror this will mean that the cookie will not be set for the right website
|
||||
|
||||
//Doing this, we avoid having to do a query (which is unneeded for logged-in users) and can make sure that the cookies are set for the right domain name
|
||||
if(UserID == 0)
|
||||
SaveButton.addEventListener("click", function(e) {
|
||||
var formInputs = document.querySelectorAll("form[method='POST'] input"),
|
||||
|
@ -80,13 +79,15 @@
|
|||
for(var i = 0; i < formInputs.length; i++) {
|
||||
var setting = formInputs[i]
|
||||
if(setting.name == "csrf_token") continue
|
||||
deleteCookie(setting.name)
|
||||
document.cookie = setting.name + "=" + setting.value + ";path=/;expires=" + farFutureString + ";domain=" + domain
|
||||
}
|
||||
|
||||
for(var i = 0; i < formSelect.length; i++) {
|
||||
var setting = formSelect[i],
|
||||
selectValues = setting.querySelectorAll("option")
|
||||
selectValues = setting.querySelectorAll("option")
|
||||
|
||||
deleteCookie(setting.name)
|
||||
document.cookie = setting.name + "=" + selectValues[setting.selectedIndex].value + ";path=/;expires=" + farFutureString + ";domain=" + domain
|
||||
}
|
||||
|
||||
|
|
Référencer dans un nouveau ticket