From 5c07f9c4dee3a81bcd3d5322c54d40af0ffb4c3f Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 24 Feb 2023 08:46:46 +0100 Subject: [PATCH] added validation check for email and account name --- routers/api/v1/user/user.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index a729c30..4b610e3 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -56,6 +56,7 @@ func UpdateUser(c *fiber.Ctx) error { return c.Status(fiber.StatusBadRequest).JSON(errValidation) } + // get requested user from db foundUser := dbstructs.User{Id: params.UserId} if err := scylladb.Session.Query(gocnjhelper.DbMUsers.Get("email", "account_name_lc", "last_account_name_lc")).BindStruct(foundUser).GetRelease(&foundUser); err != nil { @@ -63,6 +64,7 @@ func UpdateUser(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusInternalServerError) } + // check whether the email in the requested has been changed in relation to the user if foundUser.Email != body.Email { if status, err := cnjvalidator.HandleEmailValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.Email); err != nil { return c.SendStatus(status) @@ -71,6 +73,7 @@ func UpdateUser(c *fiber.Ctx) error { accountNameLc := strings.ToLower(body.AccountName) + // check whether the account name in the requested has been changed in relation to the user if foundUser.AccountNameLc != accountNameLc { if status, err := cnjvalidator.HandleAccountNameValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.AccountName); err != nil { return c.SendStatus(status)