This too.
Rename VerifyEmailSubject phrase to ActivateEmailSubject. Rename VerifyEmailBody phrase to ActivateEmailBody. Add ValidateEmailSubject phrase. Add ValidateEmailBody phrase. Tweak menu_forums_aria phrase.
This commit is contained in:
parent
1da6d3db09
commit
8f98708087
@ -5,14 +5,20 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/mail"
|
"net/mail"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
p "github.com/Azareal/Gosora/common/phrases"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Email struct {
|
func SendActivationEmail(username string, email string, token string) error {
|
||||||
UserID int
|
schema := "http"
|
||||||
Email string
|
if Site.EnableSsl {
|
||||||
Validated bool
|
schema += "s"
|
||||||
Primary bool
|
}
|
||||||
Token string
|
// TODO: Move these to the phrase system
|
||||||
|
subject := "Account Activation - " + Site.Name
|
||||||
|
msg := "Dear " + username + ", to complete your registration on our forums, we need 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendValidationEmail(username string, email string, token string) error {
|
func SendValidationEmail(username string, email string, token string) error {
|
||||||
@ -20,11 +26,21 @@ func SendValidationEmail(username string, email string, token string) error {
|
|||||||
if Site.EnableSsl {
|
if Site.EnableSsl {
|
||||||
schema += "s"
|
schema += "s"
|
||||||
}
|
}
|
||||||
|
r := func(body *string) func(name, val string) {
|
||||||
// TODO: Move these to the phrase system
|
return func(name, val string) {
|
||||||
subject := "Validate Your Email - " + Site.Name
|
*body = strings.Replace(*body,"{{"+name+"}}",val,-1)
|
||||||
msg := "Dear " + username + ", to complete your registration on our forums, we need 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)
|
}
|
||||||
|
subject := p.GetAccountPhrase("ValidateEmailSubject")
|
||||||
|
r1 := r(&subject)
|
||||||
|
r1("name",Site.Name)
|
||||||
|
body := p.GetAccountPhrase("ValidateEmailBody")
|
||||||
|
r2 := r(&body)
|
||||||
|
r2("username",username)
|
||||||
|
r2("schema",schema)
|
||||||
|
r2("url",Site.URL)
|
||||||
|
r2("token",token)
|
||||||
|
return SendEmail(email, subject, body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Refactor this
|
// TODO: Refactor this
|
||||||
@ -60,17 +76,13 @@ func SendEmail(email string, subject string, msg string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c, err = smtp.NewClient(conn, Config.SMTPServer)
|
c, err = smtp.NewClient(conn, Config.SMTPServer)
|
||||||
if err != nil {
|
|
||||||
LogWarning(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
c, err = smtp.Dial(Config.SMTPServer + ":" + Config.SMTPPort)
|
c, err = smtp.Dial(Config.SMTPServer + ":" + Config.SMTPPort)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if Config.SMTPUsername != "" {
|
if Config.SMTPUsername != "" {
|
||||||
auth := smtp.PlainAuth("", Config.SMTPUsername, Config.SMTPPassword, Config.SMTPServer)
|
auth := smtp.PlainAuth("", Config.SMTPUsername, Config.SMTPPassword, Config.SMTPServer)
|
||||||
@ -80,14 +92,11 @@ func SendEmail(email string, subject string, msg string) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err = c.Mail(from.Address); err != nil {
|
||||||
err = c.Mail(from.Address)
|
|
||||||
if err != nil {
|
|
||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.Rcpt(to.Address)
|
if err = c.Rcpt(to.Address); err != nil {
|
||||||
if err != nil {
|
|
||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -102,14 +111,11 @@ func SendEmail(email string, subject string, msg string) (err error) {
|
|||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err = w.Close(); err != nil {
|
||||||
err = w.Close()
|
|
||||||
if err != nil {
|
|
||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.Quit()
|
if err = c.Quit(); err != nil {
|
||||||
if err != nil {
|
|
||||||
LogWarning(err)
|
LogWarning(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -8,25 +8,50 @@ import (
|
|||||||
|
|
||||||
var Emails EmailStore
|
var Emails EmailStore
|
||||||
|
|
||||||
|
type Email struct {
|
||||||
|
UserID int
|
||||||
|
Email string
|
||||||
|
Validated bool
|
||||||
|
Primary bool
|
||||||
|
Token string
|
||||||
|
}
|
||||||
|
|
||||||
type EmailStore interface {
|
type EmailStore interface {
|
||||||
|
// TODO: Add an autoincrement key
|
||||||
|
Get(user *User, email string) (Email, error)
|
||||||
GetEmailsByUser(user *User) (emails []Email, err error)
|
GetEmailsByUser(user *User) (emails []Email, err error)
|
||||||
|
Add(uid int, email, token string) error
|
||||||
|
Delete(uid int, email string) error
|
||||||
VerifyEmail(email string) error
|
VerifyEmail(email string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type DefaultEmailStore struct {
|
type DefaultEmailStore struct {
|
||||||
|
get *sql.Stmt
|
||||||
getEmailsByUser *sql.Stmt
|
getEmailsByUser *sql.Stmt
|
||||||
|
add *sql.Stmt
|
||||||
|
delete *sql.Stmt
|
||||||
verifyEmail *sql.Stmt
|
verifyEmail *sql.Stmt
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultEmailStore(acc *qgen.Accumulator) (*DefaultEmailStore, error) {
|
func NewDefaultEmailStore(acc *qgen.Accumulator) (*DefaultEmailStore, error) {
|
||||||
|
e := "emails"
|
||||||
return &DefaultEmailStore{
|
return &DefaultEmailStore{
|
||||||
getEmailsByUser: acc.Select("emails").Columns("email,validated,token").Where("uid=?").Prepare(),
|
get: acc.Select(e).Columns("email,validated,token").Where("uid=? AND email=?").Prepare(),
|
||||||
|
getEmailsByUser: acc.Select(e).Columns("email,validated,token").Where("uid=?").Prepare(),
|
||||||
|
add: acc.Insert(e).Columns("uid,email,validated,token").Fields("?,?,?,?").Prepare(),
|
||||||
|
delete: acc.Delete(e).Where("uid=? AND email=?").Prepare(),
|
||||||
|
|
||||||
// Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
|
// Need to fix this: Empty string isn't working, it gets set to 1 instead x.x -- Has this been fixed?
|
||||||
verifyEmail: acc.Update("emails").Set("validated = 1, token = ''").Where("email = ?").Prepare(),
|
verifyEmail: acc.Update(e).Set("validated=1,token=''").Where("email=?").Prepare(),
|
||||||
}, acc.FirstError()
|
}, acc.FirstError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DefaultEmailStore) Get(user *User, email string) (Email, error) {
|
||||||
|
e := Email{UserID:user.ID, Primary:email !="" && user.Email==email}
|
||||||
|
err := s.get.QueryRow(user.ID, email).Scan(&e.Email, &e.Validated, &e.Token)
|
||||||
|
return e, err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err error) {
|
func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err error) {
|
||||||
e := Email{UserID: user.ID}
|
e := Email{UserID: user.ID}
|
||||||
rows, err := s.getEmailsByUser.Query(user.ID)
|
rows, err := s.getEmailsByUser.Query(user.ID)
|
||||||
@ -34,13 +59,11 @@ func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err err
|
|||||||
return emails, err
|
return emails, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&e.Email, &e.Validated, &e.Token)
|
err := rows.Scan(&e.Email, &e.Validated, &e.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return emails, err
|
return emails, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.Email == user.Email {
|
if e.Email == user.Email {
|
||||||
e.Primary = true
|
e.Primary = true
|
||||||
}
|
}
|
||||||
@ -49,6 +72,16 @@ func (s *DefaultEmailStore) GetEmailsByUser(user *User) (emails []Email, err err
|
|||||||
return emails, rows.Err()
|
return emails, rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DefaultEmailStore) Add(uid int, email string, token string) error {
|
||||||
|
_, err := s.add.Exec(uid, email, 0, token)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DefaultEmailStore) Delete(uid int, email string) error {
|
||||||
|
_, err := s.delete.Exec(uid,email)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DefaultEmailStore) VerifyEmail(email string) error {
|
func (s *DefaultEmailStore) VerifyEmail(email string) error {
|
||||||
_, err := s.verifyEmail.Exec(email)
|
_, err := s.verifyEmail.Exec(email)
|
||||||
return err
|
return err
|
||||||
|
@ -16,18 +16,22 @@ type WidgetStmts struct {
|
|||||||
delete *sql.Stmt
|
delete *sql.Stmt
|
||||||
create *sql.Stmt
|
create *sql.Stmt
|
||||||
update *sql.Stmt
|
update *sql.Stmt
|
||||||
|
|
||||||
|
//qgen.SimpleModel
|
||||||
}
|
}
|
||||||
|
|
||||||
var widgetStmts WidgetStmts
|
var widgetStmts WidgetStmts
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
DbInits.Add(func(acc *qgen.Accumulator) error {
|
DbInits.Add(func(acc *qgen.Accumulator) error {
|
||||||
|
w := "widgets"
|
||||||
widgetStmts = WidgetStmts{
|
widgetStmts = WidgetStmts{
|
||||||
//getList: acc.Select("widgets").Columns("wid, position, side, type, active, location, data").Orderby("position ASC").Prepare(),
|
//getList: acc.Select(w).Columns("wid, position, side, type, active, location, data").Orderby("position ASC").Prepare(),
|
||||||
getDockList: acc.Select("widgets").Columns("wid, position, type, active, location, data").Where("side = ?").Orderby("position ASC").Prepare(),
|
getDockList: acc.Select(w).Columns("wid, position, type, active, location, data").Where("side = ?").Orderby("position ASC").Prepare(),
|
||||||
delete: acc.Delete("widgets").Where("wid = ?").Prepare(),
|
//model: acc.SimpleModel(w,"position,type,active,location,data","wid"),
|
||||||
create: acc.Insert("widgets").Columns("position, side, type, active, location, data").Fields("?,?,?,?,?,?").Prepare(),
|
delete: acc.Delete(w).Where("wid = ?").Prepare(),
|
||||||
update: acc.Update("widgets").Set("position = ?, side = ?, type = ?, active = ?, location = ?, data = ?").Where("wid = ?").Prepare(),
|
create: acc.Insert(w).Columns("position, side, type, active, location, data").Fields("?,?,?,?,?,?").Prepare(),
|
||||||
|
update: acc.Update(w).Set("position = ?, side = ?, type = ?, active = ?, location = ?, data = ?").Where("wid = ?").Prepare(),
|
||||||
}
|
}
|
||||||
return acc.FirstError()
|
return acc.FirstError()
|
||||||
})
|
})
|
||||||
@ -111,7 +115,7 @@ func (widget *Widget) Build(hvars interface{}) (string, error) {
|
|||||||
return widget.BuildFunc(widget, hvars)
|
return widget.BuildFunc(widget, hvars)
|
||||||
}
|
}
|
||||||
|
|
||||||
var header = hvars.(*Header)
|
header := hvars.(*Header)
|
||||||
err := header.Theme.RunTmpl(widget.Body, hvars, header.Writer)
|
err := header.Theme.RunTmpl(widget.Body, hvars, header.Writer)
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,11 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"Accounts": {
|
"Accounts": {
|
||||||
"VerifyEmailSubject": "Validate Your Email @ {{name}}",
|
"ActivateEmailSubject": "Validate Your Email - {{name}}",
|
||||||
"VerifyEmailBody": "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}}://{{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."
|
"ActivateEmailBody": "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}}://{{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.",
|
||||||
|
|
||||||
|
"ValidateEmailSubject":"Validate Your Email - {{name}}",
|
||||||
|
"ValidateEmailBody":"Dear {{username}}, to receive emails from our site on this address, we need you to confirm that this email address actually belongs to you.\n\nPlease click on the following link to do so: {{schema}}://{{url}}/user/edit/token/{{token}}\n\nIf you're not a user of our site, then please ignore this email."
|
||||||
},
|
},
|
||||||
|
|
||||||
"Errors": {
|
"Errors": {
|
||||||
@ -440,7 +443,7 @@
|
|||||||
"panel_delete_button_text":"Delete",
|
"panel_delete_button_text":"Delete",
|
||||||
|
|
||||||
"menu_forums_tooltip":"Forum List",
|
"menu_forums_tooltip":"Forum List",
|
||||||
"menu_forums_aria":"The Forum list",
|
"menu_forums_aria":"The forum list",
|
||||||
"menu_topics_tooltip":"Topic List",
|
"menu_topics_tooltip":"Topic List",
|
||||||
"menu_topics_aria":"The topic list",
|
"menu_topics_aria":"The topic list",
|
||||||
"menu_alert_counter_aria":"The number of alerts",
|
"menu_alert_counter_aria":"The number of alerts",
|
||||||
|
Loading…
Reference in New Issue
Block a user