2024-06-29 23:44:18 +00:00
|
|
|
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.
|
2024-06-30 03:52:23 +00:00
|
|
|
if user.ProfilePhoto.ID > 0 && user.ProfilePhoto.Visibility != models.PhotoPublic {
|
|
|
|
if user.GetProfileField("public_avatar_consent") == "true" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-29 23:44:18 +00:00
|
|
|
templates.Redirect(w, "/settings/public-avatar-consent?next="+url.QueryEscape(r.URL.String()))
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|