Noah
6c91c67c97
* Users who set their Profile Picture to "friends only" or "private" can have their avatar be private all over the website to users who are not their friends or not granted access. * Users who are not your friends see a yellow placeholder avatar, and users not granted access to a private Profile Pic sees a purple avatar. * Admin users see these same placeholder avatars most places too (on search, forums, comments, etc.) if the user did not friend or grant the admin. But admins ALWAYS see it on their Profile Page directly, for ability to moderate. * Fix marking Notifications as read: clicking the link in an unread notification now will wait on the ajax request to finish before allowing the redirect. * Update the FAQ
110 lines
2.5 KiB
Go
110 lines
2.5 KiB
Go
package account
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"code.nonshy.com/nonshy/website/pkg/config"
|
|
"code.nonshy.com/nonshy/website/pkg/models"
|
|
"code.nonshy.com/nonshy/website/pkg/session"
|
|
"code.nonshy.com/nonshy/website/pkg/templates"
|
|
)
|
|
|
|
// Search controller.
|
|
func Search() http.HandlerFunc {
|
|
tmpl := templates.Must("account/search.html")
|
|
|
|
// Whitelist for ordering options.
|
|
var sortWhitelist = []string{
|
|
"last_login_at desc",
|
|
"created_at desc",
|
|
"username",
|
|
"lower(name)",
|
|
}
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Search filters.
|
|
var (
|
|
isCertified = r.FormValue("certified")
|
|
username = r.FormValue("username") // email or username
|
|
gender = r.FormValue("gender")
|
|
orientation = r.FormValue("orientation")
|
|
maritalStatus = r.FormValue("marital_status")
|
|
sort = r.FormValue("sort")
|
|
sortOK bool
|
|
ageMin int
|
|
ageMax int
|
|
)
|
|
|
|
ageMin, _ = strconv.Atoi(r.FormValue("age_min"))
|
|
ageMax, _ = strconv.Atoi(r.FormValue("age_max"))
|
|
if ageMin > ageMax {
|
|
ageMin, ageMax = ageMax, ageMin
|
|
}
|
|
|
|
// Get current user.
|
|
currentUser, err := session.CurrentUser(r)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't get current user!")
|
|
templates.Redirect(w, "/")
|
|
return
|
|
}
|
|
|
|
// Sort options.
|
|
for _, v := range sortWhitelist {
|
|
if sort == v {
|
|
sortOK = true
|
|
break
|
|
}
|
|
}
|
|
if !sortOK {
|
|
sort = "last_login_at desc"
|
|
}
|
|
|
|
// Default
|
|
if isCertified == "" {
|
|
isCertified = "true"
|
|
}
|
|
|
|
pager := &models.Pagination{
|
|
PerPage: config.PageSizeMemberSearch,
|
|
Sort: sort,
|
|
}
|
|
pager.ParsePage(r)
|
|
|
|
users, err := models.SearchUsers(currentUser, &models.UserSearch{
|
|
EmailOrUsername: username,
|
|
Gender: gender,
|
|
Orientation: orientation,
|
|
MaritalStatus: maritalStatus,
|
|
Certified: isCertified == "true",
|
|
AgeMin: ageMin,
|
|
AgeMax: ageMax,
|
|
}, pager)
|
|
if err != nil {
|
|
session.FlashError(w, r, "Couldn't search users: %s", err)
|
|
}
|
|
|
|
var vars = map[string]interface{}{
|
|
"Users": users,
|
|
"Pager": pager,
|
|
"Enum": config.ProfileEnums,
|
|
|
|
// Search filter values.
|
|
"Certified": isCertified,
|
|
"Gender": gender,
|
|
"Orientation": orientation,
|
|
"MaritalStatus": maritalStatus,
|
|
"EmailOrUsername": username,
|
|
"AgeMin": ageMin,
|
|
"AgeMax": ageMax,
|
|
"Sort": sort,
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|