60964868d4
De-duped some of the logging code. Added per-route state to the not found errors. Exported debugDetail, debugDetailf, debugLog, and debugLogf. Tweaked the padding on Tempra Simple. Added panel submenus to Tempra Conflux. Added Chart CSS to Tempra Conflux. Fixed the padding and margins for the Control Panel in Cosora. Made Cosora's Control Panel a little more tablet friendly. Added the rowmsg CSS class to better style message rows. Removed the repetitive guard code for the pre-render hooks. Removed the repetitive guard code for the string-string hooks. We now capture views for routes.StaticFile Added the move action to the moderation logs. Added the viewchunks_forums table. Began work on Per-forum Views. I probably missed a few things in this changelog.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"net/smtp"
|
|
)
|
|
|
|
type Email struct {
|
|
UserID int
|
|
Email string
|
|
Validated bool
|
|
Primary bool
|
|
Token string
|
|
}
|
|
|
|
func SendValidationEmail(username string, email string, token string) bool {
|
|
var schema = "http"
|
|
if Site.EnableSsl {
|
|
schema += "s"
|
|
}
|
|
|
|
// TODO: Move these to the phrase system
|
|
subject := "Validate Your Email @ " + Site.Name
|
|
msg := "Dear " + username + ", following your registration on our forums, we ask you to validate your email, so that we can confirm that this email actually belongs to you.\n\nClick on the following link to do so. " + schema + "://" + Site.URL + "/user/edit/token/" + token + "\n\nIf you haven't created an account here, then please feel free to ignore this email.\nWe're sorry for the inconvenience this may have caused."
|
|
return SendEmail(email, subject, msg)
|
|
}
|
|
|
|
// TODO: Refactor this
|
|
// TODO: Add support for TLS
|
|
func SendEmail(email string, subject string, msg string) bool {
|
|
// This hook is useful for plugin_sendmail or for testing tools. Possibly to hook it into some sort of mail server?
|
|
// TODO: Abstract this
|
|
if Vhooks["email_send_intercept"] != nil {
|
|
return Vhooks["email_send_intercept"](email, subject, msg).(bool)
|
|
}
|
|
body := "Subject: " + subject + "\n\n" + msg + "\n"
|
|
|
|
con, err := smtp.Dial(Config.SMTPServer + ":" + Config.SMTPPort)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if Config.SMTPUsername != "" {
|
|
auth := smtp.PlainAuth("", Config.SMTPUsername, Config.SMTPPassword, Config.SMTPServer)
|
|
err = con.Auth(auth)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
}
|
|
|
|
err = con.Mail(Site.Email)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
err = con.Rcpt(email)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
emailData, err := con.Data()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
_, err = fmt.Fprintf(emailData, body)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
err = emailData.Close()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return con.Quit() == nil
|
|
}
|