diff --git a/common/email.go b/common/email.go index 9cdc8934..03067615 100644 --- a/common/email.go +++ b/common/email.go @@ -13,7 +13,7 @@ type Email struct { Token string } -func SendValidationEmail(username string, email string, token string) bool { +func SendValidationEmail(username string, email string, token string) error { var schema = "http" if Site.EnableSsl { schema += "s" @@ -27,49 +27,48 @@ func SendValidationEmail(username string, email string, token string) bool { // TODO: Refactor this // TODO: Add support for TLS -func SendEmail(email string, subject string, msg string) bool { +func SendEmail(email string, subject string, msg string) error { // This hook is useful for plugin_sendmail or for testing tools. Possibly to hook it into some sort of mail server? ret, hasHook := GetHookTable().VhookNeedHook("email_send_intercept", email, subject, msg) if hasHook { - return ret.(bool) + return ret.(error) } body := "Subject: " + subject + "\n\n" + msg + "\n" con, err := smtp.Dial(Config.SMTPServer + ":" + Config.SMTPPort) if err != nil { - return false + return err } if Config.SMTPUsername != "" { auth := smtp.PlainAuth("", Config.SMTPUsername, Config.SMTPPassword, Config.SMTPServer) err = con.Auth(auth) if err != nil { - return false + return err } } err = con.Mail(Site.Email) if err != nil { - return false + return err } err = con.Rcpt(email) if err != nil { - return false + return err } emailData, err := con.Data() if err != nil { - return false + return err } _, err = fmt.Fprintf(emailData, body) if err != nil { - return false + return err } err = emailData.Close() if err != nil { - return false + return err } - - return con.Quit() == nil + return con.Quit() } diff --git a/experimental/plugin_sendmail.go b/experimental/plugin_sendmail.go index 72946382..84248744 100644 --- a/experimental/plugin_sendmail.go +++ b/experimental/plugin_sendmail.go @@ -54,19 +54,18 @@ func sendSendmail(data ...interface{}) interface{} { sendmail := exec.Command("/usr/sbin/sendmail", "-t", "-i") stdin, err := sendmail.StdinPipe() if err != nil { - return false // Possibly disable the plugin and show an error to the admin on the dashboard? Plugin log file? + return err // Possibly disable the plugin and show an error to the admin on the dashboard? Plugin log file? } err = sendmail.Start() if err != nil { - return false + return err } io.WriteString(stdin, msg) err = stdin.Close() if err != nil { - return false + return err } - - return sendmail.Wait() == nil + return sendmail.Wait() } diff --git a/routes/account.go b/routes/account.go index 603b972d..b25084f8 100644 --- a/routes/account.go +++ b/routes/account.go @@ -321,6 +321,12 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user common.U return common.InternalError(err, w, r) } + session, err := common.Auth.CreateSession(uid) + if err != nil { + return common.InternalError(err, w, r) + } + common.Auth.SetCookies(w, uid, session) + // Check if this user actually owns this email, if email activation is on, automatically flip their account to active when the email is validated. Validation is also useful for determining whether this user should receive any alerts, etc. via email if common.Site.EnableEmails { token, err := common.GenerateSafeString(80) @@ -334,17 +340,13 @@ func AccountRegisterSubmit(w http.ResponseWriter, r *http.Request, user common.U return common.InternalError(err, w, r) } - if !common.SendValidationEmail(username, email, token) { + err = common.SendValidationEmail(username, email, token) + if err != nil { + common.LogWarning(err) return common.LocalError(phrases.GetErrorPhrase("register_email_fail"), w, r, user) } } - session, err := common.Auth.CreateSession(uid) - if err != nil { - return common.InternalError(err, w, r) - } - - common.Auth.SetCookies(w, uid, session) http.Redirect(w, r, "/", http.StatusSeeOther) return nil } diff --git a/templates/panel_analytics_script.html b/templates/panel_analytics_script.html index 1d3cbae2..b63cbc2b 100644 --- a/templates/panel_analytics_script.html +++ b/templates/panel_analytics_script.html @@ -10,5 +10,7 @@ let seriesData = [{{range .Graph.Series}}[{{range .}} let legendNames = [{{range .Graph.Legends}} {{.}},{{end}} ]; -buildStatsChart(rawLabels, seriesData, "{{.TimeRange}}",legendNames); +addInitHook("after_phrases", () => { + buildStatsChart(rawLabels, seriesData, "{{.TimeRange}}",legendNames); +}); \ No newline at end of file