few small fixes

This commit is contained in:
Cam 2024-02-14 13:06:04 -06:00
parent 8d51fce2b8
commit d57d72387f
No known key found for this signature in database
GPG Key ID: 367B7C7EBD84A8BD
2 changed files with 21 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# CHANGELOG
## v0.4.24
FIX: Updated password reset to handle multiple reset requests.
## v0.4.23
CHANGE: Improved OpenZiti resource cleanup resilience. Previous resource cleanup would stop when an error was encountered at any stage of the cleanup process (serps, sps, config, service). New cleanup implementation logs errors but continues to clean up anything that it can (https://github.com/openziti/zrok/issues/533)

View File

@ -7,6 +7,7 @@ import (
"github.com/jmoiron/sqlx"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type PasswordResetRequest struct {
@ -17,6 +18,10 @@ type PasswordResetRequest struct {
}
func (str *Store) CreatePasswordResetRequest(prr *PasswordResetRequest, tx *sqlx.Tx) (int, error) {
if err := str.DeletePasswordResetRequestsByAccountId(prr.AccountId, tx); err != nil {
logrus.Errorf("unable to delete old password reset requests for account '%v', but continuing: %v", prr.AccountId, err)
}
stmt, err := tx.Prepare("insert into password_reset_requests (account_id, token) values ($1, $2) returning id")
if err != nil {
return 0, errors.Wrap(err, "error preparing password_reset_requests insert statement")
@ -98,3 +103,15 @@ func (str *Store) DeleteMultiplePasswordResetRequests(ids []int, tx *sqlx.Tx) er
}
return nil
}
func (str *Store) DeletePasswordResetRequestsByAccountId(accountId int, tx *sqlx.Tx) error {
stmt, err := tx.Prepare("update password_reset_requests set updated_at = current_timestamp, deleted = true where account_id = $1")
if err != nil {
return errors.Wrap(err, "error preparing password_reset_requests delete by account_id statement")
}
_, err = stmt.Exec(accountId)
if err != nil {
return errors.Wrap(err, "error executing password_reset_requests delete by account_id statement")
}
return nil
}