0
0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2025-09-11 12:24:27 +00:00

add version in back and front #16 / client can ignore global PK #17 / #18 email is now optional

This commit is contained in:
vx3r
2020-02-25 15:56:04 +09:00
parent 2f2b27c499
commit 1d599c401b
9 changed files with 78 additions and 62 deletions

View File

@ -8,16 +8,17 @@ import (
// Client structure
type Client struct {
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Enable bool `json:"enable"`
AllowedIPs []string `json:"allowedIPs"`
Address []string `json:"address"`
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Id string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Enable bool `json:"enable"`
IgnorePersistentKeepalive bool `json:"ignorePersistentKeepalive"`
AllowedIPs []string `json:"allowedIPs"`
Address []string `json:"address"`
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
func (a Client) IsValid() []error {
@ -31,13 +32,11 @@ func (a Client) IsValid() []error {
if len(a.Name) < 2 || len(a.Name) > 40 {
errs = append(errs, fmt.Errorf("name field must be between 2-40 chars"))
}
// check if the email empty
if a.Email == "" {
errs = append(errs, fmt.Errorf("email field is required"))
}
// check if email valid
if !util.RegexpEmail.MatchString(a.Email) {
errs = append(errs, fmt.Errorf("email %s is invalid", a.Email))
// email is not required, but if provided must match regex
if a.Email != "" {
if !util.RegexpEmail.MatchString(a.Email) {
errs = append(errs, fmt.Errorf("email %s is invalid", a.Email))
}
}
// check if the allowedIPs empty
if len(a.AllowedIPs) == 0 {