Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update(photos):credentials-page-updated

Aswin Asok8577b23e0eb6
diff --git a/web/apps/photos/src/components/auth/CredentialsForm.tsx b/web/apps/photos/src/components/auth/CredentialsForm.tsx
new file mode 100644
index 0000000000..3257c7fa54
--- /dev/null
+++ b/web/apps/photos/src/components/auth/CredentialsForm.tsx
@@ -0,0 +1,62 @@
+import { styled } from "@mui/material";
+import type { CredentialsPresentationProps } from "ente-accounts/pages/credentials";
+import { pt } from "ente-base/i18n";
+import { t } from "i18next";
+import type React from "react";
+import { FormFooter } from "./FormFooter";
+import { ScreenHeader } from "./ScreenHeader";
+import { TextLink } from "./TextLink";
+
+export function CredentialsForm({
+ userEmail,
+ host,
+ passwordForm,
+ onRecover,
+ onChangeEmail,
+}: CredentialsPresentationProps): React.JSX.Element {
+ return (
+ <>
+ <ScreenHeader
+ title={t("enter_password")}
+ subtitle={
+ <>
+ {pt("Signing in as ")}
+ <Email>{userEmail}</Email>
+ </>
+ }
+ />
+ {passwordForm}
+ <FormFooter>
+ <FooterLinks>
+ <TextLink onClick={onRecover}>
+ {t("forgot_password")}
+ </TextLink>
+ <TextLink onClick={onChangeEmail}>
+ {t("change_email")}
+ </TextLink>
+ </FooterLinks>
+ <Host>{host ?? ""}</Host>
+ </FormFooter>
+ </>
+ );
+}
+
+const Email = styled("strong")({
+ color: "var(--photos-auth-text)",
+ wordBreak: "break-word",
+});
+
+const FooterLinks = styled("div")({
+ display: "flex",
+ justifyContent: "space-between",
+ gap: "16px",
+});
+
+const Host = styled("div")({
+ minHeight: "16px",
+ textAlign: "center",
+ fontSize: "12px",
+ fontWeight: 500,
+ lineHeight: "16px",
+ color: "var(--photos-auth-text-faint)",
+});
diff --git a/web/apps/photos/src/components/auth/PasswordForm.tsx b/web/apps/photos/src/components/auth/PasswordForm.tsx
new file mode 100644
index 0000000000..cce1dbb03a
--- /dev/null
+++ b/web/apps/photos/src/components/auth/PasswordForm.tsx
@@ -0,0 +1,54 @@
+import { styled } from "@mui/material";
+import type { VerifyMasterPasswordPresentationProps } from "ente-accounts/components/VerifyMasterPasswordForm";
+import { t } from "i18next";
+import type React from "react";
+import { Button } from "./Button";
+import { Form } from "./Form";
+import { FormFields } from "./FormFields";
+import { FormFooter } from "./FormFooter";
+import { TextField } from "./TextField";
+
+export function PasswordForm({
+ userEmail,
+ password,
+ passwordError,
+ isSubmitting,
+ submitButtonTitle,
+ onPasswordChange,
+ onSubmit,
+}: VerifyMasterPasswordPresentationProps): React.JSX.Element {
+ return (
+ <Form onSubmit={onSubmit}>
+ <HiddenEmail
+ name="email"
+ type="email"
+ autoComplete="username"
+ value={userEmail}
+ readOnly
+ tabIndex={-1}
+ />
+ <FormFields>
+ <TextField
+ name="password"
+ value={password}
+ onChange={onPasswordChange}
+ type="password"
+ autoComplete="current-password"
+ label={t("password")}
+ showPasswordToggle
+ autoFocus
+ disabled={isSubmitting}
+ error={Boolean(passwordError)}
+ helperText={passwordError}
+ />
+ </FormFields>
+ <FormFooter>
+ <Button fullWidth type="submit" loading={isSubmitting}>
+ {submitButtonTitle}
+ </Button>
+ </FormFooter>
+ </Form>
+ );
+}
+
+const HiddenEmail = styled("input")({ display: "none" });
diff --git a/web/apps/photos/src/pages/credentials.tsx b/web/apps/photos/src/pages/credentials.tsx
index d087f6ab10..892c8691dd 100644
--- a/web/apps/photos/src/pages/credentials.tsx
+++ b/web/apps/photos/src/pages/credentials.tsx
@@ -1,10 +1,24 @@
+import { CredentialsForm } from "@/components/auth/CredentialsForm";
import { PasskeyVerificationForm } from "@/components/auth/PasskeyVerificationForm";
+import { PasswordForm } from "@/components/auth/PasswordForm";
import { PhotosAuthShell } from "@/components/PhotosAuthShell";
import { featureFlags } from "@/featureFlags";
import type { VerifyingPasskeyPresentationProps } from "ente-accounts/components/LoginComponents";
-import AccountsCredentialsPage from "ente-accounts/pages/credentials";
+import AccountsCredentialsPage, {
+ type CredentialsPresentationProps,
+} from "ente-accounts/pages/credentials";
import type React from "react";
+function CredentialsPresentation(
+ props: CredentialsPresentationProps,
+): React.JSX.Element {
+ return (
+ <PhotosAuthShell>
+ <CredentialsForm {...props} />
+ </PhotosAuthShell>
+ );
+}
+
function PasskeyPresentation(
props: VerifyingPasskeyPresentationProps,
): React.JSX.Element {
@@ -21,7 +35,11 @@ function CredentialsPage(): React.JSX.Element {
}
return (
- <AccountsCredentialsPage passkeyPresentation={PasskeyPresentation} />
+ <AccountsCredentialsPage
+ presentation={CredentialsPresentation}
+ passwordPresentation={PasswordForm}
+ passkeyPresentation={PasskeyPresentation}
+ />
);
}
diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
index 6f5535de84..c277acf677 100644
--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
@@ -10,7 +10,19 @@ import { ShowHidePasswordInputAdornment } from "ente-base/components/mui/Passwor
import log from "ente-base/log";
import { useFormik } from "formik";
import { t } from "i18next";
-import { useCallback, useState } from "react";
+import { useCallback, useState, type ComponentType } from "react";
+
+export interface VerifyMasterPasswordPresentationProps {
+ userEmail: string;
+ password: string;
+ passwordError: string | undefined;
+ isSubmitting: boolean;
+ submitButtonTitle: string;
+ onPasswordChange: React.ChangeEventHandler<
+ HTMLInputElement | HTMLTextAreaElement
+ >;
+ onSubmit: React.SubmitEventHandler<HTMLFormElement>;
+}
export interface VerifyMasterPasswordFormProps {
userEmail: string;
@@ -27,6 +39,7 @@ export interface VerifyMasterPasswordFormProps {
keyAttributes: KeyAttributes,
password: string,
) => void;
+ presentation?: ComponentType<VerifyMasterPasswordPresentationProps>;
}
export const VerifyMasterPasswordForm: React.FC<
@@ -38,6 +51,7 @@ export const VerifyMasterPasswordForm: React.FC<
getKeyAttributes,
onVerify,
submitButtonTitle,
+ presentation: Presentation,
}) => {
const [showPassword, setShowPassword] = useState(false);
@@ -139,6 +153,20 @@ export const VerifyMasterPasswordForm: React.FC<
onVerify(key, kek, keyAttributes, password);
};
+ if (Presentation) {
+ return (
+ <Presentation
+ userEmail={userEmail}
+ password={formik.values.password}
+ passwordError={formik.errors.password}
+ isSubmitting={formik.isSubmitting}
+ submitButtonTitle={submitButtonTitle}
+ onPasswordChange={formik.handleChange}
+ onSubmit={formik.handleSubmit}
+ />
+ );
+ }
+
return (
<form onSubmit={formik.handleSubmit}>
<Input
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index 5656239d79..ba8bb3c601 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -11,6 +11,7 @@ import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/se
import {
VerifyMasterPasswordForm,
type VerifyMasterPasswordFormProps,
+ type VerifyMasterPasswordPresentationProps,
} from "ente-accounts/components/VerifyMasterPasswordForm";
import {
savedIsFirstLogin,
@@ -59,16 +60,37 @@ import { useBaseContext } from "ente-base/context";
import { isDevBuild } from "ente-base/env";
import { clearLocalStorage } from "ente-base/local-storage";
import log from "ente-base/log";
+import { customAPIHost } from "ente-base/origins";
import { saveAuthToken, savedAuthToken } from "ente-base/token";
import { t } from "i18next";
import { useRouter } from "next/router";
-import { useCallback, useEffect, useState, type ComponentType } from "react";
+import {
+ useCallback,
+ useEffect,
+ useState,
+ type ComponentType,
+ type ReactNode,
+} from "react";
+
+export interface CredentialsPresentationProps {
+ userEmail: string;
+ host: string | undefined;
+ passwordForm: ReactNode;
+ onRecover: () => void;
+ onChangeEmail: () => void;
+}
export interface CredentialsPageProps {
+ presentation?: ComponentType<CredentialsPresentationProps>;
+ passwordPresentation?: ComponentType<VerifyMasterPasswordPresentationProps>;
passkeyPresentation?: ComponentType<VerifyingPasskeyPresentationProps>;
}
-const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
+const Page: React.FC<CredentialsPageProps> = ({
+ presentation: Presentation,
+ passwordPresentation,
+ passkeyPresentation,
+}) => {
const { logout, showMiniDialog } = useBaseContext();
const [userEmail, setUserEmail] = useState<string>("");
@@ -84,6 +106,7 @@ const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
const [sessionValidityCheck, setSessionValidityCheck] = useState<
Promise<void> | undefined
>(undefined);
+ const [host, setHost] = useState<string | undefined>();
const {
secondFactorChoiceProps,
@@ -92,6 +115,10 @@ const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
const router = useRouter();
+ useEffect(() => {
+ if (Presentation) void customAPIHost().then(setHost);
+ }, [Presentation]);
+
const validateSession = useCallback(async () => {
const showSessionExpiredDialog = () =>
showMiniDialog(sessionExpiredDialogAttributes(logout));
@@ -305,6 +332,10 @@ const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
}
}, [passkeyVerificationData]);
+ const handleRecover = useCallback(() => {
+ void router.push("/recover");
+ }, [router]);
+
if (!userEmail) {
return <LoadingIndicator />;
}
@@ -334,26 +365,52 @@ const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
}
return (
- <AccountsPageContents>
- <PasswordHeader caption={userEmail} />
- <VerifyMasterPasswordForm
- {...{
- userEmail,
- keyAttributes,
- getKeyAttributes,
- srpAttributes,
- }}
- submitButtonTitle={t("sign_in")}
- onVerify={handleVerifyMasterPassword}
- />
- <AccountsPageFooterWithHost>
- <LinkButton onClick={() => router.push("/recover")}>
- {t("forgot_password")}
- </LinkButton>
- <LinkButton onClick={logout}>{t("change_email")}</LinkButton>
- </AccountsPageFooterWithHost>
+ <>
+ {Presentation ? (
+ <Presentation
+ userEmail={userEmail}
+ host={host}
+ passwordForm={
+ <VerifyMasterPasswordForm
+ {...{
+ userEmail,
+ keyAttributes,
+ getKeyAttributes,
+ srpAttributes,
+ }}
+ submitButtonTitle={t("sign_in")}
+ onVerify={handleVerifyMasterPassword}
+ presentation={passwordPresentation}
+ />
+ }
+ onRecover={handleRecover}
+ onChangeEmail={logout}
+ />
+ ) : (
+ <AccountsPageContents>
+ <PasswordHeader caption={userEmail} />
+ <VerifyMasterPasswordForm
+ {...{
+ userEmail,
+ keyAttributes,
+ getKeyAttributes,
+ srpAttributes,
+ }}
+ submitButtonTitle={t("sign_in")}
+ onVerify={handleVerifyMasterPassword}
+ />
+ <AccountsPageFooterWithHost>
+ <LinkButton onClick={handleRecover}>
+ {t("forgot_password")}
+ </LinkButton>
+ <LinkButton onClick={logout}>
+ {t("change_email")}
+ </LinkButton>
+ </AccountsPageFooterWithHost>
+ </AccountsPageContents>
+ )}
<SecondFactorChoice {...secondFactorChoiceProps} />
- </AccountsPageContents>
+ </>
);
};