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"
|
2023-01-13 21:01:34 +01:00
|
|
|
"github.com/openziti/zrok/rest_model_zrok"
|
|
|
|
"github.com/openziti/zrok/rest_server_zrok/operations/account"
|
2022-09-12 21:00:44 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-09-19 22:13:47 +02:00
|
|
|
type verifyHandler struct {
|
2022-09-12 21:00:44 +02:00
|
|
|
}
|
|
|
|
|
2022-10-19 19:20:47 +02:00
|
|
|
func newVerifyHandler() *verifyHandler {
|
|
|
|
return &verifyHandler{}
|
2022-09-12 21:00:44 +02:00
|
|
|
}
|
2022-09-12 23:02:51 +02:00
|
|
|
|
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 {
|
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-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 {
|
2023-03-09 21:29:15 +01:00
|
|
|
logrus.Errorf("error finding account request with token '%v': %v", params.Body.Token, err)
|
|
|
|
return account.NewVerifyNotFound()
|
|
|
|
}
|
2022-09-20 22:38:20 +02:00
|
|
|
|
2022-11-30 17:43:00 +01:00
|
|
|
return account.NewVerifyOK().WithPayload(&rest_model_zrok.VerifyResponse{Email: ar.Email})
|
2022-09-12 23:02:51 +02:00
|
|
|
}
|
2022-11-30 17:43:00 +01:00
|
|
|
logrus.Error("empty verification request")
|
|
|
|
return account.NewVerifyInternalServerError()
|
2022-09-12 23:02:51 +02:00
|
|
|
}
|