mirror of
https://github.com/openziti/zrok.git
synced 2024-12-22 06:40:50 +01:00
soft delete support for account_requests (#262)
This commit is contained in:
parent
47fe0f546a
commit
9da1137a78
@ -69,7 +69,7 @@ func (h *inviteHandler) Handle(params account.InviteParams) middleware.Responder
|
||||
logrus.Infof("no account found for '%v': %v", params.Body.Email, err)
|
||||
}
|
||||
|
||||
if oldAr, err := str.FindAccountRequestWithEmail(params.Body.Email, tx); err == nil {
|
||||
if oldAr, err := str.FindAccountRequestWithEmail(params.Body.Email, tx); err == nil && !oldAr.Deleted {
|
||||
logrus.Warnf("found previous account request for '%v', removing", params.Body.Email)
|
||||
if err := str.DeleteAccountRequest(oldAr.Id, tx); err != nil {
|
||||
logrus.Errorf("error deleteing previous account request for '%v': %v", params.Body.Email, err)
|
||||
|
@ -32,6 +32,10 @@ func (h *registerHandler) Handle(params account.RegisterParams) middleware.Respo
|
||||
logrus.Errorf("error finding account request with token '%v': %v", params.Body.Token, err)
|
||||
return account.NewRegisterNotFound()
|
||||
}
|
||||
if ar.Deleted {
|
||||
logrus.Errorf("account request with token '%v' deleted", params.Body.Token)
|
||||
return account.NewRegisterNotFound()
|
||||
}
|
||||
|
||||
token, err := createToken()
|
||||
if err != nil {
|
||||
|
@ -49,10 +49,10 @@ func (self *Store) FindExpiredAccountRequests(before time.Time, limit int, tx *s
|
||||
var sql string
|
||||
switch self.cfg.Type {
|
||||
case "postgres":
|
||||
sql = "select * from account_requests where created_at < $1 limit %d for update"
|
||||
sql = "select * from account_requests where created_at < $1 and not deleted limit %d for update"
|
||||
|
||||
case "sqlite3":
|
||||
sql = "select * from account_requests where created_at < $1 limit %d"
|
||||
sql = "select * from account_requests where created_at < $1 and not deleted limit %d"
|
||||
|
||||
default:
|
||||
return nil, errors.Errorf("unknown database type '%v'", self.cfg.Type)
|
||||
@ -82,7 +82,7 @@ func (self *Store) FindAccountRequestWithEmail(email string, tx *sqlx.Tx) (*Acco
|
||||
}
|
||||
|
||||
func (self *Store) DeleteAccountRequest(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("delete from account_requests where id = $1")
|
||||
stmt, err := tx.Prepare("update account_requests set deleted = true, updated_at = current_timestamp where id = $1")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing account_requests delete statement")
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (self *Store) DeleteMultipleAccountRequests(ids []int, tx *sqlx.Tx) error {
|
||||
indexes[i] = fmt.Sprintf("$%d", i+1)
|
||||
}
|
||||
|
||||
stmt, err := tx.Prepare(fmt.Sprintf("delete from account_requests where id in (%s)", strings.Join(indexes, ",")))
|
||||
stmt, err := tx.Prepare(fmt.Sprintf("update account_requests set deleted = true, updated_at = current_timestamp where id in (%s)", strings.Join(indexes, ",")))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing account_requests delete multiple statement")
|
||||
}
|
||||
|
@ -26,7 +26,11 @@ func (self *verifyHandler) Handle(params account.VerifyParams) middleware.Respon
|
||||
|
||||
ar, err := str.FindAccountRequestWithToken(params.Body.Token, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error finding account with token '%v': %v", params.Body.Token, err)
|
||||
logrus.Errorf("error finding account request with token '%v': %v", params.Body.Token, err)
|
||||
return account.NewVerifyNotFound()
|
||||
}
|
||||
if ar.Deleted {
|
||||
logrus.Errorf("account request for '%v' with token '%v' deleted", ar.Email, params.Body.Token)
|
||||
return account.NewVerifyNotFound()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user