mirror of https://github.com/gophish/gophish
Fixing middleware JSON responses
parent
c52981614a
commit
b3cadcb01f
|
@ -73,6 +73,7 @@ func RequireAPIKey(handler http.Handler) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
if ak == "" {
|
if ak == "" {
|
||||||
JSONError(w, 400, "API Key not set")
|
JSONError(w, 400, "API Key not set")
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
u, err := models.GetUserByAPIKey(ak)
|
u, err := models.GetUserByAPIKey(ak)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -101,8 +102,8 @@ func RequireLogin(handler http.Handler) http.HandlerFunc {
|
||||||
// JSONError returns an error in JSON format with the given
|
// JSONError returns an error in JSON format with the given
|
||||||
// status code and message
|
// status code and message
|
||||||
func JSONError(w http.ResponseWriter, c int, m string) {
|
func JSONError(w http.ResponseWriter, c int, m string) {
|
||||||
w.WriteHeader(c)
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
cj, _ := json.MarshalIndent(models.Response{Success: false, Message: m}, "", " ")
|
cj, _ := json.MarshalIndent(models.Response{Success: false, Message: m}, "", " ")
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(c)
|
||||||
fmt.Fprintf(w, "%s", cj)
|
fmt.Fprintf(w, "%s", cj)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue