added validation check for email and account name

alpha
alex 2023-02-24 08:46:46 +01:00
parent a0694e8325
commit 5c07f9c4de
1 changed files with 3 additions and 0 deletions

View File

@ -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)