add(settings): password changing
This commit is contained in:
@ -67,6 +67,30 @@ class Account
|
||||
}
|
||||
return respondeData['authorize'] || respondeData['detail'] || respondeData['username']?.join(' ') || 'Error.';
|
||||
}
|
||||
|
||||
async updatePassword(currentPassword, newPassword, newPassword2)
|
||||
{
|
||||
const data = {
|
||||
current_password: currentPassword,
|
||||
new_password: newPassword,
|
||||
new_password2: newPassword2
|
||||
};
|
||||
const response = await this.client._put('/api/accounts/update_password', data);
|
||||
if (response.ok)
|
||||
return null;
|
||||
|
||||
const responseData = await response.json();
|
||||
const formatedData = {};
|
||||
if (responseData['current_password'])
|
||||
formatedData['currentPasswordDetail'] = responseData['current_password'];
|
||||
if (responseData['new_password'])
|
||||
formatedData['newPasswordDetail'] = responseData['new_password'];
|
||||
if (responseData['new_password2'])
|
||||
formatedData['newPassword2Detail'] = responseData['new_password2'];
|
||||
if (formatedData == {})
|
||||
formatedData['passwordDetail'] = 'Error';
|
||||
return formatedData;
|
||||
}
|
||||
}
|
||||
|
||||
export { Account };
|
||||
|
@ -144,6 +144,26 @@ class Client
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PUT request with json
|
||||
* @param {String} uri
|
||||
* @param {*} data
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
async _put(uri, data)
|
||||
{
|
||||
let response = await fetch(this._url + uri, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"X-CSRFToken": getCookie("csrftoken"),
|
||||
"Content-Type": "application/json",
|
||||
'Accept-Language': this.lang.currentLang,
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PATCH request with json
|
||||
* @param {String} uri
|
||||
|
Reference in New Issue
Block a user