Demo mod: Secure kolačići i blokada TOTP aktivacije
- Secure flag na kolačićima se postavlja i u demo modu (HTTPS kroz Caddy) - Podešavanje 2FA je blokirano u demo modu — handler odbija zahtev, a šablon sakriva dugme i prikazuje obaveštenje
This commit is contained in:
@@ -418,6 +418,12 @@ func (h *Handler) AdminTotpPokreni(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if h.JelDemo {
|
||||||
|
middleware.SetFlash(w, r, h.DB, "greska", "Podešavanje 2FA nije dostupno u demo modu.")
|
||||||
|
http.Redirect(w, r, "/admin/profil", http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
podesavanja, _ := sqlite.DohvatiSvaPodesavanja(r.Context(), h.DB)
|
||||||
totp, err := auth.GenerisuTotpTajnu(k.KorisnickoIme, podesavanja["naziv_firme"])
|
totp, err := auth.GenerisuTotpTajnu(k.KorisnickoIme, podesavanja["naziv_firme"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func (h *Handler) Dashboard(w http.ResponseWriter, r *http.Request) {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ func (h *Handler) Odjava(w http.ResponseWriter, r *http.Request) {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
Expires: time.Unix(0, 0),
|
Expires: time.Unix(0, 0),
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
})
|
})
|
||||||
http.Redirect(w, r, "/prijava", http.StatusSeeOther)
|
http.Redirect(w, r, "/prijava", http.StatusSeeOther)
|
||||||
@@ -318,7 +318,7 @@ func napraviKolacic(token string, istice time.Time) *http.Cookie {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
Expires: istice,
|
Expires: istice,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
SameSite: http.SameSiteStrictMode,
|
SameSite: http.SameSiteStrictMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func RequireAuth(db *sql.DB, totpKljuc []byte) func(http.Handler) http.Handler {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
Expires: time.Unix(0, 0),
|
Expires: time.Unix(0, 0),
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
})
|
})
|
||||||
http.Redirect(w, r, "/prijava", http.StatusSeeOther)
|
http.Redirect(w, r, "/prijava", http.StatusSeeOther)
|
||||||
@@ -157,7 +157,7 @@ func postaviFlashGresku(w http.ResponseWriter, poruka string) {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: 60,
|
MaxAge: 60,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func CsrfMiddleware(next http.Handler) http.Handler {
|
|||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: 86400 * 30,
|
MaxAge: 86400 * 30,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: os.Getenv("NTECH_ENV") == "production",
|
Secure: os.Getenv("NTECH_ENV") == "production" || os.Getenv("NTECH_ENV") == "demo",
|
||||||
SameSite: http.SameSiteStrictMode,
|
SameSite: http.SameSiteStrictMode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,9 +97,11 @@
|
|||||||
Status:
|
Status:
|
||||||
<strong>Isključena</strong>
|
<strong>Isključena</strong>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-size: 13px; color: var(--tekst-sporedni)">Preporučujemo uključivanje dvostepene verifikacije.</div>
|
<div style="font-size: 13px; color: var(--tekst-sporedni)">
|
||||||
|
{{if .JelDemo}}Podešavanje 2FA nije dostupno u demo modu.{{else}}Preporučujemo uključivanje dvostepene verifikacije.{{end}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a href="/admin/profil/totp/pokreni" class="btn-primarno">Podesi 2FA</a>
|
{{if not .JelDemo}}<a href="/admin/profil/totp/pokreni" class="btn-primarno">Podesi 2FA</a>{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user