api, frontend: allow editing profile information
Closes https://gitlab.com/commento/commento/issues/235
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import ()
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func commenterUpdate(commenterHex string, email string, name string, link string, photo string, provider string) error {
|
||||
if email == "" || name == "" || link == "" || photo == "" || provider == "" {
|
||||
@@ -27,3 +29,38 @@ func commenterUpdate(commenterHex string, email string, name string, link string
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func commenterUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
type request struct {
|
||||
CommenterToken *string `json:"commenterToken"`
|
||||
Name *string `json:"name"`
|
||||
Email *string `json:"email"`
|
||||
Link *string `json:"link"`
|
||||
Photo *string `json:"photo"`
|
||||
}
|
||||
|
||||
var x request
|
||||
if err := bodyUnmarshal(r, &x); err != nil {
|
||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c, err := commenterGetByCommenterToken(*x.CommenterToken)
|
||||
if err != nil {
|
||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if c.Provider == "commento" {
|
||||
*x.Link = c.Link
|
||||
*x.Photo = c.Photo
|
||||
}
|
||||
*x.Email = c.Email
|
||||
|
||||
if err = commenterUpdate(c.CommenterHex, *x.Email, *x.Name, *x.Link, *x.Photo, c.Provider); err != nil {
|
||||
bodyMarshal(w, response{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
bodyMarshal(w, response{"success": true})
|
||||
}
|
||||
|
@@ -27,6 +27,7 @@ func apiRouterInit(router *mux.Router) error {
|
||||
router.HandleFunc("/api/commenter/new", commenterNewHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/login", commenterLoginHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/self", commenterSelfHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/update", commenterUpdateHandler).Methods("POST")
|
||||
router.HandleFunc("/api/commenter/photo", commenterPhotoHandler).Methods("GET")
|
||||
|
||||
router.HandleFunc("/api/forgot", forgotHandler).Methods("POST")
|
||||
|
@@ -102,6 +102,7 @@ func staticRouterInit(router *mux.Router) error {
|
||||
"/unsubscribe",
|
||||
"/dashboard",
|
||||
"/logout",
|
||||
"/profile",
|
||||
}
|
||||
|
||||
for _, page := range pages {
|
||||
|
Reference in New Issue
Block a user