Email errors should be logged now.
Reordered the registration logic so the session is created before any, if any, email errors fire. Fixed a bug where the analytics phrases would load after the graph is drawn.
This commit is contained in:
parent
ce04b6001e
commit
e9b46e1cd6
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -10,5 +10,7 @@ let seriesData = [{{range .Graph.Series}}[{{range .}}
|
|||
let legendNames = [{{range .Graph.Legends}}
|
||||
{{.}},{{end}}
|
||||
];
|
||||
addInitHook("after_phrases", () => {
|
||||
buildStatsChart(rawLabels, seriesData, "{{.TimeRange}}",legendNames);
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue