From 950222e42405bc7b937d22963185ad51888fdae2 Mon Sep 17 00:00:00 2001 From: Connor Bechthold Date: Fri, 2 Feb 2024 03:13:28 -0500 Subject: [PATCH] linterrr --- backend/app/rest/auth_routes.py | 2 +- .../services/implementations/auth_service.py | 2 +- .../utilities/exceptions/auth_exceptions.py | 2 + frontend/src/APIClients/AuthAPIClient.ts | 12 +- frontend/src/App.tsx | 6 +- frontend/src/components/forms/Login.tsx | 14 +- frontend/src/components/forms/Signup.tsx | 9 +- .../pages/Auth/ResetPasswordPage.tsx | 194 +++++++++--------- 8 files changed, 132 insertions(+), 109 deletions(-) diff --git a/backend/app/rest/auth_routes.py b/backend/app/rest/auth_routes.py index bfdb1f88..7fe0dc85 100644 --- a/backend/app/rest/auth_routes.py +++ b/backend/app/rest/auth_routes.py @@ -7,7 +7,7 @@ from ..utilities.exceptions.auth_exceptions import ( EmailAlreadyInUseException, UserNotFoundException, - UserNotActiveException + UserNotActiveException, ) from flask import Blueprint, current_app, jsonify, request diff --git a/backend/app/services/implementations/auth_service.py b/backend/app/services/implementations/auth_service.py index 935766d7..7539553b 100644 --- a/backend/app/services/implementations/auth_service.py +++ b/backend/app/services/implementations/auth_service.py @@ -6,7 +6,7 @@ ) from ...utilities.exceptions.auth_exceptions import ( UserNotActiveException, - UserNotFoundException + UserNotFoundException, ) from ..interfaces.auth_service import IAuthService from ...resources.auth_dto import AuthDTO diff --git a/backend/app/utilities/exceptions/auth_exceptions.py b/backend/app/utilities/exceptions/auth_exceptions.py index 98c26416..ef307c3d 100644 --- a/backend/app/utilities/exceptions/auth_exceptions.py +++ b/backend/app/utilities/exceptions/auth_exceptions.py @@ -7,6 +7,7 @@ def __init__(self): self.message = "This email address has not been invited. Please try again with a different email." super().__init__(self.message) + class UserNotFoundException(Exception): """ Raised when a user is not found in the database by email @@ -16,6 +17,7 @@ def __init__(self): self.message = "This email address does not exist." super().__init__(self.message) + class UserNotActiveException(Exception): """ Raised when a user does not have a user status of Active diff --git a/frontend/src/APIClients/AuthAPIClient.ts b/frontend/src/APIClients/AuthAPIClient.ts index 76c8d637..d036a3e5 100644 --- a/frontend/src/APIClients/AuthAPIClient.ts +++ b/frontend/src/APIClients/AuthAPIClient.ts @@ -123,7 +123,9 @@ const register = async ( } }; -const resetPassword = async (email: string): Promise => { +const resetPassword = async ( + email: string, +): Promise => { const bearerToken = `Bearer ${getLocalStorageObjProperty( AUTHENTICATED_USER_KEY, "accessToken", @@ -148,13 +150,13 @@ const resetPassword = async (email: string): Promise => if (axiosErr.response && axiosErr.response.status === 404) { return { errMessage: - axiosErr.response.data.error ?? - "This email address does not exist.", + axiosErr.response.data.error ?? "This email address does not exist.", }; } return { - errMessage: "Unable to send password reset to this email address. Please try again." - } + errMessage: + "Unable to send password reset to this email address. Please try again.", + }; } }; diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index eb48a88f..bcbc1086 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -41,7 +41,11 @@ const App = (): React.ReactElement => { - + - - Not a member yet? - - history.push(SIGNUP_PAGE)}> + Not a member yet? + history.push(SIGNUP_PAGE)} + > Sign Up Now - history.push(RESET_PASSWORD_PAGE)}> + history.push(RESET_PASSWORD_PAGE)} + > Forgot your password? diff --git a/frontend/src/components/forms/Signup.tsx b/frontend/src/components/forms/Signup.tsx index e8a2c10d..bf5a3d97 100644 --- a/frontend/src/components/forms/Signup.tsx +++ b/frontend/src/components/forms/Signup.tsx @@ -286,10 +286,11 @@ const Signup = ({ - - Already have an account? - - history.push(LOGIN_PAGE)}> + Already have an account? + history.push(LOGIN_PAGE)} + > Log In Now diff --git a/frontend/src/components/pages/Auth/ResetPasswordPage.tsx b/frontend/src/components/pages/Auth/ResetPasswordPage.tsx index 2dff2008..68944c99 100644 --- a/frontend/src/components/pages/Auth/ResetPasswordPage.tsx +++ b/frontend/src/components/pages/Auth/ResetPasswordPage.tsx @@ -1,8 +1,15 @@ -import React, { useState, useContext } from "react"; +import React, { useState } from "react"; import { useHistory } from "react-router-dom"; -import { Box, Button, Flex, FormControl, FormErrorMessage, Input, Spinner, Text } from "@chakra-ui/react"; -import CreateToast from "../../common/Toasts"; -import AuthContext from "../../../contexts/AuthContext"; +import { + Box, + Button, + Flex, + FormControl, + FormErrorMessage, + Input, + Spinner, + Text, +} from "@chakra-ui/react"; import AuthAPIClient from "../../../APIClients/AuthAPIClient"; import { isErrorResponse } from "../../../helper/error"; import { LOGIN_PAGE } from "../../../constants/Routes"; @@ -12,13 +19,15 @@ const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; const ResetPasswordPage = (): React.ReactElement => { const history = useHistory(); - const [email, setEmail] = useState("") + const [email, setEmail] = useState(""); const [emailError, setEmailError] = useState(false); const [emailErrorStr, setEmailErrorStr] = useState(""); - const [resetPasswordClicked, setResetPasswordClicked] = useState(false); + const [resetPasswordClicked, setResetPasswordClicked] = useState( + false, + ); - const [emailSent, setEmailSent] = useState(false) + const [emailSent, setEmailSent] = useState(false); const [isLoading, setIsLoading] = useState(false); const handleEmailChange = (e: React.ChangeEvent) => { @@ -50,14 +59,13 @@ const ResetPasswordPage = (): React.ReactElement => { } setIsLoading(true); - const res = await AuthAPIClient.resetPassword(email) + const res = await AuthAPIClient.resetPassword(email); if (isErrorResponse(res)) { setEmailError(true); setEmailErrorStr(res.errMessage); setIsLoading(false); - } - else { - setEmailSent(true) + } else { + setEmailSent(true); setIsLoading(false); } }; @@ -72,97 +80,99 @@ const ResetPasswordPage = (): React.ReactElement => { alignItems="center" gap="28px" > - { - !emailSent ? ( - <> - - Forgot your password? - - - - - Enter your email address below to recieve an email to reset your password. - - - - - - + + Forgot your password? + + + + + Enter your email address below to recieve an email to reset + your password. + + + + + + + {emailErrorStr} + + + + + {isLoading ? ( + + - {emailErrorStr} - - - - - {isLoading ? ( - - - - ) : ( - - )} - - - - - Remembered your password? - - history.push(LOGIN_PAGE)}> - Log In Now - - - - ) : ( - <> - - Success! - - - - - {`A password reset email has been sent to ${email}. Click the link in the email and after completion, - you'll be able to sign in with your new password. If you did not receive an email, please try again.`} - - - - + ) : ( - - - ) - } + )} + + + + + Remembered your password? + + history.push(LOGIN_PAGE)} + > + Log In Now + + + + + ) : ( + <> + + Success! + + + + + {`A password reset email has been sent to ${email}. Click the link in the email and after completion, + you'll be able to sign in with your new password. If you did not receive an email, please try again.`} + + + + + + + + )}