website/pkg/middleware/public_avatar_consent.go

28 lines
749 B
Go

package middleware
import (
"net/http"
"net/url"
"time"
"code.nonshy.com/nonshy/website/pkg/config"
"code.nonshy.com/nonshy/website/pkg/models"
"code.nonshy.com/nonshy/website/pkg/templates"
)
// PublicAvatarConsent: part of CertificationRequired that enforces the consent page for affected users.
func PublicAvatarConsent(user *models.User, w http.ResponseWriter, r *http.Request) (handled bool) {
// Is the enforcement date live?
if time.Now().Before(config.PublicAvatarEnforcementDate) {
return
}
// If the current user has a non-public avatar and has not consented.
if user.NeedsPublicAvatarConsent() {
templates.Redirect(w, "/settings/public-avatar-consent?next="+url.QueryEscape(r.URL.String()))
return true
}
return
}