mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
soft deletes for invite_tokens (#262)
This commit is contained in:
parent
b8d758080b
commit
d900043fa3
@ -38,7 +38,7 @@ func (h *inviteHandler) Handle(params account.InviteParams) middleware.Responder
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
if h.cfg.Registration != nil && h.cfg.Registration.TokenStrategy == "store" {
|
||||
inviteToken, err := str.GetInviteTokenByToken(params.Body.Token, tx)
|
||||
inviteToken, err := str.FindInviteTokenByToken(params.Body.Token, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("cannot get invite token '%v' for '%v': %v", params.Body.Token, params.Body.Email, err)
|
||||
return account.NewInviteBadRequest().WithPayload("missing invite token")
|
||||
|
@ -32,16 +32,16 @@ func (str *Store) CreateInviteTokens(inviteTokens []*InviteToken, tx *sqlx.Tx) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (str *Store) GetInviteTokenByToken(token string, tx *sqlx.Tx) (*InviteToken, error) {
|
||||
func (str *Store) FindInviteTokenByToken(token string, tx *sqlx.Tx) (*InviteToken, error) {
|
||||
inviteToken := &InviteToken{}
|
||||
if err := tx.QueryRowx("select * from invite_tokens where token = $1", token).StructScan(inviteToken); err != nil {
|
||||
if err := tx.QueryRowx("select * from invite_tokens where token = $1 and not deleted", token).StructScan(inviteToken); err != nil {
|
||||
return nil, errors.Wrap(err, "error getting unused invite_token")
|
||||
}
|
||||
return inviteToken, nil
|
||||
}
|
||||
|
||||
func (str *Store) DeleteInviteToken(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("delete from invite_tokens where id = $1")
|
||||
stmt, err := tx.Prepare("update invite_tokens set updated_at = current_timestamp, deleted = true where id = $1")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing invite_tokens delete statement")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user