mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 14:05:23 +00:00
added email format check (#175)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -21,7 +22,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
alphanum = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
emailFormat = regexp.MustCompile("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$")
|
||||||
)
|
)
|
||||||
|
|
||||||
func random(i int) string {
|
func random(i int) string {
|
||||||
@@ -47,6 +49,9 @@ func NewUser(db db.DbService) *User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *User) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
|
func (s *User) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
|
||||||
|
if !emailFormat.MatchString(req.Email) {
|
||||||
|
return errors.BadRequest("create.email-format-check", "email has wrong format")
|
||||||
|
}
|
||||||
if len(req.Password) < 8 {
|
if len(req.Password) < 8 {
|
||||||
return errors.InternalServerError("user.Create.Check", "Password is less than 8 characters")
|
return errors.InternalServerError("user.Create.Check", "Password is less than 8 characters")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user