summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorPeter <peter@smitmail.eu>2014-12-17 17:41:49 +0200
committerPeter <peter@smitmail.eu>2014-12-17 17:41:49 +0200
commitec71d538fcb1f84050048a660a25258a5401828f (patch)
treed3155912217eefba56a60dd80d8a7c6fa59e30cc /modules
parent6919c80f0bdaffbf4f39c42a12536daae7f4fe79 (diff)
downloadgitea-ec71d538fcb1f84050048a660a25258a5401828f.tar.gz
gitea-ec71d538fcb1f84050048a660a25258a5401828f.zip
Method for activating email addresses through verification email
Diffstat (limited to 'modules')
-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)