import * as React from "react";
import { useState } from "react";
import { TextField, Button, Box, Typography } from "@mui/material";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutlineOutlined";
import { NavLink } from "react-router-dom";
import { useTranslation } from "react-i18next";
import accountApi from "../app/AccountApi";
import AvatarBox from "./AvatarBox";
import routes from "./routes";
// PasswordResetRequest is the standalone "request a password reset" page, reached from the login page.
// It collects a username/email and asks the server to email a reset link. The response is uniform,
// so the page always shows the same confirmation. Completing the reset happens on the separate
// PasswordReset landing page that the emailed link points to.
const PasswordResetRequest = () => {
const { t } = useTranslation();
const [identifier, setIdentifier] = useState("");
const [sending, setSending] = useState(false);
const [sent, setSent] = useState(false);
const handleSubmit = async (event) => {
event.preventDefault();
try {
setSending(true);
await accountApi.requestPasswordReset(identifier);
} catch (e) {
console.log(`[PasswordResetRequest] Request failed`, e);
} finally {
setSending(false);
setSent(true); // Uniform outcome regardless of success/failure (enumeration-safe)
}
};
if (!config.enable_reset_password) {
return (
{t("reset_password_disabled")}
{t("reset_password_back_to_login")}
);
}
if (sent) {
return (
{t("reset_password_sent_title")}
{t("reset_password_sent_description")}
{t("reset_password_back_to_login")}
);
}
return (
{t("reset_password_request_title")}
{t("reset_password_request_description")}
{t("reset_password_request_primary_required")}
setIdentifier(ev.target.value.trim())}
autoFocus
/>
{config.enable_login && (
{t("reset_password_back_to_login")}
)}
);
};
export default PasswordResetRequest;