chore: update user create validator

This commit is contained in:
Steven
2022-08-20 21:03:15 +08:00
parent 734d5f3aed
commit 05a5c59a7e
6 changed files with 88 additions and 18 deletions

View File

@ -1,5 +1,11 @@
package api
import (
"fmt"
"github.com/usememos/memos/common"
)
// Role is the type of a role.
type Role string
@ -47,6 +53,20 @@ type UserCreate struct {
OpenID string
}
func (create UserCreate) Validate() error {
if !common.ValidateEmail(create.Email) {
return fmt.Errorf("invalid email format")
}
if len(create.Email) < 6 {
return fmt.Errorf("email is too short, minimum length is 6")
}
if len(create.Password) < 6 {
return fmt.Errorf("password is too short, minimum length is 6")
}
return nil
}
type UserPatch struct {
ID int