web: add missing change password logic

This commit is contained in:
Abdullah Atta
2023-07-04 17:11:26 +05:00
committed by Abdullah Atta
parent 8c494642e4
commit 36a99cd64f
2 changed files with 26 additions and 3 deletions

View File

@@ -430,7 +430,13 @@ function getDialogData(type: string) {
export function showPasswordDialog(
type: string,
validate: ({ password }: { password: string }) => boolean | Promise<boolean>
validate: ({
password
}: {
password?: string;
oldPassword?: string;
newPassword?: string;
}) => boolean | Promise<boolean>
) {
const { title, subtitle, positiveButtonText, checks } = getDialogData(type);
return showDialog("PasswordDialog", (Dialog, perform) => (

View File

@@ -22,8 +22,11 @@ import { useStore as useUserStore } from "../../stores/user-store";
import { verifyAccount } from "../../common";
import {
show2FARecoveryCodesDialog,
showMultifactorDialog
showMultifactorDialog,
showPasswordDialog
} from "../../common/dialog-controller";
import { db } from "../../common/db";
import { showToast } from "../../utils/toast";
export const AuthenticationSettings: SettingsGroup[] = [
{
@@ -41,7 +44,21 @@ export const AuthenticationSettings: SettingsGroup[] = [
type: "button",
title: "Change password",
variant: "secondary",
action: () => {}
action: async () => {
const result = await showPasswordDialog(
"change_account_password",
async (data) => {
await db.user?.clearSessions();
return (
db.user?.changePassword(
data.oldPassword,
data.newPassword
) || false
);
}
);
if (result) showToast("success", "Account password changed!");
}
}
]
}