diff --git a/Client/src/Components/Alert/index.css b/Client/src/Components/Alert/index.css index c65bfa38c..4a1a11c67 100644 --- a/Client/src/Components/Alert/index.css +++ b/Client/src/Components/Alert/index.css @@ -2,6 +2,8 @@ margin: 0; width: fit-content; } -.alert, .alert button{ +.alert, +.alert button, +.alert .MuiTypography-root { font-size: var(--env-var-font-size-medium); -} \ No newline at end of file +} diff --git a/Client/src/Components/Alert/index.jsx b/Client/src/Components/Alert/index.jsx index 3fa0d82ab..61c3b6bc3 100644 --- a/Client/src/Components/Alert/index.jsx +++ b/Client/src/Components/Alert/index.jsx @@ -1,6 +1,6 @@ import PropTypes from "prop-types"; import { useTheme } from "@emotion/react"; -import { Box, IconButton, Stack } from "@mui/material"; +import { Box, IconButton, Stack, Typography } from "@mui/material"; import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined"; import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined"; @@ -50,9 +50,17 @@ const Alert = ({ variant, title, body, isToast, hasIcon = true, onClick }) => { }} > {hasIcon && {icon}} - - {title && {title}} - {body && {body}} + + {title && ( + + {title} + + )} + {body && ( + + {body} + + )} {hasIcon && isToast && ( { "&:focus": { outline: "none", }, + "& .MuiTouchRipple-root": { + pointerEvents: "none", + display: "none", + }, ...sx, }} > diff --git a/Client/src/Components/Check/Check.jsx b/Client/src/Components/Check/Check.jsx index 6daf90aa1..501d0a344 100644 --- a/Client/src/Components/Check/Check.jsx +++ b/Client/src/Components/Check/Check.jsx @@ -1,6 +1,8 @@ import "./check.css"; -import React from "react"; -import CheckGrey from "../../assets/Images/Check-icon-grey.png"; +import PropTypes from "prop-types"; +import CheckGrey from "../../assets/icons/check.svg?react"; +import { Stack, Typography } from "@mui/material"; +import { useTheme } from "@emotion/react"; /** * `Check` is a functional React component that displays a check icon and a label. @@ -8,6 +10,7 @@ import CheckGrey from "../../assets/Images/Check-icon-grey.png"; * @component * @param {Object} props - The properties that define the `Check` component. * @param {string} props.text - The text to be displayed as the label next to the check icon. + * @param {'info' | 'error' | 'success'} [props.variant='info'] - The variant of the check component, affecting its styling. * * @example * // To use this component, import it and use it in your JSX like this: @@ -15,14 +18,30 @@ import CheckGrey from "../../assets/Images/Check-icon-grey.png"; * * @returns {React.Element} The `Check` component with a check icon and a label, defined by the `text` prop. */ -const Check = ({ text }) => { +const Check = ({ text, variant = "info" }) => { + const theme = useTheme(); return ( - - - - {text} - + + + {text} + ); }; +Check.propTypes = { + text: PropTypes.string.isRequired, + variant: PropTypes.oneOf(["info", "error", "success"]), +}; + export default Check; diff --git a/Client/src/Components/Check/check.css b/Client/src/Components/Check/check.css index 17f372f2b..cb24be466 100644 --- a/Client/src/Components/Check/check.css +++ b/Client/src/Components/Check/check.css @@ -1,20 +1,17 @@ -.check { - display: flex; - align-items: center; - justify-content: start; -} - -.check-icon { - width: var(--env-var-img-width-1); - height: var(--env-var-img-width-1); -} - -.check-h-spacing { - margin-right: 8px; -} - -.check-label { - font-size: var(--env-var-font-size-small); - font-weight: 600; +.check span.MuiTypography-root { + font-size: var(--env-var-font-size-small-plus); color: var(--env-var-color-2); + opacity: 0.8; +} +.check-error span.MuiTypography-root { + color: var(--env-var-color-24); +} +.check-error svg > path { + fill: var(--env-var-color-19); +} +.check-success span.MuiTypography-root { + color: var(--env-var-color-17); +} +.check-success svg > path { + fill: var(--env-var-color-23); } diff --git a/Client/src/Components/Inputs/Field/index.css b/Client/src/Components/Inputs/Field/index.css index 3a8904b27..c08c8876e 100644 --- a/Client/src/Components/Inputs/Field/index.css +++ b/Client/src/Components/Inputs/Field/index.css @@ -36,7 +36,8 @@ .field .MuiInputBase-root:has(.MuiInputAdornment-root) { padding-right: var(--env-var-spacing-1-minus); } -.field .MuiInputBase-root:has(.copy.MuiInputAdornment-root > .MuiButtonBase-root) { +.field + .MuiInputBase-root:has(.copy.MuiInputAdornment-root > .MuiButtonBase-root) { padding-right: 0; } .field .MuiInputBase-root .copy.MuiInputAdornment-root .MuiButtonBase-root { @@ -64,7 +65,7 @@ border-color: var(--env-var-color-29); border-radius: var(--env-var-radius-1); } -.field:not(:has(.input-error)) +.field:not(:has(.Mui-disabled)):not(:has(.input-error)) .MuiOutlinedInput-root:hover:not(:has(input:focus)):not(:has(textarea:focus)) fieldset { border-color: var(--env-var-color-29); diff --git a/Client/src/Components/TabPanels/Account/PasswordPanel.jsx b/Client/src/Components/TabPanels/Account/PasswordPanel.jsx index 0eb961caf..97ec1c087 100644 --- a/Client/src/Components/TabPanels/Account/PasswordPanel.jsx +++ b/Client/src/Components/TabPanels/Account/PasswordPanel.jsx @@ -4,7 +4,7 @@ import { useTheme } from "@emotion/react"; import { Box, Divider, Stack, Typography } from "@mui/material"; import ButtonSpinner from "../../ButtonSpinner"; import Field from "../../Inputs/Field"; -import { editPasswordValidation } from "../../../Validation/validation"; +import { credentials } from "../../../Validation/validation"; import Alert from "../../Alert"; import { update } from "../../../Features/Auth/authSlice"; import { useDispatch, useSelector } from "react-redux"; @@ -44,9 +44,9 @@ const PasswordPanel = () => { [name]: value, })); - const validation = editPasswordValidation.validate( + const validation = credentials.validate( { [name]: value }, - { abortEarly: false, context: { newPassword: localData.newPassword } } + { abortEarly: false, context: { password: localData.newPassword } } ); setErrors((prev) => { @@ -64,9 +64,9 @@ const PasswordPanel = () => { const handleSubmit = async (event) => { event.preventDefault(); - const { error } = editPasswordValidation.validate(localData, { + const { error } = credentials.validate(localData, { abortEarly: false, - context: { newPassword: localData.newPassword }, + context: { password: localData.newPassword }, }); if (error) { diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index 346ea76b8..bc5991d2a 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -7,10 +7,7 @@ import Button from "../../Button"; import Avatar from "../../Avatar"; import Field from "../../Inputs/Field"; import ImageField from "../../Inputs/Image"; -import { - editProfileValidation, - imageValidation, -} from "../../../Validation/validation"; +import { credentials, imageValidation } from "../../../Validation/validation"; import { useDispatch, useSelector } from "react-redux"; import { clearAuthState, @@ -66,7 +63,7 @@ const ProfilePanel = () => { [name]: value, })); - validateField({ [name]: value }, editProfileValidation, name); + validateField({ [name]: value }, credentials, name); }; // Handles image file @@ -165,8 +162,8 @@ const ProfilePanel = () => { localData.file === undefined ) { createToast({ - variant: "warning", - body: "Unable to update profile: No changes detected.", + variant: "info", + body: "Unable to update profile — no changes detected.", hasIcon: false, }); setErrors({ unchanged: "unable to update profile" }); @@ -204,6 +201,22 @@ const ProfilePanel = () => { if (action.payload.success) { dispatch(clearAuthState()); dispatch(clearMonitorState()); + } else { + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } } }; diff --git a/Client/src/Features/Auth/authSlice.js b/Client/src/Features/Auth/authSlice.js index 15dd735b1..f11851d53 100644 --- a/Client/src/Features/Auth/authSlice.js +++ b/Client/src/Features/Auth/authSlice.js @@ -96,6 +96,43 @@ export const deleteUser = createAsyncThunk( } ); +export const forgotPassword = createAsyncThunk( + "auth/forgotPassword", + async (form, thunkApi) => { + try { + const res = await axiosInstance.post("/auth/recovery/request", form); + return res.data; + } catch (error) { + if (error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + return thunkApi.rejectWithValue(error.message); + } + } +); + +export const setNewPassword = createAsyncThunk( + "auth/setNewPassword", + async (data, thunkApi) => { + const { token, form } = data; + try { + await axiosInstance.post("/auth/recovery/validate", { + recoveryToken: token, + }); + const res = await axiosInstance.post("/auth/recovery/reset", { + ...form, + recoveryToken: token, + }); + return res.data; + } catch (error) { + if (error.response.data) { + return thunkApi.rejectWithValue(error.response.data); + } + return thunkApi.rejectWithValue(error.message); + } + } +); + const handleAuthFulfilled = (state, action) => { state.isLoading = false; state.success = action.payload.success; @@ -133,6 +170,25 @@ const handleDeleteRejected = (state, action) => { state.success = false; state.msg = action.payload ? action.payload.msg : "Failed to delete account."; }; +const handleForgotFulfilled = (state, action) => { + state.isLoading = false; + state.success = action.payload.success; + state.msg = action.payload.msg; +}; +const handleForgotRejected = (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to send reset instructions."; +}; +const handleNewPasswordRejected = (state, action) => { + state.isLoading = false; + state.success = false; + state.msg = action.payload + ? action.payload.msg + : "Failed to reset password."; +}; const authSlice = createSlice({ name: "auth", @@ -178,6 +234,22 @@ const authSlice = createSlice({ }) .addCase(deleteUser.fulfilled, handleDeleteFulfilled) .addCase(deleteUser.rejected, handleDeleteRejected); + + // Forgot password thunk + builder + .addCase(forgotPassword.pending, (state) => { + state.isLoading = true; + }) + .addCase(forgotPassword.fulfilled, handleForgotFulfilled) + .addCase(forgotPassword.rejected, handleForgotRejected); + + // Set new password thunk + builder + .addCase(setNewPassword.pending, (state) => { + state.isLoading = true; + }) + .addCase(setNewPassword.fulfilled, handleAuthFulfilled) + .addCase(setNewPassword.rejected, handleNewPasswordRejected); }, }); diff --git a/Client/src/Pages/Account/index.css b/Client/src/Pages/Account/index.css index 608e08b94..ac0109f68 100644 --- a/Client/src/Pages/Account/index.css +++ b/Client/src/Pages/Account/index.css @@ -67,17 +67,6 @@ justify-content: flex-start; align-items: center; } -.edit-profile-form__wrapper input, -.edit-password-form__wrapper input, -#edit-organization-name, -#input-team-member { - padding: 10px; -} -#edit-new-password + div > button > svg, -#edit-confirm-password + div > button > svg, -#edit-current-password + div > button > svg { - color: var(--env-var-color-29); -} .edit-team-form__wrapper td { padding: 10px 0; diff --git a/Client/src/Pages/CheckEmail/index.css b/Client/src/Pages/CheckEmail/index.css index dac0a0a0d..fbf3e47af 100644 --- a/Client/src/Pages/CheckEmail/index.css +++ b/Client/src/Pages/CheckEmail/index.css @@ -1,83 +1,34 @@ .check-email-page { - width: var(--env-var-width-1); display: flex; justify-content: center; - min-height: var(--env-var-height-1); + height: var(--env-var-height-1); +} +.check-email-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; +} +.check-email-page h1.MuiTypography-root { + font-size: var(--env-var-font-size-large); + color: var(--env-var-color-1); + font-weight: 600; +} +.check-email-page p.MuiTypography-root, +.check-email-page button, +.check-email-page span.MuiTypography-root { + font-size: var(--env-var-font-size-medium); +} +.check-email-page span.MuiTypography-root { + font-weight: 600; +} +.check-email-page p.MuiTypography-root { + color: var(--env-var-color-2); +} +.check-email-page button svg { + margin-right: 5px; } .check-email-form { - width: var(--env-var-width-2); - margin: 90px auto; -} - -.check-email-form-header { - justify-content: center; - align-items: center; - text-align: center; -} - -.check-email-v-gap-large { - height: var(--env-var-spacing-3); -} - -.check-email-v-gap-medium { - height: var(--env-var-spacing-2); -} - -.check-email-v-gap-small { - height: var(--env-var-spacing-1); -} - -.check-email-form-heading { - font-size: var(--env-var-font-size-large); - font-weight: 700; - color: var(--env-var-color-1); -} - -.check-email-form-subheading { - font-size: var(--env-var-font-size-medium); - font-weight: 400; - color: var(--env-var-color-2); -} - -.check-email-form-subheading span { - font-weight: 700; -} - -.check-email-body { + margin-top: 65px; width: var(--env-var-width-2); } - -.check-email-resend { - font-size: var(--env-var-font-size-medium); - font-weight: 400; - color: var(--env-var-color-2); - text-align: center; - cursor: pointer; -} - -.check-email-resend span { - font-weight: 700; - color: var(--env-var-color-3); -} - -.check-email-back-button { - display: flex; - justify-content: center; - align-items: center; -} - -.check-email-back-button-img { - width: var(--env-var-img-width-1); - height: var(--env-var-img-width-1); - margin-right: 5px; - align-items: center; -} - -.check-email-back-button-text { - height: var(--env-var-img-width-1); - font-size: var(--env-var-font-size-medium); - font-weight: 500; - color: var(--env-var-color-2); - align-items: center; -} diff --git a/Client/src/Pages/CheckEmail/index.jsx b/Client/src/Pages/CheckEmail/index.jsx index 97cb2a5d9..5d30d67aa 100644 --- a/Client/src/Pages/CheckEmail/index.jsx +++ b/Client/src/Pages/CheckEmail/index.jsx @@ -1,56 +1,143 @@ import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; import "./index.css"; -import React from "react"; -import EmailIcon from "../../assets/Images/email.png"; +import React, { useEffect, useState } from "react"; +import EmailIcon from "../../assets/icons/email.svg?react"; import Button from "../../Components/Button"; -import LeftArrow from "../../assets/Images/arrow-left.png"; +import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; +import { Stack, Typography } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import { useDispatch } from "react-redux"; +import { useNavigate } from "react-router"; +import { createToast } from "../../Utils/toastUtils"; +import { forgotPassword } from "../../Features/Auth/authSlice"; const CheckEmail = () => { + const theme = useTheme(); + const navigate = useNavigate(); + const dispatch = useDispatch(); + + const [email, setEmail] = useState(); + const [disabled, setDisabled] = useState(false); + useEffect(() => { + setEmail(sessionStorage.getItem("email")); + }, []); + + // TODO - fix + const openMail = () => { + window.location.href = "mailto:"; + }; + + const toastFail = [ + { + variant: "info", + body: "Email not found.", + hasIcon: false, + }, + { + variant: "info", + body: "Redirecting in 3...", + hasIcon: false, + }, + { + variant: "info", + body: "Redirecting in 2...", + hasIcon: false, + }, + { + variant: "info", + body: "Redirecting in 1...", + hasIcon: false, + }, + ]; + + const resendToken = async () => { + setDisabled(true); // prevent resent button from being spammed + if (!email) { + let index = 0; + const interval = setInterval(() => { + if (index < toastFail.length) { + createToast(toastFail[index]); + index++; + } else { + clearInterval(interval); + navigate("/forgot-password"); + } + }, 1000); + } else { + const form = { email: email }; + const action = await dispatch(forgotPassword(form)); + if (action.payload.success) { + createToast({ + variant: "info", + body: `Instructions sent to ${form.email}.`, + hasIcon: false, + }); + setDisabled(false); + } else { + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } + } + } + }; + return ( - - - - - Check your email - - - We sent a password reset link to username@email.com - - - - + + + + + Check your email + + + We sent a password reset link to{" "} + + {email || "username@email.com"} + + + + + + + Didn't receive the email?{" "} + + Click to resend + + + } + sx={{ alignSelf: "center", width: "fit-content" }} + onClick={() => navigate("/login")} /> - - - - Didn’t receive the email? - Click to resend - - - - - Back to log in - - + + ); }; diff --git a/Client/src/Pages/ForgotPassword/index.css b/Client/src/Pages/ForgotPassword/index.css index acb24e6e9..7ef02f4a0 100644 --- a/Client/src/Pages/ForgotPassword/index.css +++ b/Client/src/Pages/ForgotPassword/index.css @@ -1,73 +1,31 @@ .forgot-password-page { - width: var(--env-var-width-1); display: flex; justify-content: center; - min-height: var(--env-var-height-1); + height: var(--env-var-height-1); } - -.forgot-password-form { - width: var(--env-var-width-2); - margin: 90px auto; +.forgot-password-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; } - -.forgot-password-form-header { - justify-content: center; - align-items: center; - text-align: center; -} - -.forgot-password-form-header-logo { - margin: 0 auto; -} - -.forgot-password-v-gap-large { - height: var(--env-var-spacing-3); -} - -.forgot-password-v-gap-medium { - height: var(--env-var-spacing-2); -} - -.forgot-password-v-gap-small { - height: var(--env-var-spacing-1); -} - -.forgot-password-form-heading { +.forgot-password-page h1.MuiTypography-root { font-size: var(--env-var-font-size-large); - font-weight: 700; color: var(--env-var-color-1); + font-weight: 600; } - -.forgot-password-form-subheading { +.forgot-password-page p.MuiTypography-root, +.forgot-password-page button { font-size: var(--env-var-font-size-medium); - font-weight: 500; +} +.forgot-password-page p.MuiTypography-root { color: var(--env-var-color-2); } - -.forgot-password-body { - width: var(--env-var-width-2); -} - -#forgot-password-email-input { - width: 308px; - height: 11px; - font-size: var(--env-var-font-size-medium); -} - -.forgot-password-back-button { - display: flex; - justify-content: center; - align-items: center; -} - -.forgot-password-back-button-img { - width: var(--env-var-img-width-1); - height: var(--env-var-img-width-1); +.forgot-password-page button svg{ margin-right: 5px; } -.forgot-password-back-button-text { - font-size: var(--env-var-font-size-medium); - font-weight: 500; - color: var(--env-var-color-2); + +.forgot-password-form { + margin-top: 65px; + width: var(--env-var-width-2); } diff --git a/Client/src/Pages/ForgotPassword/index.jsx b/Client/src/Pages/ForgotPassword/index.jsx index 839e6a882..76e4312bf 100644 --- a/Client/src/Pages/ForgotPassword/index.jsx +++ b/Client/src/Pages/ForgotPassword/index.jsx @@ -1,19 +1,26 @@ import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; import "./index.css"; import React from "react"; -import Logomark from "../../assets/Images/key-password.png"; -import Button from "../../Components/Button"; -import LeftArrow from "../../assets/Images/arrow-left.png"; -import { useState, useEffect } from "react"; -import { recoveryValidation } from "../../Validation/validation"; -import axiosInstance from "../../Utils/axiosConfig"; +import Logomark from "../../assets/icons/key.svg?react"; +import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; +import { useState } from "react"; +import { credentials } from "../../Validation/validation"; import { useNavigate } from "react-router-dom"; import Field from "../../Components/Inputs/Field"; +import { createToast } from "../../Utils/toastUtils"; +import { useDispatch, useSelector } from "react-redux"; +import { forgotPassword } from "../../Features/Auth/authSlice"; +import ButtonSpinner from "../../Components/ButtonSpinner"; +import { Stack, Typography } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import Button from "../../Components/Button"; const ForgotPassword = () => { const navigate = useNavigate(); + const dispatch = useDispatch(); + const theme = useTheme(); - const [isLoading, setIsLoading] = useState(false); // Used to disable the button while loading so user doesn't submit multiple times + const { isLoading } = useSelector((state) => state.auth); const [errors, setErrors] = useState({}); const [form, setForm] = useState({ email: "", @@ -23,92 +30,115 @@ const ForgotPassword = () => { "forgot-password-email-input": "email", }; - useEffect(() => { - const { error } = recoveryValidation.validate(form); - if (error === undefined) { - setErrors({}); + const handleSubmit = async (event) => { + event.preventDefault(); + + const { error } = credentials.validate(form, { abortEarly: false }); + + if (error) { + // validation errors + const err = + error.details && error.details.length > 0 + ? error.details[0].message + : "Error validating data."; + setErrors(err); + createToast({ + variant: "info", + body: err, + hasIcon: false, + }); } else { - const validationErrors = error.details.reduce((acc, err) => { - return { ...acc, [err.path[0]]: err.message }; - }, {}); - setErrors(validationErrors); - } - }, [form]); - - const handleInput = (e) => { - const fieldName = idMap[e.target.id]; - setForm({ ...form, [fieldName]: e.target.value }); - }; - - const handleSubmit = async () => { - //TODO show loading spinner - setIsLoading(true); - try { - const { error } = recoveryValidation.validate(form); - if (error !== undefined) { - throw error; + const action = await dispatch(forgotPassword(form)); + if (action.payload.success) { + sessionStorage.setItem("email", form.email); + navigate("/check-email"); + createToast({ + variant: "info", + body: `Instructions sent to ${form.email}.`, + hasIcon: false, + }); + } else { + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } } - await axiosInstance.post(`/auth/recovery/request`, form); - navigate("/check-email"); - } catch (error) { - //TODO display error (Toast?) - alert(error); - } finally { - setIsLoading(false); } }; + + const handleChange = (event) => { + const { value, id } = event.target; + const name = idMap[id]; + setForm((prev) => ({ + ...prev, + [name]: value, + })); + + const { error } = credentials.validate( + { [name]: value }, + { abortEarly: false } + ); + + setErrors((prev) => { + const prevErrors = { ...prev }; + if (error) prevErrors[name] = error.details[0].message; + else delete prevErrors[name]; + return prevErrors; + }); + }; + return ( - - - - - Forgot password? - - - No worries, we’ll send you reset instructions. - - - - + + + + + Forgot password? + + + No worries, we'll send you reset instructions. + + + - - - - - - } + sx={{ alignSelf: "center", width: "fit-content" }} + onClick={() => navigate("/login")} /> - Back to log in - - + + ); }; diff --git a/Client/src/Pages/Login/index.css b/Client/src/Pages/Login/index.css index ed6b4d1dc..e94ea8a00 100644 --- a/Client/src/Pages/Login/index.css +++ b/Client/src/Pages/Login/index.css @@ -2,79 +2,57 @@ width: var(--env-var-width-1); display: flex; justify-content: center; - align-items: center; - min-height: var(--env-var-height-1); + height: 100vh; } - -.login-form { - width: var(--env-var-width-2); - margin: 90px auto; +.login-page svg rect { + fill: none; } - -.login-form-header { - justify-content: center; - align-items: center; - text-align: center; +.login-page p.MuiTypography-root, +.login-page span, +.login-page button { + font-size: var(--env-var-font-size-medium); } - -#login-form-header-logo { - margin-bottom: 60px; +.login-page p.MuiTypography-root { + color: var(--env-var-color-2); + opacity: 0.8; } - -.login-form-v-spacing { - height: var(--env-var-spacing-1); +.login-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; } - -.login-form-v2-spacing { - height: var(--env-var-spacing-2); +.login-page span:not(.MuiTypography-root):not(.MuiButtonBase-root) { + color: var(--env-var-color-3); + cursor: pointer; + font-weight: 600; } - -.login-form-v3-spacing { - height: var(--env-var-spacing-3); +.login-page .MuiFormControlLabel-root { + margin: 0; } - -.login-form-heading { - font-size: var(--env-var-font-size-xlarge); - font-weight: 700; - color: var(--env-var-color-1); +.login-page .MuiFormControlLabel-root .MuiButtonBase-root { + margin-right: 5px; +} +.login-page .MuiFormControlLabel-root span:not(.Mui-checked) svg{ + fill: var(--env-var-color-4); +} +.login-page .MuiFormControlLabel-root svg{ + margin-bottom: 1px; +} +.login-page .MuiFormControlLabel-root .MuiTypography-root { + color: var(--env-var-color-5); + user-select: none; } /* .login-form-inputs .field h3.MuiTypography-root{ font-weight: 600; } */ -.login-form-password-options { - display: flex; - align-items: center; - justify-content: space-between; -} - -.login-form-forgot-password { - color: var(--env-var-color-3); - font-weight: 600; - cursor: pointer; - font-size: var(--env-var-font-size-medium); +.login-form{ + margin-top: 95px; } .google-enter { width: var(--env-var-img-width-1); height: var(--env-var-img-width-1); margin-right: 10px; -} - -.new-account-option { - display: flex; - justify-content: center; - align-items: center; - color: var(--env-var-color-2); - font-size: var(--env-var-font-size-medium); - font-weight: 600; -} - -.new-account-option-span { - margin-left: 5px; - color: var(--env-var-color-3); - font-size: var(--env-var-font-size-medium); - cursor: pointer; - font-weight: 700; -} +} \ No newline at end of file diff --git a/Client/src/Pages/Login/index.jsx b/Client/src/Pages/Login/index.jsx index c06f3b343..da0fed6ba 100644 --- a/Client/src/Pages/Login/index.jsx +++ b/Client/src/Pages/Login/index.jsx @@ -4,31 +4,38 @@ import { useNavigate } from "react-router-dom"; import "./index.css"; import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; import Logomark from "../../assets/Images/bwl-logo-2.svg?react"; -import CheckBox from "../../Components/Checkbox/Checkbox"; import Button from "../../Components/Button"; import Google from "../../assets/Images/Google.png"; import axiosInstance from "../../Utils/axiosConfig"; -import { loginValidation } from "../../Validation/validation"; +import { credentials } from "../../Validation/validation"; import { login } from "../../Features/Auth/authSlice"; import { useDispatch } from "react-redux"; import { createToast } from "../../Utils/toastUtils"; import Field from "../../Components/Inputs/Field"; +import { + Checkbox, + Divider, + FormControlLabel, + Stack, + Typography, +} from "@mui/material"; +import { useTheme } from "@emotion/react"; const Login = () => { const dispatch = useDispatch(); const navigate = useNavigate(); + const theme = useTheme(); const idMap = { "login-email-input": "email", "login-password-input": "password", }; - const [errors, setErrors] = useState({}); - const [form, setForm] = useState({ email: "", password: "", }); + const [errors, setErrors] = useState({}); useEffect(() => { axiosInstance @@ -43,138 +50,159 @@ const Login = () => { }); }, [navigate]); - useEffect(() => { - const { error } = loginValidation.validate(form, { - abortEarly: false, - }); - - if (error) { - // Creates an error object in the format { field: message } - const validationErrors = error.details.reduce((acc, err) => { - return { ...acc, [err.path[0]]: err.message }; - }, {}); - setErrors(validationErrors); - } else { - setErrors({}); - } - }, [form]); - const handleSubmit = async (e) => { e.preventDefault(); - try { - await loginValidation.validateAsync(form, { abortEarly: false }); + + const { error } = credentials.validate(form, { abortEarly: false }); + + if (error) { + // validation errors + const newErrors = {}; + error.details.forEach((err) => { + newErrors[err.path[0]] = err.message; + }); + setErrors(newErrors); + createToast({ + variant: "info", + body: + error.details && error.details.length > 0 + ? error.details[0].message + : "Error validating data.", + hasIcon: false, + }); + } else { const action = await dispatch(login(form)); - if (action.meta.requestStatus === "fulfilled") { + if (action.payload.success) { navigate("/monitors"); - } - if (action.meta.requestStatus === "rejected") { - const error = new Error("Request rejected"); - error.response = action.payload; - throw error; - } - } catch (error) { - if (error.name === "ValidationError") { - // validation errors createToast({ variant: "info", - body: - error && error.details && error.details.length > 0 - ? error.details[0].message - : "Error validating data.", - hasIcon: false, - }); - } else if (error.response) { - // dispatch errors - createToast({ - variant: "info", - body: error.response.msg, + body: "Welcome back! You're successfully logged in.", hasIcon: false, }); } else { - // unknown errors - createToast({ - variant: "info", - body: "Unknown error.", - hasIcon: false, - }); + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } } } }; - const handleInput = (e) => { - const newForm = { ...form, [idMap[e.target.id]]: e.target.value }; - setForm(newForm); - }; + const handleChange = (event) => { + const { value, id } = event.target; + const name = idMap[id]; + setForm((prev) => ({ + ...prev, + [name]: value, + })); - const handleSignupClick = () => { - navigate("/register"); + const { error } = credentials.validate( + { [name]: value }, + { abortEarly: false } + ); + + setErrors((prev) => { + const prevErrors = { ...prev }; + if (error) prevErrors[name] = error.details[0].message; + else delete prevErrors[name]; + return prevErrors; + }); }; return ( - - - - Log in to your account - - - - + + + } + /> + + or + - - - - - - Forgot password - - - + + + } + label="Remember me" + /> + navigate("/forgot-password")}> + Forgot password + + + + - - } - /> - - - - Don’t have an account? - { - navigate("/register"); - }} - className="new-account-option-span" + - Sign up - - + + Don't have an account? + + { + navigate("/register"); + }} + > + Sign up + + + ); diff --git a/Client/src/Pages/NewPasswordConfirmed/index.css b/Client/src/Pages/NewPasswordConfirmed/index.css index 39f8bcd68..aae2d8636 100644 --- a/Client/src/Pages/NewPasswordConfirmed/index.css +++ b/Client/src/Pages/NewPasswordConfirmed/index.css @@ -1,67 +1,36 @@ .password-confirmed-page { - width: var(--env-var-width-1); display: flex; justify-content: center; - min-height: var(--env-var-height-1); + height: var(--env-var-height-1); +} +.password-confirmed-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; +} +.password-confirmed-page h1.MuiTypography-root { + font-size: var(--env-var-font-size-large); + color: var(--env-var-color-1); + font-weight: 600; +} +.password-confirmed-page p.MuiTypography-root, +.password-confirmed-page button { + font-size: var(--env-var-font-size-medium); +} +.password-confirmed-page p.MuiTypography-root { + color: var(--env-var-color-2); +} +.password-confirmed-page button:not(.MuiIconButton-root) svg { + margin-right: 5px; +} +.password-confirmed-page + .MuiFormControl-root:has(#register-password-input) + + span.MuiTypography-root { + display: none; + visibility: hidden; } .password-confirmed-form { - width: var(--env-var-width-2); - margin: 90px auto; -} - -.password-confirmed-form-header { - justify-content: center; - align-items: center; - text-align: center; -} - -.password-confirmed-v-gap-large { - height: var(--env-var-spacing-3); -} - -.password-confirmed-v-gap-medium { - height: var(--env-var-spacing-2); -} - -.password-confirmed-v-gap-small { - height: var(--env-var-spacing-1); -} - -.password-confirmed-form-heading { - font-size: var(--env-var-font-size-large); - font-weight: 700; - color: var(--env-var-color-1); -} - -.password-confirmed-form-subheading { - font-size: var(--env-var-font-size-medium); - font-weight: 600; - color: var(--env-var-color-2); -} - -.password-confirmed-body { + margin-top: 65px; width: var(--env-var-width-2); } - -.password-confirmed-back-button { - display: flex; - justify-content: center; - align-items: center; - cursor: pointer; -} - -.password-confirmed-back-button-img { - width: var(--env-var-img-width-1); - height: var(--env-var-img-width-1); - margin-right: 5px; - align-items: center; -} - -.password-confirmed-back-button-text { - height: var(--env-var-img-width-1); - font-size: var(--env-var-font-size-medium); - font-weight: 600; - color: var(--env-var-color-2); - text-align: center; -} diff --git a/Client/src/Pages/NewPasswordConfirmed/index.jsx b/Client/src/Pages/NewPasswordConfirmed/index.jsx index 1bbfc06ad..40be980b1 100644 --- a/Client/src/Pages/NewPasswordConfirmed/index.jsx +++ b/Client/src/Pages/NewPasswordConfirmed/index.jsx @@ -1,54 +1,55 @@ import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; import "./index.css"; -import React from "react"; -import SuccessIcon from "../../assets/Images/success-icon.png"; +import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; +import ConfirmIcon from "../../assets/icons/confirm-icon.svg?react"; import Button from "../../Components/Button"; -import LeftArrow from "../../assets/Images/arrow-left.png"; +import { Stack, Typography } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import { useNavigate } from "react-router"; +import { useDispatch } from "react-redux"; +import { clearAuthState } from "../../Features/Auth/authSlice"; +import { clearMonitorState } from "../../Features/Monitors/monitorsSlice"; const NewPasswordConfirmed = () => { + const theme = useTheme(); + const navigate = useNavigate(); + const dispatch = useDispatch(); + + const handleNavigate = () => { + dispatch(clearAuthState()); + dispatch(clearMonitorState()); + navigate("/login"); + }; + return ( - - - - - Password reset - - + + + + + Password reset + + Your password has been successfully reset. Click below to log in magically. - - - - + + + navigate("/monitors")} /> - - - - } + sx={{ alignSelf: "center", width: "fit-content" }} + onClick={handleNavigate} /> - - Back to log in - - - + + ); }; diff --git a/Client/src/Pages/Register/index.css b/Client/src/Pages/Register/index.css index 948f0afd0..b3e7c8a89 100644 --- a/Client/src/Pages/Register/index.css +++ b/Client/src/Pages/Register/index.css @@ -1,44 +1,38 @@ .register-page { display: flex; justify-content: center; - min-height: var(--env-var-height-1); + height: var(--env-var-height-1); +} +.register-page h1.MuiTypography-root { + font-size: var(--env-var-font-size-large); + color: var(--env-var-color-1); + font-weight: 600; + opacity: 0.5; +} +.register-page p.MuiTypography-root, +.register-page span, +.register-page button { + font-size: var(--env-var-font-size-medium); +} +.register-page p.MuiTypography-root { + color: var(--env-var-color-2); + opacity: 0.8; +} +.register-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; +} +.register-page svg rect { + fill: none; +} +.register-page + .MuiFormControl-root:has(#register-password-input) + + span.MuiTypography-root { + display: none; + visibility: hidden; } .register-form { - width: var(--env-var-width-2); - margin: 140px auto; -} - -.register-form-header { - justify-content: center; - align-items: center; - text-align: center; -} - -.register-form-header-logo { - margin: 0 auto; -} - -.register-form-v-spacing-large { - height: var(--env-var-spacing-3); -} - -.register-form-v-spacing-small { - height: var(--env-var-spacing-1); -} - -.register-form-heading { - font-size: var(--env-var-font-size-large); - font-weight: 700; - color: var(--env-var-color-1); -} - -.register-form-subheading { - font-size: var(--env-var-font-size-medium); - color: var(--env-var-color-2); - font-weight: 600; -} - -.register-bottom-spacing { - height: 50px; + margin-top: 95px; } diff --git a/Client/src/Pages/Register/index.jsx b/Client/src/Pages/Register/index.jsx index 12332f27e..6494af5cd 100644 --- a/Client/src/Pages/Register/index.jsx +++ b/Client/src/Pages/Register/index.jsx @@ -3,20 +3,23 @@ import { useNavigate } from "react-router-dom"; import "./index.css"; import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; -import Logomark from "../../assets/Images/Logomark.png"; +import Logomark from "../../assets/Images/bwl-logo-2.svg?react"; import Check from "../../Components/Check/Check"; import Button from "../../Components/Button"; import Google from "../../assets/Images/Google.png"; -import { registerValidation } from "../../Validation/validation"; +import { credentials } from "../../Validation/validation"; import axiosInstance from "../../Utils/axiosConfig"; import { useDispatch } from "react-redux"; import { register } from "../../Features/Auth/authSlice"; import { createToast } from "../../Utils/toastUtils"; import Field from "../../Components/Inputs/Field"; +import { useTheme } from "@emotion/react"; +import { Divider, Stack, Typography } from "@mui/material"; const Register = () => { const dispatch = useDispatch(); const navigate = useNavigate(); + const theme = useTheme(); // TODO If possible, change the IDs of these fields to match the backend const idMap = { @@ -24,17 +27,18 @@ const Register = () => { "register-lastname-input": "lastname", "register-email-input": "email", "register-password-input": "password", + "register-confirm-input": "confirm", }; - const [errors, setErrors] = useState({}); - const [form, setForm] = useState({ firstname: "", lastname: "", email: "", password: "", + confirm: "", role: "", }); + const [errors, setErrors] = useState({}); useEffect(() => { axiosInstance @@ -49,124 +53,129 @@ const Register = () => { }); }, [form, navigate]); - useEffect(() => { - const { error } = registerValidation.validate(form, { + const handleSubmit = async (e) => { + e.preventDefault(); + + const adminForm = { ...form, role: "admin" }; + const { error } = credentials.validate(adminForm, { abortEarly: false, + context: { password: form.password }, }); if (error) { - // Creates an error object in the format { field: message } - const validationErrors = error.details.reduce((acc, err) => { - return { ...acc, [err.path[0]]: err.message }; - }, {}); - setErrors(validationErrors); + // validation errors + const newErrors = {}; + error.details.forEach((err) => { + newErrors[err.path[0]] = err.message; + }); + setErrors(newErrors); + createToast({ + variant: "info", + body: + error.details && error.details.length > 0 + ? error.details[0].message + : "Error validating data.", + hasIcon: false, + }); } else { - setErrors({}); - } - }, [form]); - - const handleInput = (e) => { - const newForm = { ...form, [idMap[e.target.id]]: e.target.value }; - setForm(newForm); - }; - - const handleSubmit = async (e) => { - e.preventDefault(); - try { - const adminForm = { ...form, role: "admin" }; - await registerValidation.validateAsync(adminForm, { abortEarly: false }); + delete adminForm.confirm; const action = await dispatch(register(adminForm)); - - if (action.meta.requestStatus === "fulfilled") { + if (action.payload.success) { const token = action.payload.data; localStorage.setItem("token", token); navigate("/"); - } - - if (action.meta.requestStatus === "rejected") { - const error = new Error("Request rejected"); - error.response = action.payload; - throw error; - } - } catch (error) { - if (error.name === "ValidationError") { - // validation errors createToast({ variant: "info", - body: - error && error.details && error.details.length > 0 - ? error.details[0].message - : "Error validating data.", - hasIcon: false, - }); - } else if (error.response) { - // dispatch errors - createToast({ - variant: "info", - body: error.response.msg, + body: "Welcome! Your account was created successfully.", hasIcon: false, }); } else { - // unknown errors - createToast({ - variant: "info", - body: "Unknown error.", - hasIcon: false, - }); + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } } } }; + const handleChange = (event) => { + const { value, id } = event.target; + const name = idMap[id]; + setForm((prev) => ({ + ...prev, + [name]: value, + })); + + const { error } = credentials.validate( + { [name]: value }, + { abortEarly: false, context: { password: form.password } } + ); + + setErrors((prev) => { + const prevErrors = { ...prev }; + if (error) prevErrors[name] = error.details[0].message; + else delete prevErrors[name]; + return prevErrors; + }); + }; return ( - - - + + + } /> - - - Create Uptime Manager admin account - - - - - + + or + - - - { isRequired={true} placeholder="Create a password" autoComplete="current-password" + value={form.password} + onChange={handleChange} error={errors.password} - onChange={handleInput} /> - - {/* TODO - hook up to form state and run checks */} { isRequired={true} placeholder="Confirm your password" autoComplete="current-password" + value={form.confirm} + onChange={handleChange} error={errors.confirm} - onChange={handleInput} /> - - - - - - - - - + + + + + - - } - /> - + - ); }; diff --git a/Client/src/Pages/SetNewPassword/index.css b/Client/src/Pages/SetNewPassword/index.css index 183e8d21f..db7160d85 100644 --- a/Client/src/Pages/SetNewPassword/index.css +++ b/Client/src/Pages/SetNewPassword/index.css @@ -1,63 +1,36 @@ .set-new-password-page { - width: var(--env-var-width-1); display: flex; justify-content: center; - min-height: var(--env-var-height-1); + height: var(--env-var-height-1); +} +.set-new-password-page button:not(.MuiIconButton-root) { + height: 34px; + border-radius: var(--env-var-radius-2); + line-height: 0; +} +.set-new-password-page h1.MuiTypography-root { + font-size: var(--env-var-font-size-large); + color: var(--env-var-color-1); + font-weight: 600; +} +.set-new-password-page p.MuiTypography-root, +.set-new-password-page button { + font-size: var(--env-var-font-size-medium); +} +.set-new-password-page p.MuiTypography-root { + color: var(--env-var-color-2); +} +.set-new-password-page button:not(.MuiIconButton-root) svg { + margin-right: 5px; +} +.set-new-password-page + .MuiFormControl-root:has(#register-password-input) + + span.MuiTypography-root { + display: none; + visibility: hidden; } .set-new-password-form { + margin-top: 65px; width: var(--env-var-width-2); - margin: 90px auto; -} - -.set-new-password-form-header { - justify-content: center; - align-items: center; - text-align: center; -} - -.set-new-password-form-gap-large { - height: var(--env-var-spacing-3); -} - -.set-new-password-form-gap-medium { - height: var(--env-var-spacing-2); -} - -.set-new-password-form-gap-small { - height: var(--env-var-spacing-1); -} - -.set-new-password-form-heading { - font-size: var(--env-var-font-size-large); - color: var(--env-var-color-1); - font-weight: 700; -} - -.set-new-password-form-subheading { - font-size: var(--env-var-font-size-medium); - color: var(--env-var-color-2); - font-weight: 600; -} - -.set-new-password-back-button { - display: flex; - justify-content: center; - align-items: center; - cursor: pointer; -} - -.set-new-password-back-button-img { - width: var(--env-var-img-width-1); - height: var(--env-var-img-width-1); - margin-right: 5px; - align-items: center; -} - -.set-new-password-back-button-text { - height: var(--env-var-img-width-1); - font-size: var(--env-var-font-size-medium); - color: var(--env-var-color-2); - font-weight: 600; - align-items: center; } diff --git a/Client/src/Pages/SetNewPassword/index.jsx b/Client/src/Pages/SetNewPassword/index.jsx index c06787b17..f224db365 100644 --- a/Client/src/Pages/SetNewPassword/index.jsx +++ b/Client/src/Pages/SetNewPassword/index.jsx @@ -1,139 +1,207 @@ import BackgroundPattern from "../../Components/BackgroundPattern/BackgroundPattern"; import "./index.css"; -import LockIcon from "../../assets/Images/lock-icon.png"; +import LockIcon from "../../assets/icons/lock-button-icon.svg?react"; import Check from "../../Components/Check/Check"; -import Button from "../../Components/Button"; -import LeftArrow from "../../assets/Images/arrow-left.png"; +import ButtonSpinner from "../../Components/ButtonSpinner"; +import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import { useParams } from "react-router-dom"; -import { useState, useEffect } from "react"; -import { newPasswordValidation } from "../../Validation/validation"; -import axiosInstance from "../../Utils/axiosConfig"; +import { useState } from "react"; +import { credentials } from "../../Validation/validation"; import { useNavigate } from "react-router-dom"; import Field from "../../Components/Inputs/Field"; +import { useDispatch, useSelector } from "react-redux"; +import { setNewPassword } from "../../Features/Auth/authSlice"; +import { createToast } from "../../Utils/toastUtils"; +import { Stack, Typography } from "@mui/material"; +import { useTheme } from "@emotion/react"; +import Button from "../../Components/Button"; const SetNewPassword = () => { const navigate = useNavigate(); + const dispatch = useDispatch(); + const theme = useTheme(); + const [errors, setErrors] = useState({}); - const [form, setForm] = useState({}); - const [isLoading, setIsLoading] = useState(false); + const [form, setForm] = useState({ + password: "", + confirm: "", + }); const idMap = { "register-password-input": "password", "confirm-password-input": "confirm", }; - const handleInput = (e) => { - const fieldName = idMap[e.target.id]; - setForm({ ...form, [fieldName]: e.target.value }); - console.log(errors); - }; + const { isLoading } = useSelector((state) => state.auth); + const { token } = useParams(); - const handleSubmit = async () => { - // TODO show loading spinner - setIsLoading(true); - try { - await axiosInstance.post("/auth/recovery/validate", { - recoveryToken: token, - }); - await axiosInstance.post("/auth/recovery/reset", { - ...form, - recoveryToken: token, - }); - navigate("/new-password-confirmed"); - } catch (error) { - // TODO display error (Toast?) - alert(error.response.data.msg); - } finally { - setIsLoading(false); - } - }; + const handleSubmit = async (e) => { + e.preventDefault(); - useEffect(() => { - const { error } = newPasswordValidation.validate(form, { + const passwordForm = { ...form }; + const { error } = credentials.validate(passwordForm, { abortEarly: false, + context: { password: form.password }, }); if (error) { - const validationErrors = error.details.reduce((acc, err) => { - return { ...acc, [err.path[0]]: err.message }; - }, {}); - setErrors(validationErrors); + // validation errors + const newErrors = {}; + error.details.forEach((err) => { + newErrors[err.path[0]] = err.message; + }); + setErrors(newErrors); + createToast({ + variant: "info", + body: + error.details && error.details.length > 0 + ? error.details[0].message + : "Error validating data.", + hasIcon: false, + }); } else { - setErrors({}); + delete passwordForm.confirm; + const action = await dispatch( + setNewPassword({ token: token, form: passwordForm }) + ); + if (action.payload.success) { + navigate("/new-password-confirmed"); + createToast({ + variant: "info", + body: "Your password was reset successfully.", + hasIcon: false, + }); + } else { + if (action.payload) { + // dispatch errors + createToast({ + variant: "info", + body: action.payload.msg, + hasIcon: false, + }); + } else { + // unknown errors + createToast({ + variant: "info", + body: "Unknown error.", + hasIcon: false, + }); + } + } } - }, [form]); + }; + + const handleChange = (event) => { + const { value, id } = event.target; + const name = idMap[id]; + setForm((prev) => ({ + ...prev, + [name]: value, + })); + + const { error } = credentials.validate( + { [name]: value }, + { abortEarly: false, context: { password: form.password } } + ); + + setErrors((prev) => { + const prevErrors = { ...prev }; + if (error) prevErrors[name] = error.details[0].message; + else delete prevErrors[name]; + return prevErrors; + }); + }; - const { token } = useParams(); return ( - - - - - Set new password - - + + + + + Set new password + + Your new password must be different to previously used passwords. - - - - + + + - - - - - - - - - + + + + + - - - - } + sx={{ alignSelf: "center", width: "fit-content" }} + onClick={() => navigate("/login")} /> - - Back to log in - - - + + ); }; diff --git a/Client/src/Utils/Theme.js b/Client/src/Utils/Theme.js index f3ed11fc3..e758bfe2a 100644 --- a/Client/src/Utils/Theme.js +++ b/Client/src/Utils/Theme.js @@ -97,6 +97,7 @@ const theme = createTheme({ ml: "16px", large: "24px", xl: "40px", + xxl: "60px", }, alert: { info: { diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index f662d550e..26dd3d94a 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -1,138 +1,76 @@ import joi from "joi"; -const registerValidation = joi.object({ - firstname: joi.string().required().messages({ - "string.empty": "First name is required", - }), - - lastname: joi.string().required().messages({ - "string.empty": "Last name is required", - }), - - email: joi - .string() - .email({ tlds: { allow: false } }) - .required() - .messages({ - "string.email": "Email must be a valid email", - "string.empty": "Email is required", - }), - - password: joi.string().min(8).required().messages({ - "string.min": "Password must be at least 8 characters", - "string.empty": "Password is required", - }), - role: joi.string().required().messages({ - "string.empty": "Role is required", - }), -}); - -const loginValidation = joi.object({ - email: joi - .string() - .email({ tlds: { allow: false } }) - .required() - .messages({ - "string.email": "Email must be a valid email", - "string.empty": "Email is required", - }), - - password: joi.string().min(8).required().messages({ - "string.min": "Password must be at least 8 characters", - "string.empty": "Password is required", - }), -}); - -const recoveryValidation = joi.object({ - email: joi - .string() - .email({ tlds: { allow: false } }) - .required() - .messages({ - "string.email": "Email must be a valid email", - "string.empty": "Email is required", - }), -}); - -const newPasswordValidation = joi.object({ - password: joi.string().min(8).required().messages({ - "string.min": "Password must be at least 8 characters", - "string.empty": "Password is required", - }), - confirm: joi.string().valid(joi.ref("password")).min(8).required().messages({ - "string.min": "Password must be at least 8 characters", - "string.empty": "Password is required", - "any.only": "Passwords do not match", - }), -}); - -const editProfileValidation = joi.object({ - firstname: joi.string().trim().pattern(new RegExp("^[A-Za-z]+$")).messages({ - "string.empty": "*First name is required.", - "string.pattern.base": "*First name must contain only letters.", - }), - lastname: joi.string().trim().pattern(new RegExp("^[A-Za-z]+$")).messages({ - "string.empty": "*Last name is required.", - "string.pattern.base": "*Last name must contain only letters.", - }), - email: joi - .string() - .trim() - .email({ tlds: { allow: false } }) - .messages({ - "string.empty": "*Email is required.", - "string.email": "*Invalid email address.", - }), -}); +const nameSchema = joi + .string() + .max(50) + .trim() + .pattern(new RegExp("^[A-Za-z]+$")) + .messages({ + "string.empty": "Name is required", + "string.max": "Name must be less than 50 characters long", + "string.pattern.base": "Name must contain only letters", + }); const passwordSchema = joi .string() .trim() .min(8) .messages({ - "string.empty": "*Password is required.", - "string.min": "*Password must be at least 8 characters long.", + "string.empty": "Password is required", + "string.min": "Password must be at least 8 characters long", }) .custom((value, helpers) => { if (!/[A-Z]/.test(value)) { return helpers.message( - "*Password must contain at least one uppercase letter." + "Password must contain at least one uppercase letter" ); } if (!/[a-z]/.test(value)) { return helpers.message( - "*Password must contain at least one lowercase letter." + "Password must contain at least one lowercase letter" ); } if (!/\d/.test(value)) { - return helpers.message("*Password must contain at least one number."); + return helpers.message("Password must contain at least one number"); } if (!/[!@#$%^&*]/.test(value)) { return helpers.message( - "*Password must contain at least one special character." + "Password must contain at least one special character" ); } return value; }); -const editPasswordValidation = joi.object({ - // TBD - validation for current password ? +const credentials = joi.object({ + firstname: nameSchema, + lastname: nameSchema, + email: joi + .string() + .trim() + .email({ tlds: { allow: false } }) + .messages({ + "string.empty": "Email is required", + "string.email": "Must be a valid email address", + }), password: passwordSchema, newPassword: passwordSchema, confirm: joi .string() .trim() .messages({ - "string.empty": "*Password confirmation is required.", + "string.empty": "Password confirmation is required", }) .custom((value, helpers) => { - const { newPassword } = helpers.prefs.context; - if (value !== newPassword) { - return helpers.message("*Passwords do not match."); + const { password } = helpers.prefs.context; + if (value !== password) { + return helpers.message("Passwords do not match"); } return value; }), + role: joi.string().messages({ + "string.empty": "Role is required", + }), }); const createMonitorValidation = joi.object({ @@ -168,13 +106,4 @@ const imageValidation = joi.object({ }), }); -export { - imageValidation, - createMonitorValidation, - registerValidation, - loginValidation, - recoveryValidation, - newPasswordValidation, - editPasswordValidation, - editProfileValidation, -}; +export { credentials, imageValidation, createMonitorValidation }; diff --git a/Client/src/assets/Images/Check-icon-grey.png b/Client/src/assets/Images/Check-icon-grey.png deleted file mode 100644 index bf526770e..000000000 Binary files a/Client/src/assets/Images/Check-icon-grey.png and /dev/null differ diff --git a/Client/src/assets/Images/Logomark.png b/Client/src/assets/Images/Logomark.png deleted file mode 100644 index 9fe13ec93..000000000 Binary files a/Client/src/assets/Images/Logomark.png and /dev/null differ diff --git a/Client/src/assets/Images/arrow-left.png b/Client/src/assets/Images/arrow-left.png deleted file mode 100644 index 0bd5b1268..000000000 Binary files a/Client/src/assets/Images/arrow-left.png and /dev/null differ diff --git a/Client/src/assets/Images/email.png b/Client/src/assets/Images/email.png deleted file mode 100644 index 40b1f8232..000000000 Binary files a/Client/src/assets/Images/email.png and /dev/null differ diff --git a/Client/src/assets/Images/key-password.png b/Client/src/assets/Images/key-password.png deleted file mode 100644 index ed7fa6538..000000000 Binary files a/Client/src/assets/Images/key-password.png and /dev/null differ diff --git a/Client/src/assets/Images/lock-icon.png b/Client/src/assets/Images/lock-icon.png deleted file mode 100644 index 163adad87..000000000 Binary files a/Client/src/assets/Images/lock-icon.png and /dev/null differ diff --git a/Client/src/assets/Images/success-icon.png b/Client/src/assets/Images/success-icon.png deleted file mode 100644 index 43cdbbc2a..000000000 Binary files a/Client/src/assets/Images/success-icon.png and /dev/null differ diff --git a/Client/src/assets/icons/check.svg b/Client/src/assets/icons/check.svg new file mode 100644 index 000000000..357378f40 --- /dev/null +++ b/Client/src/assets/icons/check.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Client/src/assets/icons/confirm-icon.svg b/Client/src/assets/icons/confirm-icon.svg new file mode 100644 index 000000000..d5cdd42de --- /dev/null +++ b/Client/src/assets/icons/confirm-icon.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Client/src/assets/icons/email.svg b/Client/src/assets/icons/email.svg new file mode 100644 index 000000000..f501bd75c --- /dev/null +++ b/Client/src/assets/icons/email.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Client/src/assets/icons/key.svg b/Client/src/assets/icons/key.svg new file mode 100644 index 000000000..c6401e09f --- /dev/null +++ b/Client/src/assets/icons/key.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Client/src/assets/icons/lock-button-icon.svg b/Client/src/assets/icons/lock-button-icon.svg new file mode 100644 index 000000000..5048a6a80 --- /dev/null +++ b/Client/src/assets/icons/lock-button-icon.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/Client/src/index.css b/Client/src/index.css index 674acc13e..4b7898c9a 100644 --- a/Client/src/index.css +++ b/Client/src/index.css @@ -47,7 +47,7 @@ --env-var-color-27: #fecf60; --lighter-env-var-color-27: rgba(254, 207, 96, 0.1); --env-var-color-28: #f79009; - --env-var-color-29: #D0D5DD; + --env-var-color-29: #d0d5dd; --env-var-radius-1: 4px; --env-var-radius-2: 8px; @@ -128,11 +128,14 @@ button:focus-visible { .Toastify__toast-container { width: auto; } +.Toastify__toast-body .alert{ + min-width: 150px; +} .Toastify [class^="Toastify__toast"] { padding: 0; margin: 0; } -.Toastify__toast{ +.Toastify__toast { min-height: 0; border-radius: 4px; } diff --git a/Server/controllers/authController.js b/Server/controllers/authController.js index 1cab8703e..4da96e661 100644 --- a/Server/controllers/authController.js +++ b/Server/controllers/authController.js @@ -310,7 +310,7 @@ const resetPasswordController = async (req, res, next) => { try { await newPasswordValidation.validateAsync(req.body); const user = await req.db.resetPassword(req, res); - const token = issueToken(user); + const token = issueToken(user._doc); res.status(200).json({ success: true, msg: successMessages.AUTH_RESET_PASSWORD,