From 76bb6332c9ed3e9cb6e761f8f78d16888b7efab7 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 25 Jun 2021 08:17:59 +0200 Subject: [PATCH] Added LanguageId to user registration --- routers/api/v1/user/user.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index d40b8cd..843f3b1 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -123,10 +123,11 @@ func NewUser(c *fiber.Ctx) error { now := time.Now() - user.ID = strings.Replace(uuid.New().String(), "-", "", -1) + user.Id = strings.Replace(uuid.New().String(), "-", "", -1) user.Hashtag = input.Hashtag user.Name = input.Username user.Password = string(hashedPassword) + user.Language = 0 user.LastLogin = now user.CreatedAt = now @@ -176,7 +177,7 @@ func NewUser(c *fiber.Ctx) error { log.Infoln("body", body) log.Infoln("StatusCode", resp.StatusCode) - sessionId, err := createUserSession(db, user.ID, c.IP(), string(c.Context().UserAgent())) + sessionId, err := createUserSession(db, user.Id, c.IP(), string(c.Context().UserAgent())) if err != nil { return c.SendStatus(fiber.StatusInternalServerError) @@ -266,7 +267,7 @@ func isUpper(s string) bool { } func isUsernameValid(u string) bool { - if len(u) < int(cfg.Settings.UsernameMinLen) || len(u) > int(cfg.Settings.UsernameMaxLen) { + if len(u) < int(cfg.Settings.Lengths.UsernameMinLen) || len(u) > int(cfg.Settings.Lengths.UsernameMaxLen) { return false } return true @@ -275,14 +276,14 @@ func isUsernameValid(u string) bool { var emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$") func isEmailValid(e string) bool { - if len(e) < int(cfg.Settings.EmailMinLen) || len(e) > int(cfg.Settings.EmailMaxLen) { + if len(e) < int(cfg.Settings.Lengths.EmailMinLen) || len(e) > int(cfg.Settings.Lengths.EmailMaxLen) { return false } return emailRegex.MatchString(e) } func isPasswordValid(p string) bool { - if len(p) < int(cfg.Settings.PasswordMinLen) || len(p) > int(cfg.Settings.PasswordMaxLen) { + if len(p) < int(cfg.Settings.Lengths.PasswordMinLen) || len(p) > int(cfg.Settings.Lengths.PasswordMaxLen) { return false } return true @@ -431,7 +432,7 @@ func Login(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusUnauthorized) } - sessionId, err := createUserSession(database.DB, user.ID, c.IP(), string(c.Context().UserAgent())) + sessionId, err := createUserSession(database.DB, user.Id, c.IP(), string(c.Context().UserAgent())) if err != nil { return c.SendStatus(fiber.StatusInternalServerError)