Refactor user email confirmation + password reset handling (#919)
Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/919 Co-authored-by: konrad <konrad@kola-entertainments.de> Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
@ -19,7 +19,6 @@ package user
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/notifications"
|
||||
"code.vikunja.io/api/pkg/utils"
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
@ -52,26 +51,35 @@ func UpdateEmail(s *xorm.Session, update *EmailUpdate) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
update.User.IsActive = false
|
||||
update.User.Email = update.NewEmail
|
||||
update.User.EmailConfirmToken = utils.MakeRandomString(64)
|
||||
|
||||
// Send the confirmation mail
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
_, err = s.
|
||||
Where("id = ?", update.User.ID).
|
||||
Cols("email").
|
||||
Update(update.User)
|
||||
return
|
||||
}
|
||||
|
||||
update.User.Status = StatusEmailConfirmationRequired
|
||||
token, err := generateNewToken(s, update.User, TokenEmailConfirm)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = s.
|
||||
Where("id = ?", update.User.ID).
|
||||
Cols("email", "is_active", "email_confirm_token").
|
||||
Cols("email", "is_active"). // TODO: Status change
|
||||
Update(update.User)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Send the confirmation mail
|
||||
if !config.MailerEnabled.GetBool() {
|
||||
return
|
||||
}
|
||||
|
||||
// Send the user a mail with a link to confirm the mail
|
||||
n := &EmailConfirmNotification{
|
||||
User: update.User,
|
||||
IsNew: false,
|
||||
User: update.User,
|
||||
IsNew: false,
|
||||
ConfirmToken: token.Token,
|
||||
}
|
||||
|
||||
err = notifications.Notify(update.User, n)
|
||||
|
Reference in New Issue
Block a user