π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Redo
Manav Rathidf5b46e0d3f0
diff --git a/web/apps/accounts/src/pages/passkeys/index.tsx b/web/apps/accounts/src/pages/passkeys/index.tsxindex 3a13bceb9a..e3be431015 100644--- a/web/apps/accounts/src/pages/passkeys/index.tsx+++ b/web/apps/accounts/src/pages/passkeys/index.tsx@@ -193,7 +193,7 @@ export const AddPasskeyForm: React.FC<AddPasskeyFormProps> = ({margin="normal"disabled={formik.isSubmitting}error={!!formik.errors.value}- // See: Note: [Use space as default TextField helperText]+ // See: [Note: Use space as default TextField helperText]helperText={formik.errors.value ?? " "}label={t("enter_passkey_name")}/>diff --git a/web/apps/photos/src/components/Collections/CollectionShare.tsx b/web/apps/photos/src/components/Collections/CollectionShare.tsxindex a2b64a2ceb..1a8a8795b3 100644--- a/web/apps/photos/src/components/Collections/CollectionShare.tsx+++ b/web/apps/photos/src/components/Collections/CollectionShare.tsx@@ -1631,10 +1631,8 @@ const SetPublicLinkPassword: React.FC<SetPublicLinkPasswordProps> = ({publicShareProp,updatePublicShareURLHelper,}) => {- const savePassword: SingleInputFormProps["onSubmit"] = async (- passphrase,- ) => {- await enablePublicUrlPassword(passphrase);+ const savePassword: SingleInputFormProps["onSubmit"] = async (password) => {+ await enablePublicUrlPassword(password);publicShareProp.passwordEnabled = true;onClose();// The onClose above will close the dialog, but if we return immediatelydiff --git a/web/packages/accounts/components/LoginContents.tsx b/web/packages/accounts/components/LoginContents.tsxindex 24741b5d0b..eae1479346 100644--- a/web/packages/accounts/components/LoginContents.tsx+++ b/web/packages/accounts/components/LoginContents.tsx@@ -103,7 +103,7 @@ export const LoginContents: React.FC<LoginContentsProps> = ({margin="normal"disabled={formik.isSubmitting}error={!!formik.errors.email}- // See: Note: [Use space as default TextField helperText]+ // See: [Note: Use space as default TextField helperText]helperText={formik.errors.email ?? " "}/><Input sx={{ display: "none" }} type="password" value="" />diff --git a/web/packages/accounts/components/NewPasswordForm.tsx b/web/packages/accounts/components/NewPasswordForm.tsxnew file mode 100644index 0000000000..9ece35e20f--- /dev/null+++ b/web/packages/accounts/components/NewPasswordForm.tsx@@ -0,0 +1,169 @@+import { Box, Input, TextField, Typography } from "@mui/material";+import { isWeakPassword } from "ente-accounts/utils/password";+import { LoadingButton } from "ente-base/components/mui/LoadingButton";+import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";+import log from "ente-base/log";+import { useFormik } from "formik";+import { t } from "i18next";+import { useCallback, useState } from "react";+import { Trans } from "react-i18next";+import { PasswordStrengthHint } from "./PasswordStrength";++export interface NewPasswordFormProps {+ /**+ * The email of the user whose password we are setting.+ *+ * This is used to show a hidden input field of type email (and the provided+ * value) to aid password managers to detect and save the new password,+ * associating it with the user's email.+ */+ userEmail: string;+ /**+ * The title of the form's submit button.+ */+ submitButtonTitle: string;+ /**+ * Submission handler. A callback invoked when the submit button is pressed.+ *+ * @param password The new password entered by the user. The form will first+ * check that both of the passwords entered by the user match, and that the+ * password is not too weak.+ *+ * @param setPasswordsFieldError A function that can be called to show an+ * error message below the password fields.+ */+ onSubmit: (+ password: string,+ setPasswordsFieldError: (message: string) => void,+ ) => Promise<void>;+}++/**+ * A form showing two password input fields, a password strength indicator, and+ * a submit button.+ *+ * This form can be used both for the initial setup of the password, and for+ * later changing it.+ */+export const NewPasswordForm: React.FC<NewPasswordFormProps> = ({+ userEmail,+ submitButtonTitle,+ onSubmit,+}) => {+ const [showPassword, setShowPassword] = useState(false);++ const handleToggleShowHidePassword = useCallback(+ () => setShowPassword((show) => !show),+ [],+ );++ const formik = useFormik({+ initialValues: { password: "", confirmPassword: "" },+ onSubmit: async ({ password, confirmPassword }, { setFieldError }) => {+ const setPasswordsFieldError = (message: string) =>+ setFieldError("confirmPassword", message);+ if (!password) {+ setFieldError("password", t("required"));+ return;+ }+ if (!confirmPassword) {+ setFieldError("confirmPassword", t("required"));+ return;+ }++ if (password != confirmPassword) {+ setPasswordsFieldError(t("password_mismatch_error"));+ return;+ }++ try {+ await onSubmit(password, setPasswordsFieldError);+ } catch (e) {+ log.error("Could not set password", e);+ setPasswordsFieldError(t("generic_error"));+ }+ },+ });++ return (+ <form onSubmit={formik.handleSubmit}>+ <Typography variant="small" sx={{ mb: 2, color: "text.muted" }}>+ {t("pick_password_hint")}+ </Typography>++ <Input+ sx={{ display: "none" }}+ name="email"+ type="email"+ autoComplete="username"+ value={userEmail}+ />+ <TextField+ name="password"+ autoComplete="new-password"+ type={showPassword ? "text" : "password"}+ label={t("password")}+ value={formik.values.password}+ onChange={formik.handleChange}+ error={!!formik.errors.password}+ helperText={formik.errors.password}+ disabled={formik.isSubmitting}+ fullWidth+ autoFocus+ slotProps={{+ input: {+ endAdornment: (+ <ShowHidePasswordInputAdornment+ showPassword={showPassword}+ onToggle={handleToggleShowHidePassword}+ />+ ),+ },+ }}+ />+ <TextField+ name="confirmPassword"+ autoComplete="new-password"+ type="password"+ label={t("confirm_password")}+ value={formik.values.confirmPassword}+ onChange={formik.handleChange}+ error={!!formik.errors.confirmPassword}+ // See: [Note: Use space as default TextField helperText]+ //+ // We only do this for the second field for a better+ // visual look. Technically it is possible that the+ // first field also has an error if the user doesn't+ // enter a password there, but that should be rare.+ helperText={formik.errors.confirmPassword ?? " "}+ disabled={formik.isSubmitting}+ fullWidth+ />+ <PasswordStrengthHint password={formik.values.password} />++ <Typography variant="small" sx={{ my: 2 }}>+ <Trans i18nKey={"pick_password_caution"} />+ </Typography>++ <Box sx={{ mt: 4, mb: 2 }}>+ <LoadingButton+ color="accent"+ type="submit"+ loading={formik.isSubmitting}+ disabled={isWeakPassword(formik.values.password)}+ fullWidth+ >+ {submitButtonTitle}+ </LoadingButton>+ {formik.isSubmitting && (+ <Typography+ variant="small"+ sx={{ textAlign: "center", mt: 1, color: "text.muted" }}+ >+ {t("key_generation_in_progress")}+ </Typography>+ )}+ </Box>+ </form>+ );+};diff --git a/web/packages/accounts/components/SetPasswordForm.tsx b/web/packages/accounts/components/SetPasswordForm.tsxdeleted file mode 100644index 90c65b951a..0000000000--- a/web/packages/accounts/components/SetPasswordForm.tsx+++ /dev/null@@ -1,164 +0,0 @@-import { Box, Input, TextField, Typography } from "@mui/material";-import { isWeakPassword } from "ente-accounts/utils/password";-import { LoadingButton } from "ente-base/components/mui/LoadingButton";-import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/PasswordInputAdornment";-import { Formik } from "formik";-import { t } from "i18next";-import { useCallback, useState } from "react";-import { Trans } from "react-i18next";-import * as Yup from "yup";-import { PasswordStrengthHint } from "./PasswordStrength";--export interface SetPasswordFormProps {- userEmail: string;- callback: (- passphrase: string,- setFieldError: (- field: keyof SetPasswordFormValues,- message: string,- ) => void,- ) => Promise<void>;- buttonText: string;-}--export interface SetPasswordFormValues {- passphrase: string;- confirm: string;-}--function SetPasswordForm(props: SetPasswordFormProps) {- const [loading, setLoading] = useState(false);- const [showPassword, setShowPassword] = useState(false);-- const handleToggleShowHidePassword = useCallback(- () => setShowPassword((show) => !show),- [],- );-- const onSubmit = async (- values: SetPasswordFormValues,- {- setFieldError,- }: {- setFieldError: (- field: keyof SetPasswordFormValues,- message: string,- ) => void;- },- ) => {- setLoading(true);- try {- const { passphrase, confirm } = values;- if (passphrase === confirm) {- await props.callback(passphrase, setFieldError);- } else {- setFieldError("confirm", t("password_mismatch_error"));- }- } catch (e) {- const message = e instanceof Error ? e.message : "";- setFieldError("confirm", `${t("generic_error_retry")} ${message}`);- } finally {- setLoading(false);- }- };-- return (- <Formik<SetPasswordFormValues>- initialValues={{ passphrase: "", confirm: "" }}- validationSchema={Yup.object().shape({- passphrase: Yup.string().required(t("required")),- confirm: Yup.string().required(t("required")),- })}- validateOnChange={false}- validateOnBlur={false}- onSubmit={onSubmit}- >- {({ values, errors, handleChange, handleSubmit }) => (- <form noValidate onSubmit={handleSubmit}>- <Typography- variant="small"- sx={{ mb: 2, color: "text.muted" }}- >- {t("pick_password_hint")}- </Typography>-- <Input- sx={{ display: "none" }}- name="email"- id="email"- autoComplete="username"- type="email"- value={props.userEmail}- />- <TextField- fullWidth- name="password"- id="password"- autoComplete="new-password"- type={showPassword ? "text" : "password"}- label={t("password")}- value={values.passphrase}- onChange={handleChange("passphrase")}- error={Boolean(errors.passphrase)}- helperText={errors.passphrase}- autoFocus- disabled={loading}- slotProps={{- input: {- endAdornment: (- <ShowHidePasswordInputAdornment- showPassword={showPassword}- onToggle={handleToggleShowHidePassword}- />- ),- },- }}- />- <TextField- fullWidth- name="confirm-password"- id="confirm-password"- autoComplete="new-password"- type="password"- label={t("confirm_password")}- value={values.confirm}- onChange={handleChange("confirm")}- disabled={loading}- error={Boolean(errors.confirm)}- helperText={errors.confirm}- />- <PasswordStrengthHint password={values.passphrase} />-- <Typography variant="small" sx={{ my: 2 }}>- <Trans i18nKey={"pick_password_caution"} />- </Typography>-- <Box sx={{ mt: 4, mb: 2 }}>- <LoadingButton- fullWidth- color="accent"- type="submit"- loading={loading}- disabled={isWeakPassword(values.passphrase)}- >- {props.buttonText}- </LoadingButton>- {loading && (- <Typography- variant="small"- sx={{- textAlign: "center",- mt: 1,- color: "text.muted",- }}- >- {t("key_generation_in_progress")}- </Typography>- )}- </Box>- </form>- )}- </Formik>- );-}-export default SetPasswordForm;diff --git a/web/packages/accounts/pages/change-email.tsx b/web/packages/accounts/pages/change-email.tsxindex 7e9477add9..058c3abb07 100644--- a/web/packages/accounts/pages/change-email.tsx+++ b/web/packages/accounts/pages/change-email.tsx@@ -127,7 +127,7 @@ const ChangeEmailForm: React.FC = () => {value={formik.values.email}onChange={formik.handleChange}error={!!formik.errors.email}- // See: Note: [Use space as default TextField helperText]+ // See: [Note: Use space as default TextField helperText]//// Also, we only need keep the extra space until the email// has been entered (since the email field is read onlydiff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsxindex fe6ba8345b..7c5029e515 100644--- a/web/packages/accounts/pages/change-password.tsx+++ b/web/packages/accounts/pages/change-password.tsx@@ -3,9 +3,6 @@ import {AccountsPageFooter,AccountsPageTitle,} from "ente-accounts/components/layouts/centered-paper";-import SetPasswordForm, {- type SetPasswordFormProps,-} from "ente-accounts/components/SetPasswordForm";import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";import {changePassword,@@ -20,6 +17,10 @@ import { getData, setData } from "ente-shared/storage/localStorage";import { t } from "i18next";import { useRouter } from "next/router";import React, { useCallback, useEffect, useState } from "react";+import {+ NewPasswordForm,+ type NewPasswordFormProps,+} from "../components/NewPasswordForm";/*** A page that allows a user to reset or change their password.@@ -56,16 +57,15 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {void router.push(appHomeRoute);}, [router]);- const onSubmit: SetPasswordFormProps["callback"] = async (+ const handleSubmit: NewPasswordFormProps["onSubmit"] = async (password,- setFieldError,+ setPasswordsFieldError,) =>changePassword(password).then(redirectToAppHome).catch((e: unknown) => {log.error("Could not change password", e);- setFieldError(- "confirm",+ setPasswordsFieldError(e instanceof Error &&e.message == deriveKeyInsufficientMemoryErrorMessage? t("password_generation_failed")@@ -76,10 +76,10 @@ const PageContents: React.FC<PageContentsProps> = ({ user }) => {return (<AccountsPageContents><AccountsPageTitle>{t("change_password")}</AccountsPageTitle>- <SetPasswordForm+ <NewPasswordFormuserEmail={user.email}- callback={onSubmit}- buttonText={t("change_password")}+ submitButtonTitle={t("change_password")}+ onSubmit={handleSubmit}/>{(getData("showBackButton")?.value ?? true) && (<AccountsPageFooter>diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsxindex ecff1d2ba6..207f0b93b0 100644--- a/web/packages/accounts/pages/generate.tsx+++ b/web/packages/accounts/pages/generate.tsx@@ -4,9 +4,6 @@ import {AccountsPageTitle,} from "ente-accounts/components/layouts/centered-paper";import { RecoveryKey } from "ente-accounts/components/RecoveryKey";-import SetPasswordForm, {- type SetPasswordFormProps,-} from "ente-accounts/components/SetPasswordForm";import { appHomeRoute } from "ente-accounts/services/redirect";import {generateSRPSetupAttributes,@@ -35,6 +32,10 @@ import {import { t } from "i18next";import { useRouter } from "next/router";import { useEffect, useState } from "react";+import {+ NewPasswordForm,+ type NewPasswordFormProps,+} from "../components/NewPasswordForm";const Page: React.FC = () => {const { logout, showMiniDialog } = useBaseContext();@@ -65,18 +66,17 @@ const Page: React.FC = () => {}}, [router]);- const onSubmit: SetPasswordFormProps["callback"] = async (- passphrase,- setFieldError,+ const handleSubmit: NewPasswordFormProps["onSubmit"] = async (+ password,+ setPasswordsFieldError,) => {try {const { masterKey, kek, keyAttributes } =- await generateKeysAndAttributes(passphrase);-+ await generateKeysAndAttributes(password);await putUserKeyAttributes(keyAttributes);await setupSRP(await generateSRPSetupAttributes(kek));await generateAndSaveInteractiveKeyAttributes(- passphrase,+ password,keyAttributes,masterKey,);@@ -85,8 +85,7 @@ const Page: React.FC = () => {setOpenRecoveryKey(true);} catch (e) {log.error("failed to generate password", e);- setFieldError(- "passphrase",+ setPasswordsFieldError(e instanceof Error &&e.message == deriveKeyInsufficientMemoryErrorMessage? t("password_generation_failed")@@ -108,10 +107,10 @@ const Page: React.FC = () => {) : (<AccountsPageContents><AccountsPageTitle>{t("set_password")}</AccountsPageTitle>- <SetPasswordForm+ <NewPasswordFormuserEmail={user.email}- callback={onSubmit}- buttonText={t("set_password")}+ submitButtonTitle={t("set_password")}+ onSubmit={handleSubmit}/><AccountsPageFooter><LinkButton onClick={logout}>{t("go_back")}</LinkButton>diff --git a/web/packages/base/components/SingleInputForm.tsx b/web/packages/base/components/SingleInputForm.tsxindex 5229adc2fd..24c4c24bb8 100644--- a/web/packages/base/components/SingleInputForm.tsx+++ b/web/packages/base/components/SingleInputForm.tsx@@ -143,7 +143,7 @@ export const SingleInputForm: React.FC<SingleInputFormProps> = ({</LoadingButton>);- // Note: [Use space as default TextField helperText]+ // [Note: Use space as default TextField helperText]//// For MUI text fields that use a conditional helperText, e.g. in case of// errors, use an space as the default helperText in the other cases to