1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-06-19 02:53:17 +02:00

Changing password should confirm the old password

This commit is contained in:
binwiederhier 2023-01-21 20:52:16 -05:00
parent c66a9851cc
commit 88abd8872d
9 changed files with 78 additions and 39 deletions
web/src/app

View file

@ -120,17 +120,20 @@ class AccountApi {
}
}
async changePassword(newPassword) {
async changePassword(currentPassword, newPassword) {
const url = accountPasswordUrl(config.base_url);
console.log(`[AccountApi] Changing account password ${url}`);
const response = await fetch(url, {
method: "POST",
headers: withBearerAuth({}, session.token()),
body: JSON.stringify({
password: newPassword
password: currentPassword,
new_password: newPassword
})
});
if (response.status === 401 || response.status === 403) {
if (response.status === 400) {
throw new CurrentPasswordWrongError();
} else if (response.status === 401 || response.status === 403) {
throw new UnauthorizedError();
} else if (response.status !== 200) {
throw new Error(`Unexpected server response ${response.status}`);
@ -394,6 +397,12 @@ export class AccountCreateLimitReachedError extends Error {
}
}
export class CurrentPasswordWrongError extends Error {
constructor() {
super("Current password incorrect");
}
}
export class UnauthorizedError extends Error {
constructor() {
super("Unauthorized");