Noah
de3d6e9315
* Vendor fontawesome icons * User settings page: to edit profile details (other features not hooked up yet) * Initial user profile page
41 lines
868 B
Go
41 lines
868 B
Go
package account
|
|
|
|
import (
|
|
"net/http"
|
|
"regexp"
|
|
|
|
"git.kirsle.net/apps/gosocial/pkg/models"
|
|
"git.kirsle.net/apps/gosocial/pkg/templates"
|
|
)
|
|
|
|
var ProfileRegexp = regexp.MustCompile(`^/u/([^@]+?)$`)
|
|
|
|
// User profile page (/u/username)
|
|
func Profile() http.HandlerFunc {
|
|
tmpl := templates.Must("account/profile.html")
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
// Parse the username out of the URL parameters.
|
|
var username string
|
|
m := ProfileRegexp.FindStringSubmatch(r.URL.Path)
|
|
if m != nil {
|
|
username = m[1]
|
|
}
|
|
|
|
// Find this user.
|
|
user, err := models.FindUser(username)
|
|
if err != nil {
|
|
templates.NotFoundPage(w, r)
|
|
return
|
|
}
|
|
|
|
vars := map[string]interface{}{
|
|
"User": user,
|
|
}
|
|
|
|
if err := tmpl.Execute(w, r, vars); err != nil {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
})
|
|
}
|