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
userscollection with theuidsupplied [404]. - Compares the saved hashed password with a hashed version of the
old_passwordsupplied to check if the password is correct [401]. - Checks if the
usernamesupplied is already in use but not for the current record [401]. - Checks if the
new_emailsupplied is already in use but not for the current record [401]. - Checks if the
namesupplied is valid using a regex expression [400]. - Checks if the
usernamesupplied is valid using a regex expression [400]. - Checks if the
new_emailsupplied is valid using a regex expression [400]. - Checks if the
passwordsupplied 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_emaildoes not correspond to theprev_emailof the current record. - Sends a mail to the email address corresponding to
new_emailwith the following link:https://api.konnect.dev/api/v2/user/confirm/${username}/${token}. - Updates the record in the
userscollection with thename,usernameand a hashed version of thepasswordsupplied for those values who are new along withnew_emailwhich, in the case of not already corresponding to the savedprev_emailfield will be saved asemail. - Generates a new
notificationIDand atimestampcorresponding to the current date and time, and creates a new object in thenotificationscollection 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/" }