π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Require password verification before opening Legacy
Neeraj Guptab36b43845e5f
diff --git a/web/apps/locker/src/components/LockerAuthenticateUser.tsx b/web/apps/locker/src/components/LockerAuthenticateUser.tsxnew file mode 100644index 0000000000..30a4e31377--- /dev/null+++ b/web/apps/locker/src/components/LockerAuthenticateUser.tsx@@ -0,0 +1,93 @@+import { VerifyMasterPasswordForm } from "ente-accounts-rs/components/VerifyMasterPasswordForm";+import { checkSessionValidity } from "ente-accounts-rs/services/session";+import {+ ensureLocalUser,+ ensureSavedKeyAttributes,+ type KeyAttributes,+ type LocalUser,+} from "ente-accounts-rs/services/user";+import {+ TitledMiniDialog,+ type MiniDialogAttributes,+} from "ente-base/components/MiniDialog";+import type { ModalVisibilityProps } from "ente-base/components/utils/modal";+import { useBaseContext } from "ente-base/context";+import log from "ente-base/log";+import { t } from "i18next";+import React, { useCallback, useEffect, useState } from "react";++type LockerAuthenticateUserProps = ModalVisibilityProps & {+ onAuthenticate: () => void;+};++export const LockerAuthenticateUser: React.FC<LockerAuthenticateUserProps> = ({+ open,+ onClose,+ onAuthenticate,+}) => (+ <TitledMiniDialog open={open} onClose={onClose} title={t("password")}>+ <LockerAuthenticateUserDialogContents+ {...{ open, onClose, onAuthenticate }}+ />+ </TitledMiniDialog>+);++const LockerAuthenticateUserDialogContents: React.FC<+ LockerAuthenticateUserProps+> = ({ open, onClose, onAuthenticate }) => {+ const { logout, showMiniDialog } = useBaseContext();++ const [user, setUser] = useState<LocalUser | undefined>();+ const [keyAttributes, setKeyAttributes] = useState<+ KeyAttributes | undefined+ >();++ const validateSession = useCallback(async () => {+ try {+ const session = await checkSessionValidity();+ if (session.status !== "valid") {+ onClose();+ showMiniDialog(+ passwordChangedElsewhereDialogAttributes(logout),+ );+ }+ } catch (error) {+ log.warn("Ignoring error when determining session validity", error);+ }+ }, [logout, onClose, showMiniDialog]);++ useEffect(() => {+ if (!open) {+ return;+ }++ setUser(ensureLocalUser());+ setKeyAttributes(ensureSavedKeyAttributes());+ void validateSession();+ }, [open, validateSession]);++ if (!user || !keyAttributes) {+ return <></>;+ }++ return (+ <VerifyMasterPasswordForm+ userEmail={user.email}+ keyAttributes={keyAttributes}+ submitButtonTitle={t("authenticate")}+ onVerify={() => {+ onAuthenticate();+ onClose();+ }}+ />+ );+};++const passwordChangedElsewhereDialogAttributes = (+ onLogin: () => void,+): MiniDialogAttributes => ({+ title: t("password_changed_elsewhere"),+ message: t("password_changed_elsewhere_message"),+ continue: { text: t("login"), action: onLogin },+ cancel: false,+});diff --git a/web/apps/locker/src/components/LockerSidebar.tsx b/web/apps/locker/src/components/LockerSidebar.tsxindex be0193621a..91dd73fe6f 100644--- a/web/apps/locker/src/components/LockerSidebar.tsx+++ b/web/apps/locker/src/components/LockerSidebar.tsx@@ -24,6 +24,7 @@ import type { LockerCollection } from "types";import { visibleLockerCollections } from "types";import { LockerAboutDrawer } from "./LockerAboutDrawer";import { LockerAccountDrawer } from "./LockerAccountDrawer";+import { LockerAuthenticateUser } from "./LockerAuthenticateUser";import { LockerSidebarCardButton } from "./LockerSidebarCardButton";import { LockerSidebarDrawer } from "./LockerSidebarShell";import { LockerSocialFooter } from "./LockerSocialFooter";@@ -86,6 +87,8 @@ export const LockerSidebar: React.FC<LockerSidebarProps> = ({0,);const [isAccountOpen, setIsAccountOpen] = useState(false);+ const [isLegacyAuthenticateOpen, setIsLegacyAuthenticateOpen] =+ useState(false);const [isLegacyOpen, setIsLegacyOpen] = useState(false);const [isSupportOpen, setIsSupportOpen] = useState(false);const [isAboutOpen, setIsAboutOpen] = useState(false);@@ -128,6 +131,7 @@ export const LockerSidebar: React.FC<LockerSidebarProps> = ({useEffect(() => {if (!open) {setIsAccountOpen(false);+ setIsLegacyAuthenticateOpen(false);setIsLegacyOpen(false);setIsSupportOpen(false);setIsAboutOpen(false);@@ -388,7 +392,9 @@ export const LockerSidebar: React.FC<LockerSidebarProps> = ({icon={FavouriteIcon}label="Legacy"endIcon={<ChevronRightIcon />}- onClick={() => setIsLegacyOpen(true)}+ onClick={() =>+ setIsLegacyAuthenticateOpen(true)+ }/><LockerSidebarCardButtonicon={HelpCircleIcon}@@ -446,6 +452,11 @@ export const LockerSidebar: React.FC<LockerSidebarProps> = ({onRootClose={onClose}suggestedUsers={legacySuggestedUsers}/>+ <LockerAuthenticateUser+ open={isLegacyAuthenticateOpen}+ onClose={() => setIsLegacyAuthenticateOpen(false)}+ onAuthenticate={() => setIsLegacyOpen(true)}+ /><LockerSupportDraweropen={isSupportOpen}onClose={() => setIsSupportOpen(false)}