From 95eeb292b577edb8bc73dcee1130d5e52821206d Mon Sep 17 00:00:00 2001 From: olalekan odukoya Date: Mon, 26 Aug 2024 23:07:37 +0100 Subject: [PATCH] resolve conflict --- api/handlers/user.go | 9 +++++++++ api/models/user.go | 13 +++++++++++++ go.mod | 2 +- go.sum | 2 +- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/api/handlers/user.go b/api/handlers/user.go index 7120594120..be33a2cd28 100644 --- a/api/handlers/user.go +++ b/api/handlers/user.go @@ -17,6 +17,10 @@ import ( m "github.com/frain-dev/convoy/internal/pkg/middleware" ) +const ( + ErrDisposableEmailNotAllowed = "disposable email not allowed." +) + func (h *Handler) RegisterUser(w http.ResponseWriter, r *http.Request) { var newUser models.RegisterUser if err := util.ReadJSON(r, &newUser); err != nil { @@ -24,6 +28,11 @@ func (h *Handler) RegisterUser(w http.ResponseWriter, r *http.Request) { return } + if newUser.EmailIsDisposable() { + _ = render.Render(w, r, util.NewErrorResponse(ErrDisposableEmailNotAllowed, http.StatusBadRequest)) + return + } + if err := newUser.Validate(); err != nil { _ = render.Render(w, r, util.NewErrorResponse(err.Error(), http.StatusBadRequest)) return diff --git a/api/models/user.go b/api/models/user.go index 5efc89c373..553d3aa92d 100644 --- a/api/models/user.go +++ b/api/models/user.go @@ -1,6 +1,8 @@ package models import ( + emailverifier "github.com/AfterShip/email-verifier" + "github.com/frain-dev/convoy/auth" "github.com/frain-dev/convoy/datastore" "github.com/frain-dev/convoy/util" @@ -27,6 +29,17 @@ func (ru *RegisterUser) Validate() error { return util.Validate(ru) } +func (ru *RegisterUser) EmailIsDisposable() bool { + ret, err := emailverifier.NewVerifier(). + EnableAutoUpdateDisposable(). + Verify(ru.Email) + if err != nil { + return false + } + + return ret.Disposable +} + type UpdateUser struct { FirstName string `json:"first_name" valid:"required~please provide a first name"` LastName string `json:"last_name" valid:"required~please provide a last name"` diff --git a/go.mod b/go.mod index 75e9afb1ef..21933532d8 100644 --- a/go.mod +++ b/go.mod @@ -296,4 +296,4 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/dop251/goja_nodejs v0.0.0-20230821135201-94e508132562 => github.com/jirevwe/goja_nodejs v0.0.0-20240322142733-81d2fcfb82c1 +replace github.com/dop251/goja_nodejs v0.0.0-20230821135201-94e508132562 => github.com/jirevwe/goja_nodejs v0.0.0-20240322142733-81d2fcfb82c1 \ No newline at end of file diff --git a/go.sum b/go.sum index cfeca4f84d..cd30c863d4 100644 --- a/go.sum +++ b/go.sum @@ -2904,4 +2904,4 @@ sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= tags.cncf.io/container-device-interface v0.7.2 h1:MLqGnWfOr1wB7m08ieI4YJ3IoLKKozEnnNYBtacDPQU= -tags.cncf.io/container-device-interface v0.7.2/go.mod h1:Xb1PvXv2BhfNb3tla4r9JL129ck1Lxv9KuU6eVOfKto= +tags.cncf.io/container-device-interface v0.7.2/go.mod h1:Xb1PvXv2BhfNb3tla4r9JL129ck1Lxv9KuU6eVOfKto= \ No newline at end of file