diff --git a/assets/templates/guest.tmpl b/assets/templates/guest.tmpl new file mode 100644 index 0000000..ef15439 --- /dev/null +++ b/assets/templates/guest.tmpl @@ -0,0 +1,24 @@ +{{define "guest"}} + + + + BrainMinder + + + + + + + {{block "page:meta" . }} + {{ + end + }} + + + Title +
+
{{template "page:content" .}}
+
+ + +{{ end }} diff --git a/assets/templates/items/sharing_elapsed.tmpl b/assets/templates/items/sharing_elapsed.tmpl new file mode 100644 index 0000000..e14542e --- /dev/null +++ b/assets/templates/items/sharing_elapsed.tmpl @@ -0,0 +1,3 @@ +{{define "page:content"}} +Sharing elapsed +{{end}} diff --git a/cmd/web/items_handlers.go b/cmd/web/items_handlers.go index 37502b5..8c4fcfe 100644 --- a/cmd/web/items_handlers.go +++ b/cmd/web/items_handlers.go @@ -7,6 +7,7 @@ import ( "net/http" "strconv" "strings" + "time" "brainminder.speedtech.it/internal/request" "brainminder.speedtech.it/internal/response" @@ -1139,7 +1140,29 @@ func (app *application) itemShared(w http.ResponseWriter, r *http.Request) { app.serverError(w, r, err) } } else { - //Check dates + itemValidTimeRange := true + currentDateTime := time.Now() + if strings.TrimSpace(itemShare.StartDatetime) != "" { + startDateTime, _ := time.Parse(time.RFC3339, itemShare.StartDatetime+":00Z") + if currentDateTime.Before(startDateTime) { + itemValidTimeRange = false + } + } + if strings.TrimSpace(itemShare.EndDatetime) != "" { + endDateTime, _ := time.Parse(time.RFC3339, itemShare.EndDatetime+":00Z") + if currentDateTime.After(endDateTime) { + itemValidTimeRange = false + } + } + + if !itemValidTimeRange { + err := response.GuestPage(w, http.StatusOK, data, []string{"items/sharing_elapsed.tmpl"}) + if err != nil { + app.serverError(w, r, err) + } + return + } + //Does it need a password ? switch r.Method { case http.MethodGet: @@ -1149,6 +1172,8 @@ func (app *application) itemShared(w http.ResponseWriter, r *http.Request) { app.serverError(w, r, err) } case http.MethodPost: + //Check session token + //Check permission_edit } } } diff --git a/internal/response/templates.go b/internal/response/templates.go index 26e487e..bb61b93 100644 --- a/internal/response/templates.go +++ b/internal/response/templates.go @@ -53,7 +53,7 @@ func Fragment(pagePaths []string, templateName string, data any) (*bytes.Buffer, } func GuestPage(w http.ResponseWriter, status int, data any, pagePaths []string, templateNames ...string) error { - templateName := "full" + templateName := "guest" if len(templateNames) > 0 { templateName = templateNames[0]