mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-27 04:35:16 +01:00
Updates for checking cookie status.
This commit is contained in:
parent
e6b5714f7d
commit
0f553aa4e2
@ -42,10 +42,12 @@ var mappingLangNames map[string]string
|
|||||||
func (b *BaseController) Prepare() {
|
func (b *BaseController) Prepare() {
|
||||||
|
|
||||||
var lang string
|
var lang string
|
||||||
|
var langHasChanged bool
|
||||||
|
|
||||||
langRequest := b.GetString("lang")
|
langRequest := b.GetString("lang")
|
||||||
if langRequest != "" {
|
if langRequest != "" {
|
||||||
lang = langRequest
|
lang = langRequest
|
||||||
|
langHasChanged = true
|
||||||
} else {
|
} else {
|
||||||
langCookie, err := b.Ctx.Request.Cookie("language")
|
langCookie, err := b.Ctx.Request.Cookie("language")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -53,38 +55,31 @@ func (b *BaseController) Prepare() {
|
|||||||
}
|
}
|
||||||
if langCookie != nil {
|
if langCookie != nil {
|
||||||
lang = langCookie.Value
|
lang = langCookie.Value
|
||||||
}
|
} else {
|
||||||
if lang == "" {
|
al := b.Ctx.Request.Header.Get("Accept-Language")
|
||||||
sessionLang := b.GetSession("lang")
|
if len(al) > 4 {
|
||||||
if sessionLang != nil {
|
al = al[:5] // Only compare first 5 letters.
|
||||||
b.SetSession("lang", lang)
|
if i18n.IsExist(al) {
|
||||||
lang = sessionLang.(string)
|
lang = al
|
||||||
} else {
|
|
||||||
al := b.Ctx.Request.Header.Get("Accept-Language")
|
|
||||||
if len(al) > 4 {
|
|
||||||
al = al[:5] // Only compare first 5 letters.
|
|
||||||
if i18n.IsExist(al) {
|
|
||||||
lang = al
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
langHasChanged = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, exist := supportLanguages[lang]; !exist { //Check if support the request language.
|
if langHasChanged {
|
||||||
lang = defaultLang //Set default language if not supported.
|
if _, exist := supportLanguages[lang]; !exist { //Check if support the request language.
|
||||||
|
lang = defaultLang //Set default language if not supported.
|
||||||
|
}
|
||||||
|
cookies := &http.Cookie{
|
||||||
|
Name: "language",
|
||||||
|
Value: lang,
|
||||||
|
HttpOnly: true,
|
||||||
|
Domain: "/",
|
||||||
|
}
|
||||||
|
http.SetCookie(b.Ctx.ResponseWriter, cookies)
|
||||||
}
|
}
|
||||||
|
|
||||||
cookies := &http.Cookie{
|
|
||||||
Name: "language",
|
|
||||||
Value: lang,
|
|
||||||
HttpOnly: true,
|
|
||||||
Domain: "/",
|
|
||||||
}
|
|
||||||
http.SetCookie(b.Ctx.ResponseWriter, cookies)
|
|
||||||
|
|
||||||
b.SetSession("lang", lang)
|
|
||||||
|
|
||||||
curLang := langType{
|
curLang := langType{
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- Collect the nav links, forms, and other content for toggling -->
|
<!-- Collect the nav links, forms, and other content for toggling -->
|
||||||
<div class="collapse navbar-collapse" id="bs-harbor-navbar-collapse-1">
|
<div class="collapse navbar-collapse" id="bs-harbor-navbar-collapse-1">
|
||||||
<optional-menu version="dev" language="{{ .Lang }}" login-status="//vm.loginStatus//"></optional-menu>
|
<optional-menu version="{{.Version}}" language="{{.Lang}}" login-status="//vm.loginStatus//"></optional-menu>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li>
|
<li>
|
||||||
<navigation-header></navigation-header>
|
<navigation-header></navigation-header>
|
||||||
|
Loading…
Reference in New Issue
Block a user