Skip to content

Commit

Permalink
Modified
Browse files Browse the repository at this point in the history
  • Loading branch information
aadarsh012 committed Sep 20, 2021
1 parent 60465c4 commit 575b437
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 34 deletions.
Binary file removed client/public/favicon.ico
Binary file not shown.
Binary file added client/public/github-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added client/public/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 8 additions & 6 deletions client/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
<meta name="description" content="Web site created using create-react-app" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible&display=swap"
rel="stylesheet"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="shortcut icon" href="icon.png" type="image/x-icon" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand All @@ -24,7 +26,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>Authentication</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file removed client/public/logo192.png
Binary file not shown.
Binary file removed client/public/logo512.png
Binary file not shown.
17 changes: 17 additions & 0 deletions client/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ body {
.App {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

footer {
display: flex;
position: absolute;
width: 100%;
background-color: #5cdb95;
height: 3.5em;
bottom: 0;
justify-content: center;
align-items: center;
}

footer img {
width: 2em;
height: 2em;
}
27 changes: 18 additions & 9 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import Login from "./Components/Login/Login";
import Register from "./Components/Register/Register";
import ForgotPassword from "./Components/ForgotPassword/ForgotPassword";
import ResetPassword from "./Components/ResetPassword/ResetPassword";
import Aux from "./HOC/auxilliary";

function App() {
return (
<div className="App">
<Switch>
<Route path="/passwordreset/:resetToken" component={ResetPassword} />
<Route path="/forgotpassword" component={ForgotPassword} />
<Route exact path="/register" component={Register} />
<Route exact path="/login" component={Login} />
<PrivateRoute exact path="/" />
</Switch>
</div>
<Aux>
<div className="App">
<Switch>
<Route path="/passwordreset/:resetToken" component={ResetPassword} />
<Route path="/forgotpassword" component={ForgotPassword} />
<Route exact path="/register" component={Register} />
<Route exact path="/login" component={Login} />
<PrivateRoute exact path="/" />
</Switch>
</div>
<footer>
<p>Created By AADARSH SHAW | </p>
<a href="https://github.com/aadarsh012">
<img src="github-logo.png" />
</a>
</footer>
</Aux>
);
}

Expand Down
6 changes: 5 additions & 1 deletion client/src/Components/ForgotPassword/ForgotPassword.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import crypto from "crypto";
import { useState, useEffect } from "react";
import classes from "./ForgotPassword.module.css";

Expand All @@ -8,13 +9,15 @@ const ForgotPassword = (props) => {
const [error, setError] = useState("");

useEffect(() => {
document.title = "Forgot Password";
if (localStorage.getItem("authToken")) {
props.history.push("/");
}
}, [props.history]);

const sendEmailHandler = async (event) => {
event.preventDefault();

const config = {
headers: {
"Content-Type": "application/json"
Expand All @@ -23,8 +26,9 @@ const ForgotPassword = (props) => {

try {
const data = await axios.post("/api/auth/forgotpassword", { email }, config);
localStorage.setItem("resetToken", data.data.resetToken);
const resetToken = crypto.createHash("sha256").update(data.data.resetToken).digest("hex");
setSuccess(data.data);
localStorage.setItem("resetToken", resetToken);
} catch (error) {
console.log(error.response.data.error);
setSuccess(false);
Expand Down
1 change: 1 addition & 0 deletions client/src/Components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Login = (props) => {
const [error, setError] = useState("");

useEffect(() => {
document.title = "Login";
if (localStorage.getItem("authToken")) {
props.history.push("/");
}
Expand Down
1 change: 1 addition & 0 deletions client/src/Components/Register/Register.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Register = (props) => {
const [error, setError] = useState("");

useEffect(() => {
document.title = "Register";
if (localStorage.getItem("authToken")) {
props.history.push("/");
}
Expand Down
10 changes: 7 additions & 3 deletions client/src/Components/ResetPassword/ResetPassword.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from "axios";
import crypto from "crypto";
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import classes from "./ResetPassword.module.css";
Expand All @@ -10,9 +11,12 @@ const ResetPassword = (props) => {
const [errorPage, setErrorPage] = useState(false);

useEffect(() => {
const resetToken = localStorage.getItem("resetToken");
if (resetToken !== props.match.params.resetToken) {
localStorage.removeItem("resetToken");
document.title = "Reset Password";
const resetToken = crypto
.createHash("sha256")
.update(props.match.params.resetToken)
.digest("hex");
if (resetToken !== localStorage.getItem("resetToken")) {
setErrorPage(true);
}
}, [props.match]);
Expand Down
4 changes: 4 additions & 0 deletions client/src/HOC/auxilliary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const Aux = (props) => {
return <div>{props.children}</div>;
};
export default Aux;
11 changes: 1 addition & 10 deletions client/src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
font-family: "Atkinson Hyperlegible", sans-serif;
}
8 changes: 3 additions & 5 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ exports.forgotPassword = async (req, res, next) => {
};

exports.resetPassword = async (req, res, next) => {
const resetPasswordToken = crypto
.createHash("sha256")
.update(req.params.resetToken)
.digest("hex");
const resetToken = req.params.resetToken;
const resetPasswordToken = crypto.createHash("sha256").update(resetToken).digest("hex");

try {
const user = await User.findOne({
Expand All @@ -105,7 +103,7 @@ exports.resetPassword = async (req, res, next) => {

await user.save();

res.status(200).json({ success: true, data: "password Reset" });
res.status(200).json({ success: true, data: "Password Reset" });
} catch (error) {
next(error);
}
Expand Down

0 comments on commit 575b437

Please sign in to comment.