Noah
400a256ec8
* Add "Site Gallery" page showing all public+gallery member photos. * Add "Certification Required" decorator for gallery and other main pages. * Add the Certification Photo workflow: * Users have a checklist on their dashboard to upload a profile pic and post a certification selfie (two requirements) * Admins notified by email when a new certification pic comes in. * Admin can reject (w/ comment) or approve the pic. * Users can re-upload or delete their pic at the cost of losing certification status if they make any such changes. * Users are emailed when their photo is either approved or rejected. * User Preferences: can now save the explicit pref to your account. * Explicit photos on user pages and site gallery are hidden if the current user hasn't opted-in (user can always see their own explicit photos regardless of the setting) * If a user is viewing a member gallery and explicit pics are hidden, a count of the number of explicit pics is shown to inform the user that more DO exist, they just don't see them. The site gallery does not do this and simply hides explicit photos.
102 lines
2.7 KiB
Go
102 lines
2.7 KiB
Go
package account
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/config"
|
|
"git.kirsle.net/apps/gosocial/pkg/session"
|
|
"git.kirsle.net/apps/gosocial/pkg/templates"
|
|
"git.kirsle.net/apps/gosocial/pkg/utility"
|
|
)
|
|
|
|
// User settings page. (/settings).
|
|
func Settings() http.HandlerFunc {
|
|
tmpl := templates.Must("account/settings.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
vars := map[string]interface{}{
|
|
"Enum": config.ProfileEnums,
|
|
}
|
|
|
|
// Load the current user in case of updates.
|
|
user, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't get CurrentUser: %s", err)
|
|
templates.Redirect(w, r.URL.Path)
|
|
return
|
|
}
|
|
|
|
// Are we POSTing?
|
|
if r.Method == http.MethodPost {
|
|
intent := r.PostFormValue("intent")
|
|
switch intent {
|
|
case "profile":
|
|
// Setting profile values.
|
|
var (
|
|
displayName = r.PostFormValue("display_name")
|
|
dob = r.PostFormValue("dob")
|
|
)
|
|
|
|
// Set user attributes.
|
|
user.Name = &displayName
|
|
if len(dob) > 0 {
|
|
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)
|
|
} else {
|
|
// Validate birthdate is at least age 18.
|
|
if utility.Age(birthdate) < 18 {
|
|
session.FlashError(w, r, "Invalid birthdate: you must be at least 18 years old to use this site.")
|
|
templates.Redirect(w, r.URL.Path)
|
|
return
|
|
}
|
|
user.Birthdate = birthdate
|
|
}
|
|
} else {
|
|
user.Birthdate = time.Time{}
|
|
}
|
|
|
|
// Set profile attributes.
|
|
for _, attr := range config.ProfileFields {
|
|
user.SetProfileField(attr, r.PostFormValue(attr))
|
|
}
|
|
|
|
// "Looking For" checkbox list.
|
|
if hereFor, ok := r.PostForm["here_for"]; ok {
|
|
user.SetProfileField("here_for", strings.Join(hereFor, ","))
|
|
}
|
|
|
|
if err := user.Save(); err != nil {
|
|
session.FlashError(w, r, "Failed to save user to database: %s", err)
|
|
}
|
|
|
|
session.Flash(w, r, "Profile settings updated!")
|
|
case "preferences":
|
|
var (
|
|
explicit = r.PostFormValue("explicit") == "true"
|
|
)
|
|
|
|
user.Explicit = explicit
|
|
|
|
if err := user.Save(); err != nil {
|
|
session.FlashError(w, r, "Failed to save user to database: %s", err)
|
|
}
|
|
|
|
session.Flash(w, r, "Website preferences updated!")
|
|
case "settings":
|
|
fallthrough
|
|
default:
|
|
session.FlashError(w, r, "Unknown POST intent value. Please try again.")
|
|
}
|
|
|
|
templates.Redirect(w, r.URL.Path)
|
|
return
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|