Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Show message pinned at the bottom of the window warning of cookie usage to comply with EU law (#1506)

* Add global variable to template_test

* Add global variable related to EU cookie law

* Add GetEUCookieFromRequest function that checks if the EU cookie exists (to comply with EU law)

* Add div at bottom of page if no EU cookie set

* add styling in css

* Prevent message from showing up any more than once

* prevent cookie from being erased by resetCookies() function

* Fix wrong function return type

* shorter condition

* Import timeHelper

* Update template_test.go

* remove variable name

* Update template_test.go
Cette révision appartient à :
kilo 2017-09-06 07:55:00 +02:00 révisé par GitHub
Parent 5437b700ff
révision 70a865e49a
6 fichiers modifiés avec 39 ajouts et 3 suppressions

Voir le fichier

@ -12,7 +12,9 @@ a {
text-decoration: none;
}
body, .container, .modtools { min-width: 400px; }
body, .container, .modtools {
min-width: 400px;
}
.header, .pagination {
-webkit-user-select: none;
@ -52,7 +54,7 @@ body {
background-size: contain;
}
.header {
.header, #cookie-warning {
z-index: 3;
position: fixed;
width: 100%;
@ -61,6 +63,15 @@ body {
height: 60px;
border-bottom: 1px solid;
}
.header.content-admin {
height: auto;
}
#cookie-warning {
top: initial;
bottom: 0;
background: hsla(200,90%,56%,0.2);
height: 40px;
}
.container, .modtools {
max-width: 1111px;

Voir le fichier

@ -87,7 +87,7 @@ parseAllDates()
//called if no Commit cookie is set or if the website has a newer commit than the one in cookie
function resetCookies() {
var cookies = document.cookie.split(";")
var excludedCookies = ["mascot", "theme", "theme2", "mascot_url", "lang", "csrf_token", "altColors", "hideAds"]
var excludedCookies = ["mascot", "theme", "theme2", "mascot_url", "lang", "csrf_token", "altColors", "hideAds", "EU_Cookie"]
//Remove all cookies but exclude those in the above array
for (var i = 0; i < cookies.length; i++) {

Voir le fichier

@ -96,6 +96,7 @@
</div>
</footer>
</div>
{{ if !EUCookieLaw }}<div id="cookie-warning">{{ T("cookie_warning") }}</div>{{ end }}
<script type="text/javascript" charset="utf-8">var commitVersion = "{{ Config.Build }}", UserID = {{User.ID}};</script>
<script type="text/javascript" src="/js/query.js?v={{ Config.Version}}{{ Config.Build }}"></script>
<script type="text/javascript" charset="utf-8" src="/js/main.js?v={{ Config.Version }}{{ Config.Build }}" async></script>

Voir le fichier

@ -60,6 +60,7 @@ func Commonvariables(c *gin.Context) jet.VarMap {
variables.Set("User", user)
variables.Set("URL", c.Request.URL)
variables.Set("CsrfToken", token)
variables.Set("EUCookieLaw", publicSettings.GetEUCookieFromRequest(c))
variables.Set("Config", config.Get())
variables.Set("Infos", messages.GetAllInfos())
variables.Set("Errors", messages.GetAllErrors())

Voir le fichier

@ -288,6 +288,7 @@ func mockupCommonvariables(t *testing.T) jet.VarMap {
variables.Set("User", &models.User{})
variables.Set("URL", &url.URL{})
variables.Set("CsrfToken", "xxxxxx")
variables.Set("EUCookieLaw", false)
variables.Set("Config", config.Get())
variables.Set("Infos", make(map[string][]string))
variables.Set("Errors", make(map[string][]string))

Voir le fichier

@ -7,11 +7,13 @@ import (
"path"
"path/filepath"
"strings"
"net/http"
"sort"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/utils/timeHelper"
"github.com/gin-gonic/gin"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/nicksnyder/go-i18n/i18n/language"
@ -237,6 +239,18 @@ func GetMascotURLFromRequest(c *gin.Context) string {
return ""
}
func GetEUCookieFromRequest(c *gin.Context) bool {
_, err := c.Cookie("EU_Cookie")
if err == nil {
return true
//Cookie exists, everything good
}
http.SetCookie(c.Writer, &http.Cookie{Name: "EU_Cookie", Value: "true", Domain: getDomainName(), Path: "/", Expires: timeHelper.FewDaysLater(365)})
return false
//Cookie doesn't exist, we create it to prevent the message from popping up anymore after that and return false
}
func getCurrentUser(c *gin.Context) (*models.User, error) {
if userRetriever == nil {
return &models.User{}, errors.New("failed to get current user: no user retriever set")
@ -294,3 +308,11 @@ func Flag(languageCode string, parent bool) string {
}
return lang.String()
}
func getDomainName() string {
domain := config.Get().Cookies.DomainName
if config.Get().Environment == "DEVELOPMENT" {
domain = ""
}
return domain
}