api, frontend: allow editing profile information

Closes https://gitlab.com/commento/commento/issues/235
This commit is contained in:
Adhityaa Chandrasekar
2019-12-04 21:57:10 -08:00
parent 3e1576d494
commit 918a691ba3
10 changed files with 239 additions and 22 deletions

View File

@@ -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})
}

View File

@@ -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")

View File

@@ -102,6 +102,7 @@ func staticRouterInit(router *mux.Router) error {
"/unsubscribe",
"/dashboard",
"/logout",
"/profile",
}
for _, page := range pages {