mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 17:58:50 +02:00
ensure supplied email addresses are valid at both the CLI and the API (#108)
This commit is contained in:
parent
39302cd4d5
commit
65d1539182
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/identity"
|
"github.com/openziti-test-kitchen/zrok/rest_client_zrok/identity"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/util"
|
||||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||||
"github.com/openziti/foundation/v2/term"
|
"github.com/openziti/foundation/v2/term"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -33,6 +34,9 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
if !util.IsValidEmail(email) {
|
||||||
|
showError(fmt.Sprintf("'%v' is not a valid email address", email), nil)
|
||||||
|
}
|
||||||
confirm, err := term.Prompt("Confirm Email: ")
|
confirm, err := term.Prompt("Confirm Email: ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package controller
|
package controller
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/go-openapi/runtime/middleware"
|
"github.com/go-openapi/runtime/middleware"
|
||||||
"github.com/openziti-test-kitchen/zrok/controller/store"
|
"github.com/openziti-test-kitchen/zrok/controller/store"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/rest_model_zrok"
|
||||||
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
|
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/identity"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,6 +22,10 @@ func (self *createAccountHandler) Handle(params identity.CreateAccountParams) mi
|
|||||||
logrus.Errorf("missing email")
|
logrus.Errorf("missing email")
|
||||||
return identity.NewCreateAccountBadRequest().WithPayload("missing email")
|
return identity.NewCreateAccountBadRequest().WithPayload("missing email")
|
||||||
}
|
}
|
||||||
|
if !util.IsValidEmail(params.Body.Email) {
|
||||||
|
logrus.Errorf("'%v' is not a valid email address", params.Body.Email)
|
||||||
|
return identity.NewCreateAccountBadRequest().WithPayload(rest_model_zrok.ErrorMessage(fmt.Sprintf("'%v' is not a valid email address", params.Body.Email)))
|
||||||
|
}
|
||||||
logrus.Infof("received account request for email '%v'", params.Body.Email)
|
logrus.Infof("received account request for email '%v'", params.Body.Email)
|
||||||
|
|
||||||
token, err := createToken()
|
token, err := createToken()
|
||||||
|
12
util/email.go
Normal file
12
util/email.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||||
|
|
||||||
|
func IsValidEmail(e string) bool {
|
||||||
|
if len(e) < 3 && len(e) > 254 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return emailRegex.MatchString(e)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user