From 3543dd3e42fb1f9468ff0416fa0715dca58c473e Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Mon, 11 Sep 2023 19:24:09 -0700 Subject: [PATCH] Allow updating birthdate, with admin report --- pkg/controller/account/settings.go | 27 +++++++++++++++++++++++---- web/templates/account/settings.html | 6 +++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/controller/account/settings.go b/pkg/controller/account/settings.go index 8f9c11e..ef3a233 100644 --- a/pkg/controller/account/settings.go +++ b/pkg/controller/account/settings.go @@ -77,12 +77,31 @@ func Settings() http.HandlerFunc { return } - // The user isn't allowed to change it on their own, even if they edit the form to remove the readonly value. + // If the user changes their birthdate, notify the admin. if !user.Birthdate.IsZero() && user.Birthdate.Format("2006-01-02") != dob { - session.FlashError(w, r, "Please contact support if you want to change your birthdate.") - } else { - user.Birthdate = birthdate + // Create an admin Feedback model. + fb := &models.Feedback{ + Intent: "report", + Subject: "report.dob", + UserID: user.ID, + TableName: "users", + TableID: user.ID, + Message: fmt.Sprintf( + "A user has modified their birthdate on their profile page!\n\n"+ + "* Original: %s (age %d)\n* Updated: %s (age %d)", + user.Birthdate, utility.Age(user.Birthdate), + birthdate, utility.Age(birthdate), + ), + } + + // Save the feedback. + if err := models.CreateFeedback(fb); err != nil { + log.Error("Couldn't save feedback from user updating their DOB: %s", err) + } } + + // Work around DST issues: set the hour to noon. + user.Birthdate = birthdate.Add(12 * time.Hour) } // Set profile attributes. diff --git a/web/templates/account/settings.html b/web/templates/account/settings.html index 274a2f6..87720e4 100644 --- a/web/templates/account/settings.html +++ b/web/templates/account/settings.html @@ -73,12 +73,12 @@ id="dob" name="dob" value="{{if not $User.Birthdate.IsZero}}{{$User.Birthdate.Format "2006-01-02"}}{{end}}" - required - {{if not $User.Birthdate.IsZero}}readonly{{end}}> + required>

Used to show your age on your profile. {{if not $User.Birthdate.IsZero}} - If you entered a wrong birthdate, contact support to change it. + If you entered a wrong birthdate, you can change it here. Note that all birthdate + changes will notify the admin, so don't mess around or behave dishonestly. {{end}}