|
|
@ -21,6 +21,7 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
const ( |
|
|
|
AUTH_ACTIVE base.TplName = "mail/auth/active" |
|
|
|
AUTH_ACTIVE base.TplName = "mail/auth/active" |
|
|
|
|
|
|
|
AUTH_ACTIVATE_EMAIL base.TplName = "mail/auth/activate_email" |
|
|
|
AUTH_REGISTER_SUCCESS base.TplName = "mail/auth/register_success" |
|
|
|
AUTH_REGISTER_SUCCESS base.TplName = "mail/auth/register_success" |
|
|
|
AUTH_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd" |
|
|
|
AUTH_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd" |
|
|
|
|
|
|
|
|
|
|
@ -64,6 +65,17 @@ func CreateUserActiveCode(u *models.User, startInf interface{}) string { |
|
|
|
return code |
|
|
|
return code |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create a time limit code for user active
|
|
|
|
|
|
|
|
func CreateUserEmailActivateCode(u *models.User, e *models.EmailAddress, startInf interface{}) string { |
|
|
|
|
|
|
|
minutes := setting.Service.ActiveCodeLives |
|
|
|
|
|
|
|
data := com.ToStr(u.Id) + e.Email + u.LowerName + u.Passwd + u.Rands |
|
|
|
|
|
|
|
code := base.CreateTimeLimitCode(data, minutes, startInf) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add tail hex username
|
|
|
|
|
|
|
|
code += hex.EncodeToString([]byte(u.LowerName)) |
|
|
|
|
|
|
|
return code |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send user register mail with active code
|
|
|
|
// Send user register mail with active code
|
|
|
|
func SendRegisterMail(r macaron.Render, u *models.User) { |
|
|
|
func SendRegisterMail(r macaron.Render, u *models.User) { |
|
|
|
code := CreateUserActiveCode(u, nil) |
|
|
|
code := CreateUserActiveCode(u, nil) |
|
|
@ -103,6 +115,27 @@ func SendActiveMail(r macaron.Render, u *models.User) { |
|
|
|
SendAsync(&msg) |
|
|
|
SendAsync(&msg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send email to verify secondary email.
|
|
|
|
|
|
|
|
func SendActivateEmail(r macaron.Render, user *models.User, email *models.EmailAddress) { |
|
|
|
|
|
|
|
code := CreateUserEmailActivateCode(user, email, nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subject := "Verify your e-mail address" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data := GetMailTmplData(user) |
|
|
|
|
|
|
|
data["Code"] = code |
|
|
|
|
|
|
|
data["Email"] = email.Email |
|
|
|
|
|
|
|
body, err := r.HTMLString(string(AUTH_ACTIVATE_EMAIL), data) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error(4, "mail.SendActiveMail(fail to render): %v", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg := NewMailMessage([]string{email.Email}, subject, body) |
|
|
|
|
|
|
|
msg.Info = fmt.Sprintf("UID: %d, send activate email to %s", user.Id, email.Email) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SendAsync(&msg) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send reset password email.
|
|
|
|
// Send reset password email.
|
|
|
|
func SendResetPasswdMail(r macaron.Render, u *models.User) { |
|
|
|
func SendResetPasswdMail(r macaron.Render, u *models.User) { |
|
|
|
code := CreateUserActiveCode(u, nil) |
|
|
|
code := CreateUserActiveCode(u, nil) |
|
|
|