mirror of https://github.com/gophish/gophish
Updating gorm constructs to support gorm v1.0 released yesterday.
parent
095da00a05
commit
d43a888b26
|
@ -130,7 +130,7 @@ func API_Groups(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
_, err = models.GetGroupByName(g.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err != gorm.RecordNotFound {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
JSONResponse(w, models.Response{Success: false, Message: "Group name already in use"}, http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func API_Templates(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
_, err = models.GetTemplateByName(t.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err != gorm.RecordNotFound {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
JSONResponse(w, models.Response{Success: false, Message: "Template name already in use"}, http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ func API_Pages(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
// Check to make sure the name is unique
|
||||
_, err = models.GetPageByName(p.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err != gorm.RecordNotFound {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
JSONResponse(w, models.Response{Success: false, Message: "Page name already in use"}, http.StatusConflict)
|
||||
Logger.Println(err)
|
||||
return
|
||||
|
@ -365,7 +365,7 @@ func API_SMTP(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
// Check to make sure the name is unique
|
||||
_, err = models.GetSMTPByName(s.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err != gorm.RecordNotFound {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
JSONResponse(w, models.Response{Success: false, Message: "SMTP name already in use"}, http.StatusConflict)
|
||||
Logger.Println(err)
|
||||
return
|
||||
|
@ -540,7 +540,7 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
// Get the Template requested by name
|
||||
s.Template, err = models.GetTemplateByName(s.Template.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Template %s does not exist", s.Template.Name)
|
||||
JSONResponse(w, models.Response{Success: false, Message: models.ErrTemplateNotFound.Error()}, http.StatusBadRequest)
|
||||
} else if err != nil {
|
||||
|
@ -554,7 +554,7 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
|
|||
if err := s.SMTP.Validate(); err != nil {
|
||||
// Otherwise get the SMTP requested by name
|
||||
s.SMTP, err = models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64))
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Sending profile %s does not exist", s.SMTP.Name)
|
||||
JSONResponse(w, models.Response{Success: false, Message: models.ErrSMTPNotFound.Error()}, http.StatusBadRequest)
|
||||
} else if err != nil {
|
||||
|
|
|
@ -201,7 +201,7 @@ func PostCampaign(c *Campaign, uid int64) error {
|
|||
// Check to make sure all the groups already exist
|
||||
for i, g := range c.Groups {
|
||||
c.Groups[i], err = GetGroupByName(g.Name, uid)
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Group %s does not exist", g.Name)
|
||||
return ErrGroupNotFound
|
||||
} else if err != nil {
|
||||
|
@ -211,7 +211,7 @@ func PostCampaign(c *Campaign, uid int64) error {
|
|||
}
|
||||
// Check to make sure the template exists
|
||||
t, err := GetTemplateByName(c.Template.Name, uid)
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Template %s does not exist", t.Name)
|
||||
return ErrTemplateNotFound
|
||||
} else if err != nil {
|
||||
|
@ -222,7 +222,7 @@ func PostCampaign(c *Campaign, uid int64) error {
|
|||
c.TemplateId = t.Id
|
||||
// Check to make sure the page exists
|
||||
p, err := GetPageByName(c.Page.Name, uid)
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Page %s does not exist", p.Name)
|
||||
return ErrPageNotFound
|
||||
} else if err != nil {
|
||||
|
@ -233,7 +233,7 @@ func PostCampaign(c *Campaign, uid int64) error {
|
|||
c.PageId = p.Id
|
||||
// Check to make sure the sending profile exists
|
||||
s, err := GetSMTPByName(c.SMTP.Name, uid)
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
Logger.Printf("Error - Sending profile %s does not exist", s.Name)
|
||||
return ErrPageNotFound
|
||||
} else if err != nil {
|
||||
|
|
|
@ -203,7 +203,7 @@ func insertTargetIntoGroup(t Target, gid int64) error {
|
|||
return err
|
||||
}
|
||||
err = trans.Where("group_id=? and target_id=?", gid, t.Id).Find(&GroupTarget{}).Error
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
err = trans.Save(&GroupTarget{GroupId: gid, TargetId: t.Id}).Error
|
||||
if err != nil {
|
||||
Logger.Println(err)
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
_ "github.com/mattn/go-sqlite3" // Blank import needed to import sqlite3
|
||||
)
|
||||
|
||||
var db gorm.DB
|
||||
var db *gorm.DB
|
||||
var err error
|
||||
|
||||
// ErrUsernameTaken is thrown when a user attempts to register a username that is taken.
|
||||
|
|
|
@ -75,7 +75,7 @@ func (r *Result) GenerateId() {
|
|||
io.ReadFull(rand.Reader, k)
|
||||
r.RId = fmt.Sprintf("%x", k)
|
||||
err := db.Table("results").Where("id=?", r.RId).First(&Result{}).Error
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func GetTemplates(uid int64) ([]Template, error) {
|
|||
if err == nil && len(ts[i].Attachments) == 0 {
|
||||
ts[i].Attachments = make([]Attachment, 0)
|
||||
}
|
||||
if err != nil && err != gorm.RecordNotFound {
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
Logger.Println(err)
|
||||
return ts, err
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func GetTemplate(id int64, uid int64) (Template, error) {
|
|||
return t, err
|
||||
}
|
||||
err = db.Where("template_id=?", t.Id).Find(&t.Attachments).Error
|
||||
if err != nil && err != gorm.RecordNotFound {
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
Logger.Println(err)
|
||||
return t, err
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ func GetTemplateByName(n string, uid int64) (Template, error) {
|
|||
return t, err
|
||||
}
|
||||
err = db.Where("template_id=?", t.Id).Find(&t.Attachments).Error
|
||||
if err != nil && err != gorm.RecordNotFound {
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
Logger.Println(err)
|
||||
return t, err
|
||||
}
|
||||
|
@ -126,11 +126,11 @@ func PutTemplate(t *Template) error {
|
|||
}
|
||||
// Delete all attachments, and replace with new ones
|
||||
err = db.Where("template_id=?", t.Id).Delete(&Attachment{}).Error
|
||||
if err != nil && err != gorm.RecordNotFound {
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
Logger.Println(err)
|
||||
return err
|
||||
}
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
err = nil
|
||||
}
|
||||
for i, _ := range t.Attachments {
|
||||
|
|
|
@ -38,7 +38,7 @@ func GetUserByUsername(username string) (User, error) {
|
|||
u := User{}
|
||||
err := db.Where("username = ?", username).First(&u).Error
|
||||
// No issue if we don't find a record
|
||||
if err == gorm.RecordNotFound {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return u, nil
|
||||
} else if err == nil {
|
||||
return u, ErrUsernameTaken
|
||||
|
|
Loading…
Reference in New Issue