diff --git a/backend/config/.env b/backend/config/.env index ccd9ae7..9172304 100644 --- a/backend/config/.env +++ b/backend/config/.env @@ -1,4 +1,4 @@ -DEBUG=True -SECRET_KEY=wjtowjatiowjatioawtawt +DEBUG= +SECRET_KEY= DATABASE_USER= -DATABASE_PASSWORD= \ No newline at end of file +DATABASE_PASSWORD= diff --git a/frontend/.env b/frontend/.env index 7b4778e..baf4ed1 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1 @@ -REACT_APP_API_ENDPOINT=https://api.reinvest.space/api \ No newline at end of file +REACT_APP_API_ENDPOINT=https://api.reinvest.space/api diff --git a/frontend/README.md b/frontend/README.md deleted file mode 100644 index 02aac3f..0000000 --- a/frontend/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# Getting Started with Create React App - -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `yarn start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.\ -It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn eject` - -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** - -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. - -Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. - -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. - -## Learn More - -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). - -To learn React, check out the [React documentation](https://reactjs.org/). - -### Code Splitting - -This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) - -### Analyzing the Bundle Size - -This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) - -### Making a Progressive Web App - -This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) - -### Advanced Configuration - -This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) - -### Deployment - -This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) - -### `yarn build` fails to minify - -This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/frontend/public/favicon.ico b/frontend/public/favicon.ico new file mode 100644 index 0000000..a1a02f2 Binary files /dev/null and b/frontend/public/favicon.ico differ diff --git a/frontend/public/index.html b/frontend/public/index.html index b24f39a..56b2456 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -9,6 +9,7 @@ name="description" content="Web site created using create-react-app" /> + <link rel="icon" href="favicon.png" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <title>ReInvest</title> </head> diff --git a/frontend/src/App.css b/frontend/src/App.css index e69de29..de9289c 100644 --- a/frontend/src/App.css +++ b/frontend/src/App.css @@ -0,0 +1,5 @@ +@import url("https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;700&display=swap"); + +* { + font-family: "Source Sans Pro" !important; +} diff --git a/frontend/src/App.js b/frontend/src/App.js index 4925f46..cc2f6e4 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -4,46 +4,27 @@ import Portfolio from "./components/Portfolio"; import Bank from "./components/Bank"; import Profile from "./components/Profile"; import Browse from "./components/Browse"; -import Login from "./components/Login"; import Nav from "./components/Nav"; +import Signin from "./components/auth/Signin"; +import Signup from "./components/auth/Signup"; + import "./App.css"; +import ProtectedRoute from "./components/ProtectedRoute"; function App() { - const adminUser = { - email: "admin@admin.com", - password: "admin123", - }; - - const [user, setUser] = useState({ name: "", email: "" }); - const [error, setError] = useState(""); - - const Login = (details) => { - console.log(details); - }; - - const Logout = () => { - console.log("Logout"); - }; - return ( <div className="App"> <BrowserRouter> <Nav /> <Switch> - <Route component={Bank} path="/banking" /> - <Route component={Browse} path="/browse" /> - <Route component={Profile} path="/profile" /> - <Route component={Portfolio} path="/" /> + <Route component={Signup} path="/register" /> + <Route component={Signin} path="/login" /> + <ProtectedRoute component={Bank} path="/banking" /> + <ProtectedRoute component={Browse} path="/browse" /> + <ProtectedRoute component={Profile} path="/profile" /> + <ProtectedRoute exact component={Portfolio} path="/" /> </Switch> </BrowserRouter> - {/* {(user.email !== "") ? ( - <div className="welcome"> - <h2>Welcome, <span>{user.name}</span></h2> - <button>Logout</button> - </div> - ) : ( - <Login/> - )} */} </div> ); } diff --git a/frontend/src/components/Bank.js b/frontend/src/components/Bank.js index 8d5c8a3..b5fee8f 100644 --- a/frontend/src/components/Bank.js +++ b/frontend/src/components/Bank.js @@ -3,6 +3,8 @@ import "./assets/Portfolio.css"; const Bank = (props) => { const [state, setState] = useState({}); + const [bruh, setBruh] = useState(1); + useEffect(() => { callAPI(); }); @@ -15,9 +17,9 @@ const Bank = (props) => { }; return ( - <div className="container"> - <h1 className="d-flex justify-content-center m-2 p-4">Bank</h1> - <h1></h1> + <div class="container"> + <h1 class="d-flex justify-content-center m-2 p-4">Bank</h1> + <h1>{process.env.REACT_APP_API_ENDPOINT}</h1> </div> ); }; diff --git a/frontend/src/components/Login.js b/frontend/src/components/Login.js deleted file mode 100644 index 1f2ec84..0000000 --- a/frontend/src/components/Login.js +++ /dev/null @@ -1,25 +0,0 @@ -import React from "react"; - -const Login = (props) => { - return ( - <form> - <div className="form-inner"> - <h2>Login</h2> - <div className="form-group"> - <label htmlFor="name">Name:</label> - <input type="text" name="name" id="name" /> - </div> - <div className="form-group"> - <label htmlFor="email">Email: </label> - <input type="email" name="email" id="email" /> - </div> - <div className="form-group"> - <label htmlFor="password">Password:</label> - <input type="password" name="password" id="password" /> - </div> - </div> - </form> - ); -}; - -export default Login; diff --git a/frontend/src/components/ProtectedRoute.js b/frontend/src/components/ProtectedRoute.js new file mode 100644 index 0000000..d348fa0 --- /dev/null +++ b/frontend/src/components/ProtectedRoute.js @@ -0,0 +1,49 @@ +import React from "react"; +import { Route, Redirect } from "react-router-dom"; + +const ProtectedRoute = ({ component: Component, ...rest }) => { + const isAuthenticated = async () => { + try { + const requestOptions = { + method: "GET", + headers: { Authorization: `JWT ${localStorage.getItem("token")}` }, + }; + const response = await fetch( + `${process.env.REACT_APP_API_ENDPOINT}/profile`, + requestOptions + ); + + if (response.status === 200) { + return true; + } else { + return false; + } + } catch (e) { + return false; + } + }; + + return ( + <Route + {...rest} + render={(props) => { + if (isAuthenticated()) { + return <Component {...props} {...rest} />; + } else { + return ( + <Redirect + to={{ + pathname: "/", + state: { + from: props.location, + }, + }} + /> + ); + } + }} + /> + ); +}; + +export default ProtectedRoute; diff --git a/frontend/src/components/assets/Register.css b/frontend/src/components/assets/Register.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/components/auth/Signin.js b/frontend/src/components/auth/Signin.js new file mode 100644 index 0000000..6039eb7 --- /dev/null +++ b/frontend/src/components/auth/Signin.js @@ -0,0 +1,65 @@ +import React, { useState } from "react"; +import { useHistory } from "react-router-dom"; + +const Signup = (props) => { + let history = useHistory(); + + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + + const onSubmit = async (e) => { + e.preventDefault(); + const requestOptions = { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ username: username, password: password }), + }; + try { + const response = await fetch( + `${process.env.REACT_APP_API_ENDPOINT}/token`, + requestOptions + ); + const data = await response.json(); + + localStorage.setItem("token", data.token); + history.push("/"); + } catch (e) { + console.error(e); + } + }; + + return ( + <form onSubmit={onSubmit}> + <div className="form-inner"> + <h2>Login</h2> + <div className="form-group"> + <label htmlFor="name">Username:</label> + <input + type="text" + onChange={(e) => { + setUsername(e.target.value); + }} + value={username} + name="name" + id="name" + /> + </div> + <div className="form-group"> + <label htmlFor="password">Password:</label> + <input + type="password" + onChange={(e) => { + setPassword(e.target.value); + }} + value={password} + name="password" + id="password" + /> + </div> + </div> + <button type="submit">Submit</button> + </form> + ); +}; + +export default Signup; diff --git a/frontend/src/components/auth/Signup.js b/frontend/src/components/auth/Signup.js new file mode 100644 index 0000000..96a0368 --- /dev/null +++ b/frontend/src/components/auth/Signup.js @@ -0,0 +1,127 @@ +import React, { useState } from "react"; +import { useHistory } from "react-router-dom"; + +const Signup = (props) => { + let history = useHistory(); + + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + const [verifyPassword, setVerifyPassword] = useState(""); + const [email, setEmail] = useState(""); + const [firstName, setFirstName] = useState(""); + const [lastName, setLastName] = useState(""); + + const onSubmit = async (e) => { + e.preventDefault(); + if (verifyPassword !== password) { + alert("The passwords don't match!"); + return; + } + const requestOptions = { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + username: username, + password: password, + email: email, + first_name: firstName, + last_name: lastName, + }), + }; + try { + const response = await fetch( + `${process.env.REACT_APP_API_ENDPOINT}/profile/create`, + requestOptions + ); + const data = await response.json(); + console.log(data.username); + + history.push("/login"); + } catch (e) { + console.error(e); + } + }; + + return ( + <form onSubmit={onSubmit}> + <div className="form-inner"> + <h2>Register</h2> + <div className="form-group"> + <label htmlFor="name">Username:</label> + <input + type="text" + onChange={(e) => { + setUsername(e.target.value); + }} + value={username} + name="name" + id="name" + /> + </div> + <div className="form-group"> + <label htmlFor="password">Password:</label> + <input + type="password" + onChange={(e) => { + setPassword(e.target.value); + }} + value={password} + name="password" + id="password" + /> + </div> + <div className="form-group"> + <label htmlFor="password">Verify Password:</label> + <input + type="password" + onChange={(e) => { + setVerifyPassword(e.target.value); + }} + value={verifyPassword} + name="password" + id="password" + /> + </div> + <div className="form-group"> + <label htmlFor="name">Email:</label> + <input + type="text" + onChange={(e) => { + setEmail(e.target.value); + }} + value={email} + name="name" + id="name" + /> + </div> + <div className="form-group"> + <label htmlFor="name">First Name:</label> + <input + type="text" + onChange={(e) => { + setFirstName(e.target.value); + }} + value={firstName} + name="name" + id="name" + /> + </div> + <div className="form-group"> + <label htmlFor="name">Last Name:</label> + <input + type="text" + onChange={(e) => { + setLastName(e.target.value); + }} + value={lastName} + name="name" + id="name" + /> + </div> + </div> + <button type="submit">Submit</button> + </form> + ); +}; + +export default Signup;