12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package auth
- import (
- "encoding/hex"
- "fmt"
- "github.com/gogits/gogs/models"
- "github.com/gogits/gogs/modules/base"
- "github.com/gogits/gogs/modules/mailer"
- )
- func CreateUserActiveCode(user *models.User, startInf interface{}) string {
- hours := base.Service.ActiveCodeLives / 60
- data := base.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands
- code := base.CreateTimeLimitCode(data, hours, startInf)
-
- code += hex.EncodeToString([]byte(user.LowerName))
- return code
- }
- func SendRegisterMail(user *models.User) {
- code := CreateUserActiveCode(user, nil)
- subject := "Register success, Welcome"
- data := mailer.GetMailTmplData(user)
- data["Code"] = code
- body := base.RenderTemplate("mail/auth/register_success.html", data)
- msg := mailer.NewMailMessage([]string{user.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, send register mail", user.Id)
-
- mailer.SendAsync(msg)
- }
- func SendActiveMail(user *models.User) {
- code := CreateUserActiveCode(user, nil)
- subject := "Verify your email address"
- data := mailer.GetMailTmplData(user)
- data["Code"] = code
- body := base.RenderTemplate("mail/auth/active_email.html", data)
- msg := mailer.NewMailMessage([]string{user.Email}, subject, body)
- msg.Info = fmt.Sprintf("UID: %d, send email verify mail", user.Id)
-
- mailer.SendAsync(msg)
- }
|