with this change the time calculations for pdf reports should be better line with the reports send as "week_report"
35 lines
908 B
Go
35 lines
908 B
Go
package helper
|
|
|
|
// web helpers to either set Cross Origin Request Security or block all requests without a user
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/alexedwards/scs/v2"
|
|
)
|
|
|
|
// setting cors, important for later frontend use
|
|
//
|
|
// in DEBUG == "true" everything is set to "*" so that no cors errors will be happen
|
|
func SetCors(w http.ResponseWriter) {
|
|
if os.Getenv("NO_CORS") == "true" {
|
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
w.Header().Set("Access-Control-Allow-Methods", "*")
|
|
w.Header().Set("Access-Control-Allow-Headers", "*")
|
|
// log.Println("Setting cors to *")
|
|
}
|
|
}
|
|
|
|
func RequiresLogin(session *scs.SessionManager, w http.ResponseWriter, r *http.Request) {
|
|
r = r.WithContext(context.WithValue(r.Context(), "session", session))
|
|
if IsDebug() {
|
|
return
|
|
}
|
|
if session.Exists(r.Context(), "user") {
|
|
return
|
|
}
|
|
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
|
}
|