Skip to content

Commit

Permalink
558 create forgot password (#567)
Browse files Browse the repository at this point in the history
* email input and submit button

* fixed indentation errors

* update Forgot password to match other requests

* fixing lint errors

---------

Co-authored-by: Kevin Monisit <[email protected]>
  • Loading branch information
avsomers25 and kevinmonisit authored Aug 30, 2023
1 parent 254592c commit 1952bcb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
89 changes: 46 additions & 43 deletions src/components/Forgot.jsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
import React, { useState } from "react";
// import { Container, Grid, createMuiTheme, ThemeProvider} from "@material-ui/core";
import { Container, Grid } from "@material-ui/core";
import { Container, Grid, createMuiTheme, ThemeProvider} from "@material-ui/core";
//import { Container, Grid } from "@material-ui/core";
import Alert from "@material-ui/lab/Alert";
import { Link } from "react-router-dom";
import { Redirect } from "react-router-dom";
import AuthForm from "../library/AuthForm";
import ColorButton from "../library/ColorButton";
// import WhiteTextField from "../library/WhiteTextField";
import WhiteTextField from "../library/WhiteTextField";
import PropTypes from "prop-types";
// import { theme } from "../Defaults";
import { theme } from "../Defaults";

/**
* Forgot my password application for "/forgot"
*/
// const color_theme = createMuiTheme({

// overrides: {
// palette: {
// primary: {
// main: theme.primary[1].trim(),
// },
// secondary: {
// main: theme.secondary[1].trim(),
// },
// },
// MuiInputLabel: {
// root: {
// color: "white",
// "&$focused": {
// color: "white"
// }
// }
// }
// }
// });
const color_theme = createMuiTheme({

overrides: {
palette: {
primary: {
main: theme.primary[1].trim(),
},
secondary: {
main: theme.secondary[1].trim(),
},
},
MuiInputLabel: {
root: {
color: "white",
"&$focused": {
color: "white"
}
}
}
}
});



const ForgotPage = (props) => {
Expand All @@ -42,23 +43,22 @@ const ForgotPage = (props) => {
const [done, setDone] = useState(false);
const [errors, setErrors] = useState("");

const onSubmit = (e) => {
const onSubmit = async (e) => {
e.preventDefault();
if (!loading) {
setLoading(true);
setErrors("");
let email = document.getElementById("email").value;
props.profile.Forgot(email)
.then((msg) => {
if (msg.error) {
setLoading(false);
setErrors(msg.error);
} else {
setLoading(false);
setDone(true);
setErrors("");
}
});
let msg = await props.profile.Forgot(email);
if (msg.error) {
setLoading(false);
setErrors(msg.error);
} else {
setLoading(false);
setDone(true);
setErrors("");
}

}
};

Expand Down Expand Up @@ -102,7 +102,7 @@ const ForgotPage = (props) => {
spacing={2}>
<Grid item
xs={12}>
{/* <ThemeProvider theme={color_theme}>
{<ThemeProvider theme={color_theme}>
<WhiteTextField
variant="outlined"
autofocus
Expand All @@ -114,14 +114,15 @@ const ForgotPage = (props) => {
autoComplete="email"
size="small"
/>
</ThemeProvider> */}
</ThemeProvider> }
{/*
<div>
Please reach out to [email protected] to reset password
</div>
</div>*/}
</Grid>
<Grid item
xs={12}>
{/* <ThemeProvider theme={color_theme}>
{<ThemeProvider theme={color_theme}>
<ColorButton
size = "small"
type="submit"
Expand All @@ -131,7 +132,8 @@ const ForgotPage = (props) => {
Submit
</ColorButton>

</ThemeProvider> */}
</ThemeProvider> }
{/*
<a href="mailto:[email protected]?subject=[HackRU Password Reset]"
target="_blank"
rel="noopener noreferrer">
Expand All @@ -143,7 +145,8 @@ const ForgotPage = (props) => {
color="primary">
Email Us
</ColorButton>
</a>
</a>*/}
</Grid>
<Grid item
xs={12}>
Expand Down
24 changes: 12 additions & 12 deletions src/components/Profile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//import { ControlCameraSharp } from "@material-ui/icons";
import { defaults } from "../Defaults";
import PropTypes from "prop-types";

Expand Down Expand Up @@ -486,34 +487,33 @@ class Profile {
} else {
await fetch(ENDPOINTS.forgot, {
method: "POST",
body: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
forgot: true,
},
json: true,
}),
})
.then((res) => {
if (res.statusCode === 200) {
.then(async (res) => {
let resJSON = await res.json();
if (resJSON.statusCode === 200) {
return resp;
} else {
if (res.errorMessage) {
console.error(res.errorMessage);
}
if (res.body) {
return res.body;
if (resJSON.body) {
resp.error = resJSON.body;
} else {
resp.error = "Unexpected Error";
return resp;
}
}
})
.catch((error) => {
resp.error =
error +
"An error occured when attempting to general url";
return resp;
});
}
return resp;
}
}
async Reset(email, password, conpassword, magic) {
Expand Down

0 comments on commit 1952bcb

Please sign in to comment.