mirror of
https://github.com/openziti/zrok.git
synced 2024-11-28 11:04:04 +01: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"
|
||||
"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/util"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/openziti/foundation/v2/term"
|
||||
"github.com/spf13/cobra"
|
||||
@ -33,6 +34,9 @@ func (cmd *inviteCommand) run(_ *cobra.Command, _ []string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !util.IsValidEmail(email) {
|
||||
showError(fmt.Sprintf("'%v' is not a valid email address", email), nil)
|
||||
}
|
||||
confirm, err := term.Prompt("Confirm Email: ")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -1,9 +1,12 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"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/util"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -19,6 +22,10 @@ func (self *createAccountHandler) Handle(params identity.CreateAccountParams) mi
|
||||
logrus.Errorf("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)
|
||||
|
||||
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…
Reference in New Issue
Block a user