Bugfixes with changing user birthdates
This commit is contained in:
parent
ae8ef83115
commit
a98c218628
|
@ -28,6 +28,12 @@ func AgeGate() http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have already set our age, don't allow changing it.
|
||||||
|
if !user.Birthdate.IsZero() {
|
||||||
|
templates.NotFoundPage(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Are we POSTing?
|
// Are we POSTing?
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -59,7 +59,8 @@ func Settings() http.HandlerFunc {
|
||||||
|
|
||||||
// Set user attributes.
|
// Set user attributes.
|
||||||
user.Name = &displayName
|
user.Name = &displayName
|
||||||
if len(dob) > 0 {
|
|
||||||
|
// Birthdate, now required.
|
||||||
if birthdate, err := time.Parse("2006-01-02", dob); err != nil {
|
if birthdate, err := time.Parse("2006-01-02", dob); err != nil {
|
||||||
session.FlashError(w, r, "Incorrect format for birthdate; should be in yyyy-mm-dd format but got: %s", dob)
|
session.FlashError(w, r, "Incorrect format for birthdate; should be in yyyy-mm-dd format but got: %s", dob)
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,10 +70,13 @@ func Settings() http.HandlerFunc {
|
||||||
templates.Redirect(w, r.URL.Path)
|
templates.Redirect(w, r.URL.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The user isn't allowed to change it on their own, even if they edit the form to remove the readonly value.
|
||||||
|
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
|
user.Birthdate = birthdate
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
user.Birthdate = time.Time{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set profile attributes.
|
// Set profile attributes.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user