From 31aa5614a0e5d974774b917c64060052ea5e836d Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 1 Jun 2014 22:30:23 -0500 Subject: [PATCH] Moving JSON Responses to a standard Response object Added cursor:pointer styling to dropdown menus --- controllers/api.go | 2 +- controllers/route.go | 13 ++----------- models/models.go | 5 +++++ static/css/main.css | 4 ++++ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/controllers/api.go b/controllers/api.go index c9678938..8e8e7245 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -255,7 +255,7 @@ func API_Templates_Id(w http.ResponseWriter, r *http.Request) { if checkError(err, w, "Error deleting group", http.StatusInternalServerError) { return } - writeJSON(w, []byte("{\"success\" : \"true\"}")) + writeJSON(w, models.Response{Success: true, Message: "Template Deleted Successfully"}) case r.Method == "PUT": _, err := models.GetTemplate(id, ctx.Get(r, "user_id").(int64)) if checkError(err, w, "No group found", http.StatusNotFound) { diff --git a/controllers/route.go b/controllers/route.go index 686aed1d..0993be3a 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -1,7 +1,6 @@ package controllers import ( - "encoding/json" "fmt" "html/template" "net/http" @@ -95,7 +94,6 @@ func Register(w http.ResponseWriter, r *http.Request) { m = "Unknown error - please try again" fmt.Println(err) } - fmt.Println(m) session.AddFlash(models.Flash{ Type: "danger", Message: m, @@ -131,10 +129,7 @@ func Settings(w http.ResponseWriter, r *http.Request) { switch { case r.Method == "POST": err := auth.ChangePassword(r) - msg := struct { - Message string `json:"message"` - Success bool `json:"success"` - }{Message: "Settings Updated Successfully", Success: true} + msg := models.Response{Success: true, Message: "Settings Updated Successfully"} if err == auth.ErrInvalidPassword { msg.Message = "Invalid Password" msg.Success = false @@ -142,11 +137,7 @@ func Settings(w http.ResponseWriter, r *http.Request) { msg.Message = "Unknown Error Occured" msg.Success = false } - msgj, err := json.MarshalIndent(msg, "", " ") - if checkError(err, w, "Error marshaling response", http.StatusInternalServerError) { - return - } - writeJSON(w, msgj) + writeJSON(w, msg) } } diff --git a/models/models.go b/models/models.go index 76bc804e..9d23b2ba 100644 --- a/models/models.go +++ b/models/models.go @@ -30,6 +30,11 @@ type Flash struct { Message string } +type Response struct { + Message string `json:"message"` + Success bool `json:"success"` +} + // Setup initializes the Conn object // It also populates the Gophish Config object func Setup() error { diff --git a/static/css/main.css b/static/css/main.css index da6ade15..75334181 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -123,4 +123,8 @@ .modal-lg { width: 900px; } +} + +.dropdown-menu > li > a { + cursor:pointer; } \ No newline at end of file