Made models more consistent

Added UserId field to result (for use in looking up campaign when result is clicked)
pull/24/head
Jordan 2014-07-06 21:34:02 -05:00
parent 28e074f1fd
commit cc2ae713e5
5 changed files with 14 additions and 6 deletions

View File

@ -78,7 +78,12 @@ func PhishHandler(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
rs.UpdateStatus("Clicked Link")
rs.UpdateStatus(models.STATUS_SUCCESS)
c, err := models.GetCampaign(rs.CampaignId, rs.UserId)
if err != nil {
Logger.Println(err)
}
c.AddEvent(models.Event{Email: rs.Email, Message: models.EVENT_CLICKED})
w.Write([]byte("It Works!"))
}

View File

@ -141,7 +141,7 @@ func PostCampaign(c *Campaign, uid int64) error {
for _, g := range c.Groups {
// Insert a result for each target in the group
for _, t := range g.Targets {
r := Result{Email: t.Email, Status: "Unknown", CampaignId: c.Id}
r := Result{Email: t.Email, Status: STATUS_UNKNOWN, CampaignId: c.Id, UserId: c.UserId}
r.GenerateId()
err = db.Save(&r).Error
if err != nil {

View File

@ -21,9 +21,11 @@ const (
CAMPAIGN_IN_PROGRESS string = "In progress"
CAMPAIGN_QUEUED string = "Queued"
CAMPAIGN_COMPLETE string = "Completed"
STATUS_SENT string = "Email Sent"
STATUS_OPENED string = "Email Opened"
STATUS_CLICKED string = "Clicked Link"
EVENT_SENT string = "Email Sent"
EVENT_OPENED string = "Email Opened"
EVENT_CLICKED string = "Clicked Link"
STATUS_SUCCESS string = "Success"
STATUS_UNKNOWN string = "Unknown"
ERROR string = "Error"
)

View File

@ -11,6 +11,7 @@ import (
type Result struct {
Id int64 `json:"-"`
CampaignId int64 `json:"-"`
UserId int64 `json:"-"`
RId string `json:"id"`
Email string `json:"email"`
Status string `json:"status" sql:"not null"`

View File

@ -80,7 +80,7 @@ func processCampaign(c *models.Campaign) {
Logger.Println(err)
}
} else {
err = t.UpdateStatus("Email Sent")
err = t.UpdateStatus(models.EVENT_SENT)
if err != nil {
Logger.Println(err)
}