This project is live on heroku: FAC Guidebook
-
Clone of fork the repo
-
Go into the project folder
cd FAC_guidebook2.0
-
Run
npm i
-
Create a file
config.env
in your root directory and save the database credentials in this format:export DB_URL = postgres://_your_db_info_
-
Run
npm start
-
Go to
localhost:5000
for the home page -
Start contributing to FAC-guidebook! 💕
- For testing: run
npm test
(Database testing need additional credentials)
-
User can view 👀 existing posts
- Pull and display data from db
-
Click to add ➕ own post
- Check for cookie to see if user is logged in
-
If not logged in 🔓 : Prompted to login or signup
- (If logged in, jump to step 6)
-
User signs up 🔏
- Client side validation - check that password is at least 8 chars, with at least 1 numb, 1 uppercase and 1 lowercase
- Server side - Check if user name already exists in the db
- If no error, submit form to new row in USERS table with a HASHED password
-
User logs in 🔑
- Server side - check that username is present in db, then check that the hash of the input matches that user's hashed password.
- If success, creates a JWT with info about specific user
-
User can now access the post form (protected route) 📃
-
User submits post form 📃
- Client side - check that fields are not empty
- Server side - check if the restaurant already exists/that a post hasn't already been made referencing it
- If success, submit form to POSTS table and RESTAURANTS table
-
User can view 👀 updated home page!
- Creating a new database on Heroku and linking it to the new repo (this took longer than expected, we're still not sure why!)
- Signup form validation on the client side (unmatching passwords, patterns)
- We spent a long time tracking our callback functions through different files to figure out where to put the login form validation (to compare the password in the database with the password that is submitted)
- whiteboard coding
- Updated our user journey
-
Client-side validation for the sign up page
-
Handling the USER LOGIN logic:
- First step:
const handlerLogin = (req, res) => {
let body = "";
req.on("data", function(data) {
body += data;
});
req.on("end", function() {
const {userName, password} = qs.parse(body);
console.log(userName, password);
getData.getUserData((err, result)=>{
let loggedIn = false;
if(err){
console.log(err);
} else {
result.forEach((user)=>{
if(user.name === userName && user.password === password){
console.log("correct user details");
loggedIn = true;
return;
} else {
console.log("user doesn't exist!");
}
});
if(!loggedIn){
res.writeHead(302, {
Location: "http://localhost:5000/public/login.html"
});
res.end();
} else {
res.writeHead(302, {
Location: "http://localhost:5000/public/form.html"
});
res.end();
}
}
})
});
};
-
Refactor with bcryptjs?
-
We created two promises. Here's one:
const promiseSpecificUser = name => {
return new Promise((resolve, reject) => {
dbConnection.query(
`SELECT * FROM users WHERE name = '${name}'`, (err, res) => {
if (err) reject(err);
else resolve(res.rows);
});
});
}
-
Signup form validation:
-
Client side - check that password is at least 8 chars, with at least 1 numb, 1 uppercase and 1 lowercase.
-
Server side - Check is user name already exists in the db
-
Server side - check that username is present in db, then check that the hash of the input matches that user's hashed password!
-
Post form validation (everything we had in there last week...)
- Add logout button & home button
- Add the required rules for the password validation
- Handle the length of the resturant review
- Travis CI - All passing! 💚