-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain_moderator_delete.go
62 lines (51 loc) · 1.37 KB
/
domain_moderator_delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"net/http"
)
func domainModeratorDelete(domain string, email string) error {
if domain == "" || email == "" {
return errorMissingConfig
}
statement := `
DELETE FROM moderators
WHERE domain=$1 AND email=$2;
`
_, err := db.Exec(statement, domain, email)
if err != nil {
logger.Errorf("cannot delete moderator: %v", err)
return errorInternal
}
return nil
}
func domainModeratorDeleteHandler(w http.ResponseWriter, r *http.Request) {
type request struct {
OwnerToken *string `json:"ownerToken"`
Domain *string `json:"domain"`
Email *string `json:"email"`
}
var x request
if err := bodyUnmarshal(r, &x); err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
o, err := ownerGetByOwnerToken(*x.OwnerToken)
if err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
domain := domainStrip(*x.Domain)
authorised, err := domainOwnershipVerify(o.OwnerHex, domain)
if err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
if !authorised {
bodyMarshal(w, response{"success": false, "message": errorNotAuthorised.Error()})
return
}
if err = domainModeratorDelete(domain, *x.Email); err != nil {
bodyMarshal(w, response{"success": false, "message": err.Error()})
return
}
bodyMarshal(w, response{"success": true})
}