mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
@@ -97,6 +97,14 @@ func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) b
|
||||
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
type AddEmailForm struct {
|
||||
Email string `form:"email" binding:"Required;Email;MaxSize(50)"`
|
||||
}
|
||||
|
||||
func (f *AddEmailForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
type ChangePasswordForm struct {
|
||||
OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"`
|
||||
Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"`
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user