added validation check for email and account name
parent
a01d716eed
commit
f05d3392ed
|
@ -56,6 +56,27 @@ func UpdateUser(c *fiber.Ctx) error {
|
|||
return c.Status(fiber.StatusBadRequest).JSON(errValidation)
|
||||
}
|
||||
|
||||
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 {
|
||||
gocnjhelper.LogErrorf("Failed to find user, err: %s", err.Error())
|
||||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
if foundUser.Email != body.Email {
|
||||
if status, err := cnjvalidator.HandleEmailValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.Email); err != nil {
|
||||
return c.SendStatus(status)
|
||||
}
|
||||
}
|
||||
|
||||
accountNameLc := strings.ToLower(body.AccountName)
|
||||
|
||||
if foundUser.AccountNameLc != accountNameLc {
|
||||
if status, err := cnjvalidator.HandleAccountNameValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.AccountName); err != nil {
|
||||
return c.SendStatus(status)
|
||||
}
|
||||
}
|
||||
|
||||
updatedUser := dbstructs.User{
|
||||
Id: params.UserId,
|
||||
Username: body.Username,
|
||||
|
|
Loading…
Reference in New Issue