1
mirror of https://gitlab.com/commento/commento.git synced 2025-06-29 22:56:37 -04:00

api,frontend: add unsubscribe

This commit is contained in:
Adhityaa Chandrasekar
2019-02-18 16:30:54 -05:00
parent 60a9f2cc15
commit e1c94ecf15
11 changed files with 252 additions and 8 deletions

39
api/email_update.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"net/http"
)
func emailUpdate(e email) error {
statement := `
UPDATE emails
SET sendReplyNotifications = $3, sendModeratorNotifications = $4
WHERE email = $1 AND unsubscribeSecretHex = $2;
`
_, err := db.Exec(statement, e.Email, e.UnsubscribeSecretHex, e.SendReplyNotifications, e.SendModeratorNotifications)
if err != nil {
logger.Errorf("error updating email: %v", err)
return errorInternal
}
return nil
}
func emailUpdateHandler(w http.ResponseWriter, r *http.Request) {
type request struct {
Email *email `json:"email"`
}
var x request
if err := bodyUnmarshal(r, &x); err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
if err := emailUpdate(*x.Email); err != nil {
bodyMarshal(w, response{"success": true, "message": err.Error()})
return
}
bodyMarshal(w, response{"success": true})
}