zrok/controller/verify.go

40 lines
1.3 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"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
"github.com/sirupsen/logrus"
)
2022-09-19 22:13:47 +02:00
type verifyHandler struct {
cfg *Config
}
2022-09-19 22:13:47 +02:00
func newVerifyHandler(cfg *Config) *verifyHandler {
return &verifyHandler{cfg: cfg}
}
2022-09-19 22:13:47 +02:00
func (self *verifyHandler) Handle(params identity.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)
return identity.NewVerifyInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
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)
return identity.NewVerifyNotFound()
}
2022-09-19 22:26:54 +02:00
return identity.NewVerifyOK().WithPayload(&rest_model_zrok.VerifyResponse{Email: ar.Email})
} else {
logrus.Error("empty verification request")
return identity.NewVerifyInternalServerError().WithPayload(rest_model_zrok.ErrorMessage("empty verification request"))
}
}