Add sending account deletion notifications
This commit is contained in:
parent
5e54f90589
commit
d0aedc7223
|
@ -0,0 +1,58 @@
|
||||||
|
// Vikunja is a to-do list application to facilitate your life.
|
||||||
|
// Copyright 2018-2021 Vikunja and contributors. All rights reserved.
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public Licensee for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public Licensee
|
||||||
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.vikunja.io/api/pkg/notifications"
|
||||||
|
|
||||||
|
"xorm.io/xorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RequestDeletion creates a user deletion confirm token and sends a notification to the user
|
||||||
|
func RequestDeletion(s *xorm.Session, user *User) (err error) {
|
||||||
|
token, err := generateNewToken(s, user, TokenAccountDeletion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return notifications.Notify(user, &AccountDeletionConfirmNotification{
|
||||||
|
User: user,
|
||||||
|
ConfirmToken: token.Token,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConfirmDeletion ConformDeletion checks a token and schedules the user for deletion
|
||||||
|
func ConfirmDeletion(s *xorm.Session, user *User, token string) (err error) {
|
||||||
|
tk, err := getToken(s, token, TokenAccountDeletion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if tk == nil {
|
||||||
|
// TODO: return invalid token error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = removeTokens(s, user, TokenAccountDeletion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Schedule deletion
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -201,6 +201,7 @@ func (n *AccountDeletionConfirmNotification) ToMail() *notifications.Mail {
|
||||||
Greeting("Hi "+n.User.GetName()+",").
|
Greeting("Hi "+n.User.GetName()+",").
|
||||||
Line("You have requested the deletion of your account. To confirm this, please click the link below:").
|
Line("You have requested the deletion of your account. To confirm this, please click the link below:").
|
||||||
Action("Confirm the deletion of my account", config.ServiceFrontendurl.GetString()+"?accountDeletionConfirm="+n.ConfirmToken).
|
Action("Confirm the deletion of my account", config.ServiceFrontendurl.GetString()+"?accountDeletionConfirm="+n.ConfirmToken).
|
||||||
|
Line("This link will be valid for 24 hours.").
|
||||||
Line("Once you confirm the deletion we will schedule the deletion of your account in three days and send you another email until then.").
|
Line("Once you confirm the deletion we will schedule the deletion of your account in three days and send you another email until then.").
|
||||||
Line("If you did not requested the deletion or changed your mind, you can simply ignore this email.").
|
Line("If you did not requested the deletion or changed your mind, you can simply ignore this email.").
|
||||||
Line("Have a nice day!")
|
Line("Have a nice day!")
|
||||||
|
|
|
@ -33,6 +33,7 @@ const (
|
||||||
TokenUnknown TokenKind = iota
|
TokenUnknown TokenKind = iota
|
||||||
TokenPasswordReset
|
TokenPasswordReset
|
||||||
TokenEmailConfirm
|
TokenEmailConfirm
|
||||||
|
TokenAccountDeletion
|
||||||
|
|
||||||
tokenSize = 64
|
tokenSize = 64
|
||||||
)
|
)
|
||||||
|
@ -88,7 +89,7 @@ func RegisterTokenCleanupCron() {
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
deleted, err := s.
|
deleted, err := s.
|
||||||
Where("created > ? AND kind = ?", time.Now().Add(time.Hour*24*-1), TokenPasswordReset).
|
Where("created > ? AND (kind = ? OR kind = ?)", time.Now().Add(time.Hour*24*-1), TokenPasswordReset, TokenAccountDeletion).
|
||||||
Delete(&Token{})
|
Delete(&Token{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf(logPrefix+"Error removing old password reset tokens: %s", err)
|
log.Errorf(logPrefix+"Error removing old password reset tokens: %s", err)
|
||||||
|
|
Loading…
Reference in New Issue