mirror of https://github.com/gophish/gophish
Fixed PUT /api/template/:id - Works now!
parent
c9d00059b0
commit
ad3e69e6ae
|
@ -162,6 +162,7 @@ func API_Groups_Id(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
JSONResponse(w, models.Response{Success: true, Message: "Group Deleted Successfully"}, http.StatusOK)
|
||||
case r.Method == "PUT":
|
||||
// Change this to get from URL and uid (don't bother with id in r.Body)
|
||||
g = models.Group{}
|
||||
err = json.NewDecoder(r.Body).Decode(&g)
|
||||
if g.Id != id {
|
||||
|
@ -237,8 +238,13 @@ func API_Templates_Id(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, "Error: /:id and template_id mismatch", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
err = t.Validate()
|
||||
/* if checkError(err, w, http.StatusBadRequest) {
|
||||
return
|
||||
}*/
|
||||
t.ModifiedDate = time.Now()
|
||||
err = models.PutTemplate(&t, ctx.Get(r, "user_id").(int64))
|
||||
t.UserId = ctx.Get(r, "user_id").(int64)
|
||||
err = models.PutTemplate(&t)
|
||||
if checkError(err, w, "Error updating group", http.StatusInternalServerError) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Template struct {
|
||||
Id int64 `json:"id"`
|
||||
|
@ -12,14 +15,17 @@ type Template struct {
|
|||
ModifiedDate time.Time `json:"modified_date"`
|
||||
}
|
||||
|
||||
func (t *Template) Validate() (string, bool) {
|
||||
var ErrTemplateNameNotSpecified = errors.New("Template Name not specified")
|
||||
var ErrTemplateMissingParameter = errors.New("Need to specify at least plaintext or HTML format")
|
||||
|
||||
func (t *Template) Validate() error {
|
||||
switch {
|
||||
case t.Name == "":
|
||||
return "Template Name not specified", false
|
||||
return ErrTemplateNameNotSpecified
|
||||
case t.Text == "" && t.HTML == "":
|
||||
return "Need to specify at least plaintext or HTML format", false
|
||||
return ErrTemplateMissingParameter
|
||||
}
|
||||
return "", true
|
||||
return nil
|
||||
}
|
||||
|
||||
type UserTemplate struct {
|
||||
|
@ -73,9 +79,14 @@ func PostTemplate(t *Template) error {
|
|||
|
||||
// PutTemplate edits an existing template in the database.
|
||||
// Per the PUT Method RFC, it presumes all data for a template is provided.
|
||||
func PutTemplate(t *Template, uid int64) error {
|
||||
func PutTemplate(t *Template) error {
|
||||
Logger.Println(t)
|
||||
err := db.Debug().Where("id=?", t.Id).Save(t).Error
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
//err :=
|
||||
}
|
||||
|
||||
// DeleteTemplate deletes an existing template in the database.
|
||||
|
|
Loading…
Reference in New Issue