Skip to content

Commit

Permalink
Merge pull request #568 from openziti/reset_to_regenerate
Browse files Browse the repository at this point in the history
reset token -> regenerate token (#191)
  • Loading branch information
michaelquigley authored Feb 20, 2024
2 parents 778e50c + a7194ae commit c9a9b27
Show file tree
Hide file tree
Showing 25 changed files with 1,006 additions and 1,009 deletions.
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func Run(inCfg *config.Config) error {
api.AccountChangePasswordHandler = newChangePasswordHandler(cfg)
api.AccountInviteHandler = newInviteHandler(cfg)
api.AccountLoginHandler = account.LoginHandlerFunc(loginHandler)
api.AccountRegenerateTokenHandler = newRegenerateTokenHandler()
api.AccountRegisterHandler = newRegisterHandler(cfg)
api.AccountResetPasswordHandler = newResetPasswordHandler(cfg)
api.AccountResetPasswordRequestHandler = newResetPasswordRequestHandler()
api.AccountResetTokenHandler = newResetTokenHandler()
api.AccountVerifyHandler = newVerifyHandler()
api.AdminCreateFrontendHandler = newCreateFrontendHandler()
api.AdminCreateIdentityHandler = newCreateIdentityHandler()
Expand Down
24 changes: 12 additions & 12 deletions controller/resetToken.go → controller/regenerateToken.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,57 @@ import (
"github.com/sirupsen/logrus"
)

type resetTokenHandler struct{}
type regenerateTokenHandler struct{}

func newResetTokenHandler() *resetTokenHandler {
return &resetTokenHandler{}
func newRegenerateTokenHandler() *regenerateTokenHandler {
return &regenerateTokenHandler{}
}

func (handler *resetTokenHandler) Handle(params account.ResetTokenParams, principal *rest_model_zrok.Principal) middleware.Responder {
func (handler *regenerateTokenHandler) Handle(params account.RegenerateTokenParams, principal *rest_model_zrok.Principal) middleware.Responder {
logrus.Infof("received token regeneration request for email '%v'", principal.Email)

if params.Body.EmailAddress != principal.Email {
logrus.Errorf("mismatched account '%v' for '%v'", params.Body.EmailAddress, principal.Email)
return account.NewResetTokenNotFound()
return account.NewRegenerateTokenNotFound()
}

tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction for '%v': %v", params.Body.EmailAddress, err)
return account.NewResetTokenInternalServerError()
return account.NewRegenerateTokenInternalServerError()
}
defer tx.Rollback()

a, err := str.FindAccountWithEmail(params.Body.EmailAddress, tx)
if err != nil {
logrus.Errorf("error finding account for '%v': %v", params.Body.EmailAddress, err)
return account.NewResetTokenNotFound()
return account.NewRegenerateTokenNotFound()
}
if a.Deleted {
logrus.Errorf("account '%v' for '%v' deleted", a.Email, a.Token)
return account.NewResetTokenNotFound()
return account.NewRegenerateTokenNotFound()
}

// Need to create new token and invalidate all other resources
token, err := CreateToken()
if err != nil {
logrus.Errorf("error creating token for request '%v': %v", params.Body.EmailAddress, err)
return account.NewResetTokenInternalServerError()
return account.NewRegenerateTokenInternalServerError()
}

a.Token = token

if _, err := str.UpdateAccount(a, tx); err != nil {
logrus.Errorf("error updating account for request '%v': %v", params.Body.EmailAddress, err)
return account.NewResetTokenInternalServerError()
return account.NewRegenerateTokenInternalServerError()
}

if err := tx.Commit(); err != nil {
logrus.Errorf("error committing '%v' (%v): %v", params.Body.EmailAddress, a.Email, err)
return account.NewResetTokenInternalServerError()
return account.NewRegenerateTokenInternalServerError()
}

logrus.Infof("regenerated token '%v' for '%v'", a.Token, a.Email)

return account.NewResetTokenOK().WithPayload(&account.ResetTokenOKBody{Token: token})
return account.NewRegenerateTokenOK().WithPayload(&account.RegenerateTokenOKBody{Token: token})
}
70 changes: 35 additions & 35 deletions rest_client_zrok/account/account_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9a9b27

Please sign in to comment.