From 5a5c9f600f10fbcf1e4dd9a913e9e81723023ce8 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Thu, 12 Dec 2013 01:00:22 -0600 Subject: [PATCH] Working on SendMail (currently NOT functional) Added user model for kicks - we'll see if it finds a reason to stay Setup /users and /settings routes --- lib/mailer.go | 9 ++++++++- models.go | 7 +++++++ route.go | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/mailer.go b/lib/mailer.go index 8d477c49..b4aacfe5 100644 --- a/lib/mailer.go +++ b/lib/mailer.go @@ -4,6 +4,13 @@ import ( "net/smtp" ) +//Send sends an Email using a connection to Server. +//If a Username and Password are set for the Server, authentication will be attempted +//However, to support open-relays, authentication is optional. func Send(email Email, server Server) { - auth = smtp.PlainAuth("", server.User, server.Password, server.Server) + auth := nil + if server.User != nil && server.Password != nil { + auth := smtp.PlainAuth("", server.User, server.Password, server.Host) + } + smtp.SendMail(server.Host, auth, email.From, email.To, Email.Body) } diff --git a/models.go b/models.go index 759ce13d..3b4f495b 100644 --- a/models.go +++ b/models.go @@ -19,3 +19,10 @@ type Config struct { URL string `json:"url"` SMTP SMTPServer `json:"smtp"` } + +type User struct { + Id string + Username string + Hash string + APIKey string +} diff --git a/route.go b/route.go index 9ae1c9de..f156bb8d 100644 --- a/route.go +++ b/route.go @@ -43,6 +43,8 @@ func createRouter() http.Handler { router.HandleFunc("/login", Login) router.HandleFunc("/register", Register) router.HandleFunc("/campaigns", Base_Campaigns) + router.HandleFunc("/users", Users) + router.HandleFunc("/settings", Settings) // Create the API routes api := router.PathPrefix("/api").Subrouter() @@ -69,6 +71,14 @@ func Base(w http.ResponseWriter, r *http.Request) { renderTemplate(w, "dashboard") } +func Users(w http.ResponseWriter, r *http.Request) { + renderTemplate(w, "users") +} + +func Settings(w http.ResponseWriter, r *http.Request) { + renderTemplate(w, "settings") +} + func Base_Campaigns(w http.ResponseWriter, r *http.Request) { //session, _ := store.Get(r, "gophish") renderTemplate(w, "dashboard")