summaryrefslogtreecommitdiffstats
path: root/modules/mailer
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2014-12-20 22:47:05 -0500
committer无闻 <u@gogs.io>2014-12-20 22:47:05 -0500
commita18decf4ccc9498f5fd394b03f77744bab89081b (patch)
tree63352d102a17c4c45f5bdfd376b415da1901db31 /modules/mailer
parente6e2cf7855b61f6acd7bc98b6757f99846038365 (diff)
parent20b5c23a192b3a87b4fdac724c5be705588e461c (diff)
downloadgitea-a18decf4ccc9498f5fd394b03f77744bab89081b.tar.gz
gitea-a18decf4ccc9498f5fd394b03f77744bab89081b.zip
Merge pull request #755 from phsmit/multiple_emails
Multiple emails
Diffstat (limited to 'modules/mailer')
-rw-r--r--modules/mailer/mail.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go
index 6c73e7e58f..21f33b17e8 100644
--- a/modules/mailer/mail.go
+++ b/modules/mailer/mail.go
@@ -21,6 +21,7 @@ import (
const (
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_RESET_PASSWORD base.TplName = "mail/auth/reset_passwd"
@@ -64,6 +65,17 @@ func CreateUserActiveCode(u *models.User, startInf interface{}) string {
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
func SendRegisterMail(r macaron.Render, u *models.User) {
code := CreateUserActiveCode(u, nil)
@@ -103,6 +115,27 @@ func SendActiveMail(r macaron.Render, u *models.User) {
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.
func SendResetPasswdMail(r macaron.Render, u *models.User) {
code := CreateUserActiveCode(u, nil)