From 9f31112e1bd96372e3b85ddac16332dc4f224e89 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 31 Jan 2025 14:00:54 -0500 Subject: [PATCH] reset password micro-app (#840) --- ui100/src/App.tsx | 2 + ui100/src/Register.tsx | 4 +- ui100/src/ResetPassword.tsx | 170 ++++++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 ui100/src/ResetPassword.tsx diff --git a/ui100/src/App.tsx b/ui100/src/App.tsx index 19649fc6..b7442d6a 100644 --- a/ui100/src/App.tsx +++ b/ui100/src/App.tsx @@ -6,6 +6,7 @@ import {User} from "./model/user.ts"; import useApiConsoleStore from "./model/store.ts"; import ForgotPassword from "./ForgotPassword.tsx"; import Register from "./Register.tsx"; +import ResetPassword from "./ResetPassword.tsx"; const App = () => { const user = useApiConsoleStore((state) => state.user); @@ -46,6 +47,7 @@ const App = () => { } /> } /> + } /> ); diff --git a/ui100/src/Register.tsx b/ui100/src/Register.tsx index af355ba6..3b7af5fc 100644 --- a/ui100/src/Register.tsx +++ b/ui100/src/Register.tsx @@ -1,5 +1,5 @@ import {Box, Button, Checkbox, Container, FormControlLabel, Grid2, TextField, Typography} from "@mui/material"; -import zroket from "./assets/zrok-1.0.0-rocket-purple.svg"; +import zrokLogo from "./assets/zrok-1.0.0-rocket-purple.svg"; import {useParams} from "react-router"; import {useFormik} from "formik"; import * as Yup from 'yup'; @@ -235,7 +235,7 @@ const Register = () => { - +

z r o k

{component}
diff --git a/ui100/src/ResetPassword.tsx b/ui100/src/ResetPassword.tsx new file mode 100644 index 00000000..3caeb4a3 --- /dev/null +++ b/ui100/src/ResetPassword.tsx @@ -0,0 +1,170 @@ +import {useEffect, useState} from "react"; +import {Link, useParams} from "react-router"; +import {useFormik} from "formik"; +import * as Yup from "yup"; +import {Box, Button, Container, TextField, Typography} from "@mui/material"; +import zrokLogo from "./assets/zrok-1.0.0-rocket-purple.svg"; +import {AccountApi} from "./api"; + +interface ResetPasswordFormProps { + resetPassword: (v) => void; +} + +const ResetPasswordForm = ({ resetPassword }: ResetPasswordFormProps) => { + const form = useFormik({ + initialValues: { + password: "", + confirm: "", + }, + onSubmit: v => { + resetPassword(v); + }, + validationSchema: Yup.object({ + password: Yup.string() + .min(8, "Password must be at least 8 characters") + .max(64, "Password must be less than 64 characters") + .matches( + /^.*[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?].*$/, + "Password requires at least one special character" + ) + .matches( + /^.*[a-z].*$/, + "Password requires at least one lowercase letter" + ) + .matches( + /^.*[A-Z].*$/, + "Password requires at least one uppercase letter" + ) + .required("Password is required"), + confirm: Yup.string() + .required("Please confirm your new password") + .test("password-matches", "Password confirmation does not match", v => v === form.values.password) + }) + }); + + return ( +
+

New Password

+ + + + + ); +} + +const ResetComplete = () => { + return ( + + + + +

Password Changed...

+
+
+
+ + + + You can use your new password to log into the console here: + + + + + {window.location.origin} + + + +
+ ); +} + +const ResetFailed = () => { + return ( + + + + +

Password Reset Failed!

+
+
+
+ + + + Your password change request failed. This might be due to an invalid password reset token. + + + + + Please use the forgot password link below to create a new password reset request: + + + + + Forgot Password? + + + +
+ ); +} + +const ResetPassword = () => { + const { resetToken } = useParams(); + const [component, setComponent] = useState(); + + const doReset = (v) => { + new AccountApi().resetPassword({body: {token: resetToken, password: v.password}}) + .then(() => { + setComponent(); + }) + .catch(e => { + setComponent(); + console.log("doReset", e); + }); + } + + useEffect(() => { + setComponent(); + }, [resetToken]); + + return ( + + + + +

z r o k

+ {component} +
+
+
+ ) +} + +export default ResetPassword; \ No newline at end of file