mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 13:44:17 +08:00
add email validation
This commit is contained in:
parent
b3a9ffd260
commit
30309a4f9a
2 changed files with 10 additions and 0 deletions
|
@ -206,6 +206,10 @@ func inviteUsers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
for _, inviteeEmail := range inviteReq.UserEmails {
|
||||
// check if user with email exists, then ignore
|
||||
if !email.IsValid(inviteeEmail) {
|
||||
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("invalid email "+inviteeEmail), "badrequest"))
|
||||
return
|
||||
}
|
||||
_, err := logic.GetUser(inviteeEmail)
|
||||
if err == nil {
|
||||
// user exists already, so ignore
|
||||
|
|
|
@ -2,6 +2,7 @@ package email
|
|||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
)
|
||||
|
@ -52,3 +53,8 @@ type Notification struct {
|
|||
func GetClient() (e EmailSender) {
|
||||
return client
|
||||
}
|
||||
|
||||
func IsValid(email string) bool {
|
||||
emailRegex := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
|
||||
return emailRegex.MatchString(email)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue