2022-09-12 21:00:44 +02:00
|
|
|
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"
|
2022-09-12 21:00:44 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-09-19 22:13:47 +02:00
|
|
|
type verifyHandler struct {
|
|
|
|
cfg *Config
|
2022-09-12 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 22:13:47 +02:00
|
|
|
func newVerifyHandler(cfg *Config) *verifyHandler {
|
|
|
|
return &verifyHandler{cfg: cfg}
|
2022-09-12 21:00:44 +02:00
|
|
|
}
|
2022-09-12 23:02:51 +02:00
|
|
|
|
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 {
|
2022-09-20 22:38:20 +02:00
|
|
|
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-09-26 22:35:06 +02:00
|
|
|
return identity.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)
|
|
|
|
return identity.NewVerifyNotFound()
|
|
|
|
}
|
2022-09-20 22:38:20 +02:00
|
|
|
|
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"))
|
2022-09-12 23:02:51 +02:00
|
|
|
}
|
|
|
|
}
|