1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: validate email addresses with dns

This commit is contained in:
Ferdinand Mütsch
2023-01-02 15:14:49 +01:00
parent ef5b49ebd8
commit a1444bca8c
4 changed files with 75 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"crypto/md5"
"fmt"
conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/utils"
"regexp"
"strings"
"time"
@ -190,8 +191,9 @@ func ValidatePassword(password string) bool {
return len(password) >= 6
}
// ValidateEmail checks that, if an email address is given, it has proper syntax and (if not in dev mode) an MX record exists for the domain
func ValidateEmail(email string) bool {
return email == "" || mailRegex.Match([]byte(email))
return email == "" || (mailRegex.Match([]byte(email)) && (conf.Get().IsDev() || utils.CheckEmailMX(email)))
}
func ValidateTimezone(tz string) bool {