Created the reset passowrd component. Linked every page for the lifecycle of the user forgetting his password.
This commit is contained in:
parent
4e80933ea9
commit
24d9bd2c07
@ -1,18 +1,26 @@
|
|||||||
import React, { useState, ChangeEvent, MouseEvent } from "react";
|
import React, { useState, ChangeEvent, MouseEvent } from "react";
|
||||||
import { Card, Button, TextField } from "@mui/material";
|
import { Card, Button, TextField } from "@mui/material";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import "@scss/forgot_password.scss";
|
import "@scss/forgot_password.scss";
|
||||||
|
|
||||||
export default function ForgotPassword() {
|
export default function ForgotPassword() {
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
function handleEmail(e: ChangeEvent<HTMLInputElement>) {
|
function handleEmail(e: ChangeEvent<HTMLInputElement>) {
|
||||||
setEmail(e.target.value);
|
setEmail(e.target.value);
|
||||||
console.log(email);
|
console.log(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buttonCancel(e: MouseEvent<HTMLButtonElement>) {
|
||||||
|
e.preventDefault();
|
||||||
|
navigate("/")
|
||||||
|
}
|
||||||
|
|
||||||
function buttonSubmit(e: MouseEvent<HTMLButtonElement>) {
|
function buttonSubmit(e: MouseEvent<HTMLButtonElement>) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(`Sumbitting email "${email}" to which send a link.`);
|
console.log(`Sumbitting email "${email}" to which send a link.`);
|
||||||
|
navigate("/reset")
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -34,7 +42,7 @@ export default function ForgotPassword() {
|
|||||||
<Button
|
<Button
|
||||||
id="cancel"
|
id="cancel"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={buttonSubmit}
|
onClick={buttonCancel}
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -1,28 +1,31 @@
|
|||||||
import React, { useState, ChangeEvent, MouseEvent } from "react";
|
import React, { useState, ChangeEvent, MouseEvent } from "react";
|
||||||
import { Card, Button, TextField } from "@mui/material"
|
import { Card, Button, TextField } from "@mui/material"
|
||||||
import "@scss/login.scss"
|
import "@scss/login.scss"
|
||||||
|
import { Link, Navigate, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function Login() {
|
export default function Login() {
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
function hash(s: string){
|
function hash(s: string) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEmail(e: ChangeEvent<HTMLInputElement>){
|
function handleEmail(e: ChangeEvent<HTMLInputElement>) {
|
||||||
setEmail(e.target.value);
|
setEmail(e.target.value);
|
||||||
console.log(email);
|
console.log(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePassword(e: ChangeEvent<HTMLInputElement>){
|
function handlePassword(e: ChangeEvent<HTMLInputElement>) {
|
||||||
setPassword(e.target.value);
|
setPassword(e.target.value);
|
||||||
console.log(hash(password));
|
console.log(hash(password));
|
||||||
}
|
}
|
||||||
|
|
||||||
function buttonSubmit(e: MouseEvent<HTMLButtonElement>){
|
function buttonSubmit(e: MouseEvent<HTMLButtonElement>) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
console.log(`Sumbitting username "${email}" and password "${hash(password)}"`)
|
console.log(`Sumbitting username "${email}" and password "${hash(password)}"`)
|
||||||
|
navigate("/main")
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -30,9 +33,9 @@ export default function Login() {
|
|||||||
<Card className="card">
|
<Card className="card">
|
||||||
<h3>Login</h3>
|
<h3>Login</h3>
|
||||||
<TextField className="textfield" id="email" label="Email" value={email} onChange={handleEmail} />
|
<TextField className="textfield" id="email" label="Email" value={email} onChange={handleEmail} />
|
||||||
<TextField className="textfield" id="password" label="Password" type="password" value={password} onChange={handlePassword}/>
|
<TextField className="textfield" id="password" label="Password" type="password" value={password} onChange={handlePassword} />
|
||||||
<Button id="submit" variant="contained" onClick={buttonSubmit}>Login</Button>
|
<Button id="submit" variant="contained" onClick={buttonSubmit}>Login</Button>
|
||||||
<p>Forgot your <a href="/">password</a>?</p>
|
<p>Forgot your <Link to="/forgot">password</Link>?</p>
|
||||||
</Card>
|
</Card>
|
||||||
</main>
|
</main>
|
||||||
)
|
)
|
||||||
|
46
src/components/Reset.tsx
Normal file
46
src/components/Reset.tsx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import React, { useState, ChangeEvent, MouseEvent } from "react";
|
||||||
|
import { Card, Button, TextField } from "@mui/material"
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import "@scss/reset.scss"
|
||||||
|
|
||||||
|
export default function Reset() {
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
const [confirmPassword, setConfirmPassword] = useState("");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
function hash(s: string) {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePassword(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
setPassword(e.target.value);
|
||||||
|
console.log(hash(password));
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleConfirmPassword(e: ChangeEvent<HTMLInputElement>) {
|
||||||
|
setConfirmPassword(e.target.value);
|
||||||
|
console.log(confirmPassword);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buttonSubmit(e: MouseEvent<HTMLButtonElement>) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (password == confirmPassword && password.length != 0){
|
||||||
|
console.log(`Sumbitting password "${hash(password)}"`)
|
||||||
|
navigate("/")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.warn("Passwords are not matching or are empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main id="root">
|
||||||
|
<Card className="card">
|
||||||
|
<h3>Reset Password</h3>
|
||||||
|
<TextField className="textfield" id="password" label="Password" type="password" value={password} onChange={handlePassword} />
|
||||||
|
<TextField className="textfield" id="configrmPassword" label="Confirm Password" type="password" value={confirmPassword} onChange={handleConfirmPassword} />
|
||||||
|
<Button id="submit" variant="contained" onClick={buttonSubmit}>Reset Password</Button>
|
||||||
|
</Card>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
|
}
|
7
src/components/index.tsx
Normal file
7
src/components/index.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import App from "@components/App";
|
||||||
|
import Login from "@components/Login";
|
||||||
|
import ForgotPassword from "@components/ForgotPassword";
|
||||||
|
import Reset from "@components/Reset";
|
||||||
|
import ErrorPage from "@components/ErrorPage";
|
||||||
|
|
||||||
|
export { App, Login, ForgotPassword, Reset, ErrorPage };
|
@ -1,15 +1,27 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { createRoot } from "react-dom/client";
|
import { createRoot } from "react-dom/client";
|
||||||
import App from "@components/App";
|
import { createBrowserRouter, Navigate, RouterProvider } from "react-router-dom";
|
||||||
import ErrorPage from "@components/ErrorPage";
|
import { ErrorPage, Login, ForgotPassword, Reset } from "@components";
|
||||||
import { createBrowserRouter, RouterProvider, Route } from "react-router-dom";
|
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
element: <App />,
|
element: <Navigate to="/login" />,
|
||||||
errorElement: <ErrorPage />,
|
errorElement: <ErrorPage />,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/login",
|
||||||
|
element: <Login />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/forgot",
|
||||||
|
element: <ForgotPassword />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/reset",
|
||||||
|
element: <Reset />,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
createRoot(document.querySelector("#root")).render(
|
createRoot(document.querySelector("#root")).render(
|
||||||
|
2
src/scss/reset.scss
Normal file
2
src/scss/reset.scss
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
@use "style.scss";
|
||||||
|
@use "cards.scss";
|
@ -1,4 +1,2 @@
|
|||||||
$bg1: #333;
|
$bg1: #333;
|
||||||
$fg1: #c5c8c6;
|
$fg1: #c5c8c6;
|
||||||
|
|
||||||
// :export {}
|
|
@ -10,6 +10,7 @@
|
|||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"baseUrl": "./src",
|
"baseUrl": "./src",
|
||||||
"paths" : {
|
"paths" : {
|
||||||
|
"@components": ["components"],
|
||||||
"@components/*": ["components/*"],
|
"@components/*": ["components/*"],
|
||||||
"@scss/*": ["scss/*"],
|
"@scss/*": ["scss/*"],
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user