added validation check for email and account name
parent
a0694e8325
commit
5c07f9c4de
|
@ -56,6 +56,7 @@ func UpdateUser(c *fiber.Ctx) error {
|
||||||
return c.Status(fiber.StatusBadRequest).JSON(errValidation)
|
return c.Status(fiber.StatusBadRequest).JSON(errValidation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get requested user from db
|
||||||
foundUser := dbstructs.User{Id: params.UserId}
|
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 {
|
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)
|
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 foundUser.Email != body.Email {
|
||||||
if status, err := cnjvalidator.HandleEmailValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.Email); err != nil {
|
if status, err := cnjvalidator.HandleEmailValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.Email); err != nil {
|
||||||
return c.SendStatus(status)
|
return c.SendStatus(status)
|
||||||
|
@ -71,6 +73,7 @@ func UpdateUser(c *fiber.Ctx) error {
|
||||||
|
|
||||||
accountNameLc := strings.ToLower(body.AccountName)
|
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 foundUser.AccountNameLc != accountNameLc {
|
||||||
if status, err := cnjvalidator.HandleAccountNameValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.AccountName); err != nil {
|
if status, err := cnjvalidator.HandleAccountNameValidation(scylladb.Session, scylladb.Cluster.Keyspace, body.AccountName); err != nil {
|
||||||
return c.SendStatus(status)
|
return c.SendStatus(status)
|
||||||
|
|
Loading…
Reference in New Issue