diff --git a/server.js b/server.js index d38c2bf..98949af 100644 --- a/server.js +++ b/server.js @@ -46,32 +46,83 @@ app.post("/register", (req, res) => { const lastname = req.body.lastname; const phone = req.body.phone; - bcrypt.hash(password, saltRounds, (err, hash) => { - if (err) { - console.log(err); - } + db.query( + "SELECT * FROM account WHERE username = ?", + username, + (err, result) => { + if (err) { + console.log(err); + } + if (result.length > 0) { + return res.send({ message: "User account already exists!" }); + + } else { + bcrypt.hash(password, saltRounds, (err, hash) => { + if (err) { + console.log(err); + } + + const data = [ + username, + email, + address, + hash, + firstname, + lastname, + phone + ]; - const data = [ - username, - email, - address, - hash, - firstname, - lastname, - phone - ]; - - const query = "INSERT INTO account (username, email, address, password, first_name, last_name, phone_num) VALUES (?, ?, ?, ?, ?, ?, ?);"; - db.query( - query, data, - (err, result) => { - if (err) { - res.send({ err: err }); - } + const query = "INSERT INTO account (username, email, address, password, first_name, last_name, phone_num) VALUES (?, ?, ?, ?, ?, ?, ?);"; + db.query( + query, data, + (err, result) => { + if (err) { + res.send({ err: err }); + } + res.send({ message: "You have been successfully registered!" }); + } + ); + }); } - ); - }); + } + ) }); + +app.post('/signin', (req, res) => +{ + const username = req.body.username; + const password = req.body.password; + + db.query( + "SELECT * FROM account WHERE username = ?", + username, + (err, result) => + { + if(err) + { + res.send({err: err}) + } + + if (result.length > 0) + { + bcrypt.compare(password, result[0].password, (error, response) => + { + if(response) + { + res.send(result) + } else + { + res.send({ message: "Incorrect username or password" }) + } + }) + } else + { + res.send({ message: "Incorrect username" }) + } + } + ); +}) + // start express server on port 5000 server.listen(5000, () => { console.log('NodeJS server running'); diff --git a/src/App.js b/src/App.js index 7da904f..d5e4d89 100644 --- a/src/App.js +++ b/src/App.js @@ -2,6 +2,7 @@ import React from "react"; import Registration from "./Pages/RegistrationPage/RegistrationPage"; import Home from "./Pages/HomePage/HomePage" import Product from "./Pages/ProductPage/ProductPage" +import SignIn from "./Pages/SignInPage/SignInPage" import "./GeneralStyles.css"; import { BrowserRouter as Router, @@ -21,9 +22,14 @@ function App() { Register   Product +   + Sign In + + + diff --git a/src/Pages/ProductPage/ProductPage.css b/src/Pages/ProductPage/ProductPage.css index 40599c3..7de889d 100644 --- a/src/Pages/ProductPage/ProductPage.css +++ b/src/Pages/ProductPage/ProductPage.css @@ -7,6 +7,13 @@ text-align: center; } +.image1{ + position: relative; + right: 450px; + top: 100px; + border-radius: 100px; +} + .panel1 { height: 500px; font-family: 'Times New Roman', Times, serif; @@ -29,6 +36,7 @@ */ .header2 { position: relative; + top: -350px; left: 55%; height: 500px; width: 40%; @@ -41,6 +49,7 @@ .panel1 button { position: relative; + top: -350px; left: 25%; width: 15%; } \ No newline at end of file diff --git a/src/Pages/ProductPage/ProductPage.js b/src/Pages/ProductPage/ProductPage.js index 55b28b6..685dc71 100644 --- a/src/Pages/ProductPage/ProductPage.js +++ b/src/Pages/ProductPage/ProductPage.js @@ -1,6 +1,10 @@ import "./ProductPage.css" +import image from "../../images/testglasses.jpg"; function Product() { + let name = "Test Glasses"; + let manufacturer = "Stark Industries" + let cost = 99.99; return (
@@ -9,10 +13,16 @@ function Product() {
{/* create an overall panel, with header 2, the image, and the button inside of it */}
+
+ +
-

Name:

-

Manufacturer:

-

Cost:

+

Name: {name}

+

Manufacturer: {manufacturer}

+

Cost: {cost}

diff --git a/src/Pages/RegistrationPage/RegistrationPage.css b/src/Pages/RegistrationPage/RegistrationPage.css index d1a52e6..291bd12 100644 --- a/src/Pages/RegistrationPage/RegistrationPage.css +++ b/src/Pages/RegistrationPage/RegistrationPage.css @@ -1,6 +1,6 @@ .information { display: flex; - height: 100%; + min-height: 100vh; width: 100%; flex-direction: column; justify-content: center; diff --git a/src/Pages/RegistrationPage/RegistrationPage.js b/src/Pages/RegistrationPage/RegistrationPage.js index d845f8e..2229dbe 100644 --- a/src/Pages/RegistrationPage/RegistrationPage.js +++ b/src/Pages/RegistrationPage/RegistrationPage.js @@ -12,6 +12,8 @@ function Registration() { const [lastname, setLastname] = useState(0); const [phone, setPhone] = useState(""); + const [registrationStatus, setRegistrationStatus] = useState(""); + let history = useHistory(); const registerUser = () => { @@ -24,12 +26,21 @@ function Registration() { lastname: lastname, phone: phone }; + + let emptyField = Object.values(data).includes(""); + if (emptyField) { + setRegistrationStatus("You must fill out all fields before continuing"); + return; + } + Axios.post("http://localhost:5000/register", data).then((response) => { if (response.data.error) { alert(response.data.error); console.log("error!"); } else { - console.log(response); + if (response.data.message) { + setRegistrationStatus(response.data.message); + } /*history.push("/");*/ } }); @@ -49,7 +60,7 @@ function Registration() { setPassword(event.target.value); }} /> - + { setEmail(event.target.value); @@ -80,6 +91,7 @@ function Registration() { }} /> +

{registrationStatus}

); } diff --git a/src/Pages/SignInPage/SignInPage.css b/src/Pages/SignInPage/SignInPage.css new file mode 100644 index 0000000..62ef674 --- /dev/null +++ b/src/Pages/SignInPage/SignInPage.css @@ -0,0 +1,23 @@ +.signin-wrapper { + display: flex; + flex-direction: column; + width: 100%; + justify-content: center; + align-items: center; + background-color: aqua; + min-height: 100vh; +} + +.signin-wrapper input { + width: 250px; + height: 50px; + font-size: 20px; + padding-left: 10px; + margin: 5px; +} + +.signin-wrapper button { + width: 320px; + height: 50px; + margin-top: 15px; +} \ No newline at end of file diff --git a/src/Pages/SignInPage/SignInPage.js b/src/Pages/SignInPage/SignInPage.js new file mode 100644 index 0000000..298e877 --- /dev/null +++ b/src/Pages/SignInPage/SignInPage.js @@ -0,0 +1,53 @@ +import React, { useState } from 'react'; +import Axios from "axios"; +import './SignInPage.css'; + +function SignIn() { + const [username, setUsername] = useState(""); + const [password, setPassword] = useState(""); + + const [loginStatus, setLoginStatus] = useState(""); + + const login = () => { + Axios.post("http://localhost:5000/signin", + { + username: username, + password: password, + }).then((response) => { + if (response.data.message) { + setLoginStatus(response.data.message); + } else { + setLoginStatus(response.data[0].username); + } + + }); + }; + + return ( +
+
+

Sign In

+ { + setUsername(e.target.value); + }} + /> + + { + setPassword(e.target.value); + }} + /> +
+ +
+

{loginStatus}

+
+
+ ); +} +export default SignIn; \ No newline at end of file