Link Search Menu Expand Document

Update

/api/v2/user/update

Post

users

notifications


Purpose

To allow an user to update some of his / her credentials.

Body Content [input]

{
    uid: string,
    name: string,
    username: string,
    new_email: string,
    password: string,
    old_password: string
}

Returns if valid [output]

{
    message: string,
    error: 0
}

What the API does

  • Checks if there is a record in the users collection with the uid supplied [404].
  • Compares the saved hashed password with a hashed version of the old_password supplied to check if the password is correct [401].
  • Checks if the username supplied is already in use but not for the current record [401].
  • Checks if the new_email supplied is already in use but not for the current record [401].
  • Checks if the name supplied is valid using a regex expression [400].
  • Checks if the username supplied is valid using a regex expression [400].
  • Checks if the new_email supplied is valid using a regex expression [400].
  • Checks if the password supplied contains at least 1 lowercase alphabet, 1 uppercase alphabet, 1 numerical character and that it is at least 8 characters long [400].
  • Generates and saves a token if new_email does not correspond to the prev_email of the current record.
  • Sends a mail to the email address corresponding to new_email with the following link: https://api.konnect.dev/api/v2/user/confirm/${username}/${token}.
  • Updates the record in the users collection with the name, username and a hashed version of the password supplied for those values who are new along with new_email which, in the case of not already corresponding to the saved prev_email field will be saved as email.
  • Generates a new notificationID and a timestamp corresponding to the current date and time, and creates a new object in the notifications collection with the following data:
    {
      uid: uid,
      notificationID: notificationID,
      content: "Details about your account just got updated",
      profileID: uid,
      type: "account_update",
      created_on: timestamp,
      read: false,
      redirect: "/profile/"
    }