Moving JSON Responses to a standard Response object

Added cursor:pointer styling to dropdown menus
pull/24/head
Jordan 2014-06-01 22:30:23 -05:00
parent 3dd22e8d7c
commit 31aa5614a0
4 changed files with 12 additions and 12 deletions

View File

@ -255,7 +255,7 @@ func API_Templates_Id(w http.ResponseWriter, r *http.Request) {
if checkError(err, w, "Error deleting group", http.StatusInternalServerError) { if checkError(err, w, "Error deleting group", http.StatusInternalServerError) {
return return
} }
writeJSON(w, []byte("{\"success\" : \"true\"}")) writeJSON(w, models.Response{Success: true, Message: "Template Deleted Successfully"})
case r.Method == "PUT": case r.Method == "PUT":
_, err := models.GetTemplate(id, ctx.Get(r, "user_id").(int64)) _, err := models.GetTemplate(id, ctx.Get(r, "user_id").(int64))
if checkError(err, w, "No group found", http.StatusNotFound) { if checkError(err, w, "No group found", http.StatusNotFound) {

View File

@ -1,7 +1,6 @@
package controllers package controllers
import ( import (
"encoding/json"
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
@ -95,7 +94,6 @@ func Register(w http.ResponseWriter, r *http.Request) {
m = "Unknown error - please try again" m = "Unknown error - please try again"
fmt.Println(err) fmt.Println(err)
} }
fmt.Println(m)
session.AddFlash(models.Flash{ session.AddFlash(models.Flash{
Type: "danger", Type: "danger",
Message: m, Message: m,
@ -131,10 +129,7 @@ func Settings(w http.ResponseWriter, r *http.Request) {
switch { switch {
case r.Method == "POST": case r.Method == "POST":
err := auth.ChangePassword(r) err := auth.ChangePassword(r)
msg := struct { msg := models.Response{Success: true, Message: "Settings Updated Successfully"}
Message string `json:"message"`
Success bool `json:"success"`
}{Message: "Settings Updated Successfully", Success: true}
if err == auth.ErrInvalidPassword { if err == auth.ErrInvalidPassword {
msg.Message = "Invalid Password" msg.Message = "Invalid Password"
msg.Success = false msg.Success = false
@ -142,11 +137,7 @@ func Settings(w http.ResponseWriter, r *http.Request) {
msg.Message = "Unknown Error Occured" msg.Message = "Unknown Error Occured"
msg.Success = false msg.Success = false
} }
msgj, err := json.MarshalIndent(msg, "", " ") writeJSON(w, msg)
if checkError(err, w, "Error marshaling response", http.StatusInternalServerError) {
return
}
writeJSON(w, msgj)
} }
} }

View File

@ -30,6 +30,11 @@ type Flash struct {
Message string Message string
} }
type Response struct {
Message string `json:"message"`
Success bool `json:"success"`
}
// Setup initializes the Conn object // Setup initializes the Conn object
// It also populates the Gophish Config object // It also populates the Gophish Config object
func Setup() error { func Setup() error {

View File

@ -124,3 +124,7 @@
width: 900px; width: 900px;
} }
} }
.dropdown-menu > li > a {
cursor:pointer;
}