Skip to content

Commit

Permalink
linterrr
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor Bechthold committed Feb 2, 2024
1 parent dd5038f commit 950222e
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 109 deletions.
2 changes: 1 addition & 1 deletion backend/app/rest/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..utilities.exceptions.auth_exceptions import (
EmailAlreadyInUseException,
UserNotFoundException,
UserNotActiveException
UserNotActiveException,
)

from flask import Blueprint, current_app, jsonify, request
Expand Down
2 changes: 1 addition & 1 deletion backend/app/services/implementations/auth_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions backend/app/utilities/exceptions/auth_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/APIClients/AuthAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const register = async (
}
};

const resetPassword = async (email: string): Promise<boolean | ErrorResponse> => {
const resetPassword = async (
email: string,
): Promise<boolean | ErrorResponse> => {
const bearerToken = `Bearer ${getLocalStorageObjProperty(
AUTHENTICATED_USER_KEY,
"accessToken",
Expand All @@ -148,13 +150,13 @@ const resetPassword = async (email: string): Promise<boolean | ErrorResponse> =>
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.",
};
}
};

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const App = (): React.ReactElement => {
<Switch>
<Route exact path={Routes.LOGIN_PAGE} component={LoginPage} />
<Route exact path={Routes.SIGNUP_PAGE} component={SignupPage} />
<Route exact path={Routes.RESET_PASSWORD_PAGE} component={ResetPasswordPage} />
<Route
exact
path={Routes.RESET_PASSWORD_PAGE}
component={ResetPasswordPage}
/>
<PrivateRoute
exact
path={Routes.VERIFICATION_PAGE}
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/forms/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,21 @@ const Login = ({
</Box>
<Box w="80%">
<Flex gap="10px">
<Text variant="loginSecondary">
Not a member yet?
</Text>
<Text variant="loginTertiary" onClick={() => history.push(SIGNUP_PAGE)}>
<Text variant="loginSecondary">Not a member yet?</Text>
<Text
variant="loginTertiary"
onClick={() => history.push(SIGNUP_PAGE)}
>
Sign Up Now
</Text>
</Flex>
</Box>
<Box w="80%">
<Flex gap="10px">
<Text variant="loginTertiary" onClick={() => history.push(RESET_PASSWORD_PAGE)}>
<Text
variant="loginTertiary"
onClick={() => history.push(RESET_PASSWORD_PAGE)}
>
Forgot your password?
</Text>
</Flex>
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/components/forms/Signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,11 @@ const Signup = ({
</Box>
<Box w="80%">
<Flex gap="10px">
<Text variant="loginSecondary">
Already have an account?
</Text>
<Text variant="loginTertiary" onClick={() => history.push(LOGIN_PAGE)}>
<Text variant="loginSecondary">Already have an account?</Text>
<Text
variant="loginTertiary"
onClick={() => history.push(LOGIN_PAGE)}
>
Log In Now
</Text>
</Flex>
Expand Down
194 changes: 102 additions & 92 deletions frontend/src/components/pages/Auth/ResetPasswordPage.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<string>("")
const [email, setEmail] = useState<string>("");
const [emailError, setEmailError] = useState<boolean>(false);
const [emailErrorStr, setEmailErrorStr] = useState<string>("");

const [resetPasswordClicked, setResetPasswordClicked] = useState<boolean>(false);
const [resetPasswordClicked, setResetPasswordClicked] = useState<boolean>(
false,
);

const [emailSent, setEmailSent] = useState<boolean>(false)
const [emailSent, setEmailSent] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(false);

const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -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);
}
};
Expand All @@ -72,97 +80,99 @@ const ResetPasswordPage = (): React.ReactElement => {
alignItems="center"
gap="28px"
>
{
!emailSent ? (
<>
<Box w="80%" textAlign="left">
<Text variant="login">Forgot your password?</Text>
</Box>

<Box w="80%" textAlign="left">
<Text variant="loginSecondary">
Enter your email address below to recieve an email to reset your password.
</Text>
</Box>

<Box w="80%">
<FormControl isRequired isInvalid={emailError}>
<Input
variant="login"
placeholder="Your email address"
value={email}
onChange={handleEmailChange}
{!emailSent ? (
<>
<Box w="80%" textAlign="left">
<Text variant="login">Forgot your password?</Text>
</Box>

<Box w="80%" textAlign="left">
<Text variant="loginSecondary">
Enter your email address below to recieve an email to reset
your password.
</Text>
</Box>

<Box w="80%">
<FormControl isRequired isInvalid={emailError}>
<Input
variant="login"
placeholder="Your email address"
value={email}
onChange={handleEmailChange}
/>
<FormErrorMessage>{emailErrorStr}</FormErrorMessage>
</FormControl>
</Box>

<Box w="80%">
{isLoading ? (
<Flex flexDirection="column" alignItems="center">
<Spinner
thickness="4px"
speed="0.65s"
emptyColor="gray.200"
size="lg"
margin="0 auto"
textAlign="center"
/>
<FormErrorMessage>{emailErrorStr}</FormErrorMessage>
</FormControl>
</Box>

<Box w="80%">
{isLoading ? (
<Flex flexDirection="column" alignItems="center">
<Spinner
thickness="4px"
speed="0.65s"
emptyColor="gray.200"
size="lg"
margin="0 auto"
textAlign="center"
/>
</Flex>
) : (
<Button
variant="login"
onClick={handleResetPassword}
_hover={{
background: "teal.500",
transition:
"transition: background-color 0.5s ease !important",
}}
>
Send Reset Password Email
</Button>
)}
</Box>
<Box w="80%">
<Flex gap="10px">
<Text variant="loginSecondary">
Remembered your password?
</Text>
<Text variant="loginTertiary" onClick={() => history.push(LOGIN_PAGE)}>
Log In Now
</Text>
</Flex>
</Box>
</>
) : (
<>
<Box w="80%" textAlign="left">
<Text variant="login">Success!</Text>
</Box>

<Box w="80%" textAlign="left">
<Text variant="loginSecondary">
{`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.`}
</Text>
</Box>

<Box w="80%">
) : (
<Button
variant="login"
onClick={() => history.push(LOGIN_PAGE)}
onClick={handleResetPassword}
_hover={{
background: "teal.500",
transition:
"transition: background-color 0.5s ease !important",
}}
>
Back To Login
>
Send Reset Password Email
</Button>
</Box>
</>
)
}
)}
</Box>
<Box w="80%">
<Flex gap="10px">
<Text variant="loginSecondary">
Remembered your password?
</Text>
<Text
variant="loginTertiary"
onClick={() => history.push(LOGIN_PAGE)}
>
Log In Now
</Text>
</Flex>
</Box>
</>
) : (
<>
<Box w="80%" textAlign="left">
<Text variant="login">Success!</Text>
</Box>

<Box w="80%" textAlign="left">
<Text variant="loginSecondary">
{`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.`}
</Text>
</Box>

<Box w="80%">
<Button
variant="login"
onClick={() => history.push(LOGIN_PAGE)}
_hover={{
background: "teal.500",
transition:
"transition: background-color 0.5s ease !important",
}}
>
Back To Login
</Button>
</Box>
</>
)}
</Flex>
</Box>

Expand Down

0 comments on commit 950222e

Please sign in to comment.