diff --git a/Backend/server.js b/Backend/server.js index 8769862..b1df5e6 100644 --- a/Backend/server.js +++ b/Backend/server.js @@ -175,6 +175,27 @@ app.get('/loginUser', async (req, res) => { return res.status(code).json(json); }) +app.get('/registerAccount', async (req, res) => { + const username = req.query.username; + const password = req.query.password; + + if (!username || !password) { + return res.status(400).json({message: "Input both a username and password"}); + } + + let db = getDb(); + let user = await db.find({"username" : username}) + user = await user.toArray(); + + if (user.length > 0) { + return res.status(400).json({message: "Username already taken"}); + } + + const hashedPassword = await bcrypt.hash(password, 10); + db.insertOne({username: username, password: hashedPassword, canvasUser: null, lastLogin: null, lastLogout: null}) + return res.status(200).json({message: "User registered"}); +}); + app.get('/', async (req, res) => { res.status(200).json({ message: "hello!" }); }); diff --git a/Frontend/src/App.jsx b/Frontend/src/App.jsx index 418c8ab..9f9b7d7 100644 --- a/Frontend/src/App.jsx +++ b/Frontend/src/App.jsx @@ -4,7 +4,7 @@ import './App.css' import Login from "./Login" const API_URL = "http://localhost:3500" -const API_KEY = +const API_KEY = "nolol" function App() { const [courses, setCourses] = useState(null); diff --git a/Frontend/src/Login.jsx b/Frontend/src/Login.jsx index 4b7860d..d00b428 100644 --- a/Frontend/src/Login.jsx +++ b/Frontend/src/Login.jsx @@ -1,36 +1,56 @@ import { useState } from "react"; import axios from "axios" import logo from "./img/temp.png" -import bcrypt from "bcryptjs" +import PropTypes from "prop-types"; import "./css/Login.css" const API_URL = "http://localhost:3500" -const saltRounds = 10; export default function Login() { const [username, setUser] = useState(""); const [password, setPassword] = useState(""); + const [canvasAPIKey, setCanvasAPIKey] = useState(""); const [logState, setLogState] = useState("login"); const handleSubmit = (e) => { - e.preventDefault(); - attemptLogin(); - alert("Username: " + username + " " + "Password: " + password); + e.preventDefault(); + attemptLogin(); + alert("Username: " + username + " " + "Password: " + password); }; const attemptLogin = async () => { - if (logState == "login") { + if (logState === "login") { const temp = await axios.get(`${API_URL}/loginUser`, { params: { "username": username, "password": password - } + } }) console.log(temp) - } else if (logState == "create") { - + } else if (logState === "create") { + try { + const temp = await axios.get(`${API_URL}/registerAccount`, { + params: { + "username": username, + "password": password + } + }) + localStorage.setItem("canvasAPIKey", canvasAPIKey) + + console.log(temp) + } catch (e) { + console.log("account creation failed") + } + } + } + + const toggleLoginState = () => { + if (logState === "login") { + setLogState("create") + } else { + setLogState("login") } } @@ -39,27 +59,47 @@ export default function Login() { Cat Corporate

Welcome to Cat Corporate!!!

handleSubmit(e)}> -
-

Username

- setUser(e.target.value)} - type="text" /> -
-
-

Password

- setPassword(e.target.value)} - type="password"/> -
-
- -
-

New User?

-

Forgot Password?

-
-
+
+

Username

+ setUser(e.target.value)} + type="text" /> +
+
+

Password

+ setPassword(e.target.value)} + type="password"/> +
+ { + logState === "create" && + } + +
+
+ +

Forgot Password?

+
+
© 2024 Cat Corporate ); } + +function CanvasAPIKeyContainer({ keyVal, setKey }) { + return ( +
+

Canvas API Key

+ setKey(e.target.value)} + type="password"/> +
+ ) +} + +CanvasAPIKeyContainer.propTypes = { + keyVal: PropTypes.string, + setKey: PropTypes.func +}