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:
39
api/email_update.go
Normal file
39
api/email_update.go
Normal 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})
|
||||
}
|
Reference in New Issue
Block a user