From cc2ae713e5282b31218873ec0445acad1b5c56f2 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 6 Jul 2014 21:34:02 -0500 Subject: [PATCH] Made models more consistent Added UserId field to result (for use in looking up campaign when result is clicked) --- controllers/route.go | 7 ++++++- models/campaign.go | 2 +- models/models.go | 8 +++++--- models/result.go | 1 + worker/worker.go | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/controllers/route.go b/controllers/route.go index ee493004..619c0a6e 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -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!")) } diff --git a/models/campaign.go b/models/campaign.go index d5bf1734..81287a06 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -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 { diff --git a/models/models.go b/models/models.go index a54fd9ac..72b27a7d 100644 --- a/models/models.go +++ b/models/models.go @@ -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" ) diff --git a/models/result.go b/models/result.go index c29de83c..5c05e38b 100644 --- a/models/result.go +++ b/models/result.go @@ -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"` diff --git a/worker/worker.go b/worker/worker.go index 84c579a4..9f2856ca 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -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) }