zrok/controller/verify.go

38 lines
1.1 KiB
Go
Raw Normal View History

package controller
import (
2022-09-19 22:13:47 +02:00
"github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
2022-11-30 17:43:00 +01:00
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/account"
"github.com/sirupsen/logrus"
)
2022-09-19 22:13:47 +02:00
type verifyHandler struct {
}
func newVerifyHandler() *verifyHandler {
return &verifyHandler{}
}
2022-11-30 17:43:00 +01:00
func (self *verifyHandler) Handle(params account.VerifyParams) middleware.Responder {
2022-09-19 22:26:54 +02:00
if params.Body != nil {
logrus.Debugf("received verify request for token '%v'", params.Body.Token)
2022-09-19 22:26:54 +02:00
tx, err := str.Begin()
if err != nil {
logrus.Errorf("error starting transaction: %v", err)
2022-11-30 17:43:00 +01:00
return account.NewVerifyInternalServerError()
2022-09-19 22:26:54 +02:00
}
2022-09-20 22:28:19 +02:00
defer func() { _ = tx.Rollback() }()
2022-09-19 22:26:54 +02:00
ar, err := str.FindAccountRequestWithToken(params.Body.Token, tx)
if err != nil {
logrus.Errorf("error finding account with token '%v': %v", params.Body.Token, err)
2022-11-30 17:43:00 +01:00
return account.NewVerifyNotFound()
2022-09-19 22:26:54 +02:00
}
2022-11-30 17:43:00 +01:00
return account.NewVerifyOK().WithPayload(&rest_model_zrok.VerifyResponse{Email: ar.Email})
}
2022-11-30 17:43:00 +01:00
logrus.Error("empty verification request")
return account.NewVerifyInternalServerError()
}