Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a3-jimmyjam100-James-Scherick #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.DS_Store
node_modules/
package-lock.json
84 changes: 16 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,22 @@
Assignment 3 - Persistence: Two-tier Web Application with Flat File Database, Express server, and CSS template
===
## Food You Eat

Due: September 16th, by 11:59 AM.
https://a3-jamesscherick.glitch.me

This assignnment continues where we left off, extending it to use the most popular Node.js server framework (express), a flat file database suitable for small applications (lowdb), and a CSS application framework / template of your choice (Boostrap, Material Design, Semantic UI, Pure etc.)
![What the website looks like after logging in](https://github.com/jimmyjam100/a3-persistence/blob/master/image.PNG)

The goal of this application is to have a place where everyone can have a personal list of all of the different types of food they eat so they can keep track of their diet.
To log in enter any unused username to create a new account, or use an existing username and password.
It took me many many hours to figure out how the authentification process worked. I would redirect to the home page and then be redirected right back because the login session did not save. Turned out I needed to add more middleware that I did not know about.
The authentification stratagy I used was just local, and for database I ended up just writing and reading from a json file for my database. That is bassically what lowDB does and I am more comfturable doing it like this.
I chose to use the pure css framework. I feel like its style really fit my theme of just a place you can list things without being to fancy or anything. It just felt clean. I also like how they do tables
I used passport, morgan, session, body-parser, and express-uncapitalize.
passport is used for authenticating users and creating a login system.
morgan is used for logging any get and post request that are made to the server. Used for debugging
session stores your login information for the duration of the session.
body-parser is used for parsing through http requests
express-uncapitalize uncapitalizes any url you have by redirecting you to the url that is not capitalized

Baseline Requirements
---

Your application is required to implement the following functionalities:

- a `Server`, created using Express (no alternatives will be accepted for this assignment)
- a `Results` functionality which shows the entire dataset residing in the server's memory
- a `Form/Entry` functionality which allows users to add, modify, and delete data items (must be all three!) associated with their user name / account.
- Use of at least five [Express middleware packages](https://expressjs.com/en/resources/middleware.html). Explore!
- Basic authentication using the [Passport middleware](http://www.passportjs.org) for Express (this counts as one of your five middleware packages). We encourage using the Local strategy, but OAuth (Open Authentication) can also be used for additional technical achievement. The course staff cannot help you with the various flavors of OAuth strategies. YOU MUST PROVIDE US WITH ACCOUNT CREDENTIALS TO LOGIN TO YOUR APPLICATION IF YOU USE OAUTH. The course staff cannot be expected to have credentials for any particular OAuth service.
- Persistent data storage in between server sessions. [lowdb](https://github.com/typicode/lowdb) is a suitable database package for this assignment and will be discussed in class.
- Use of a [CSS framework or template](https://github.com/troxler/awesome-css-frameworks). This should do the bulk of your styling/CSS for you and be appropriate to your application. For example, don't use [NES.css](https://nostalgic-css.github.io/NES.css/) (which is awesome!) unless you're creating a game or some type of retro 80s site.

Your application is required to demonstrate the use of the following concepts:

HTML:
- HTML input tags and form fields of various flavors (`<textarea>`, `<input>`, checkboxes, radio buttons etc.)
- HTML that can display all data *for a particular authenticated user*. Note that this is different from the last assignnment, which required the display of all data in memory on the server.

Note that it might make sense to have two simple pages for this assignment, one that handles login / authentication, and one that contains the rest of your application. For this assignment, it is acceptable to simply create new user accounts upon login if none exist, however, you must alert your users to this fact. If you're not using OAuth

CSS:
- CSS styling should primarily be provided by your chosen template/framework. Oftentimes a great deal of care has been put into designing CSS templates; don't override their stylesheets unless you are extremely confident in your graphic design capabilities. The idea is to use CSS templates that give you a professional looking design aesthetic without requiring you to be a graphic designer yourself.

JavaScript:
- At minimum, a small amount of front-end JavaScript to get / fetch data from the server. See the [previous assignment](https://github.com/cs4241-19a/a2-shortstack) for reference.

Node.js:
- A server using Express, at least five pieces of Express middleware, and a persistent database (a flat file using lowdb is great).

Deliverables
---

Do the following to complete this assignment:

1. Implement your project with the above requirements. A good potential starting point is to use the "hello-express" project template inside of Glitch; this appears as an option when you hit the "New Project" button. Use the work you did in the last assignment as a reference to implement functionality, as well as the notes from class on 9/9 and 9/12.
2. If you developed your project locally, deploy your project to Glitch, and fill in the appropriate fields in your package.json file.
3. Test your project to make sure that when someone goes to your main page on Glitch, it displays correctly.
4. Ensure that your project has the proper naming scheme `a3-yourname` so we can find it.
5. Fork this repository and modify the README to the specifications below. You do not need to include any of your project files in this repo (we will see those on Glitch), you only need to update and commit the README file.
6. Create and submit a Pull Request to the original repo. Name the pull request using the following template: `a3-gitname-firstname-lastname`.

Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions)
---

## Your Web Application Title

your glitch link e.g. http://a3-charlieroberts.glitch.me

Include a very brief summary of your project here. Images are encouraged, along with concise, high-level text. Be sure to include:

- the goal of the application
- challenges you faced in realizing the application
- what authentication strategy / database you chose to use and why (choosing one because it seemed the easiest to implement is perfectly acceptable)
- what CSS framework you used and why.
- include any modifications to the CSS framework you made via custom CSS you authored.
- the five Express middleware packages you used and a short (one sentence) summary of what each one does.

## Technical Achievements
- **Tech Achievement 1**: I used OAuth authentication via the GitHub strategy
- **Tech Achievement 2**: I used over ten Express middleware packages, enabling me to create a server that...
NOTE FOR GRADER: Figuring out the login system took me a lot longer than I though it would. So I ended up having to copy and paste some code from project 2 to make it in time. I greatly apologize for this and am willing to accept any peneltys towrds my grade because of this. I will plan on doing better in the future.

### Design/Evaluation Achievements
- **Design Achievement 1**: I tested my application using screen reading software, and found that...
- **Design Achievement 2**: I followed best practices for accessibility, including providing alt attributes for images and using semantic HTML. There are no `<div>` or `<span>` elements in my document.
- **Design Achievement 3**: We tested the application with n=X users, finding that...
- **Design Achievement 2**: There are no `<div>` or `<span>` elements in my document.
Binary file added image.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "Food You Eat",
"version": "1.0.0",
"description": "Stores the information of all the different types of food you eat",
"author": "James Scherick",
"scripts": {
"start": "node server.improved.js"
},
"dependencies": {
"body-parser": "^1.19.0",
"connect-ensure-login": "^0.1.1",
"connect-timeout": "^1.9.0",
"cookie-parser": "^1.4.4",
"cookie-session": "^1.3.3",
"express": "^4.17.1",
"express-session": "^1.16.2",
"express-uncapitalize": "^1.0.0",
"mime": "^2.4.4",
"modern-normalize": "^0.5.0",
"mongodb": "^3.3.2",
"morgan": "^1.9.1",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
}
}
1 change: 1 addition & 0 deletions public/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
129 changes: 129 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47" crossorigin="anonymous">
<title>CS4241 Assignment 3</title>
<meta charset="utf-8">
</head>
<body>
<form action="">
<p>Food You Eat</p>
<table class="pure-table">
<tr>
<th> Food Name </th>
<th> Food Calories </th>
<th> Amount Eaten Average Week </th>
<th> Is Bad For You?</th>
</tr>
<tr>
<td><input type="text" id="food" placeholder="Enter Name Of Food"></td>
<td><input type="number" id="cal"></td>
<td><input type="number" id="ammount"></td>
<td><input type="checkbox" id="bad"></td>
</tr>
</table>

<button class="pure-button" id="submitButton">submit</button>
</form>
<a id="response"></a>

<center><button class="pure-button" onclick="deleteAll();">
delete all
</button></center>
</body>
<style>
#table{
background-color:lightgreen;
text-align: center;
margin: auto;
}
</style>
<script>
const editFood = function( i ) {
const food = document.querySelector( '#food' ),
cal = document.querySelector( '#cal' ),
ammount = document.querySelector( '#ammount' ),
bad = document.querySelector( '#bad' );
if (food.value === "" || cal.value === "" || ammount.value === ""){
alert("Some Information About this food is missing");
return false;
}
const json = { food: food.value, cal: cal.value, ammount: ammount.value, bad: bad.checked, index: i },
body = JSON.stringify( json )
fetch( '/edit', {
method:'POST',
body
})
.then( function( response ) { //do something with the reponse
getFoods();
})
return false
}

const deleteAll = function(){
const json = { },
body = JSON.stringify( json )

fetch( '/deleteall', {
method:'POST',
body
})
.then( function( response ) {
getFoods();
})
return false
}

const addFood = function( e ) {
e.preventDefault()
const food = document.querySelector( '#food' ),
cal = document.querySelector( '#cal' ),
ammount = document.querySelector( '#ammount' ),
bad = document.querySelector( '#bad' );
if (food.value === "" || cal.value === "" || ammount.value === ""){
alert("Some Information about this food is missing");
return false;
}
const json = { food: food.value, cal: cal.value, ammount: ammount.value, bad: bad.checked},
body = JSON.stringify( json )

fetch( '/submit', {
method:'POST',
body
})
.then( function( response ) { //do something with the reponse
getFoods();
})
return false
}

const del = function( i ){
const json = { delete: i },
body = JSON.stringify( json )
fetch( '/deletefood', {
method:'POST',
body
})
.then( function( response ) { //do something with the reponse
getFoods();
})
return false
}

const getFoods = function(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("response").innerHTML = this.responseText;
}
};
xhttp.open("GET", "getfoods", true);
xhttp.send();
}
window.onload = function() {
const button = document.querySelector( '#submitButton' )
button.onclick = addFood
getFoods();
}
</script>
</html>
19 changes: 19 additions & 0 deletions public/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<head>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-oAOxQR6DkCoMliIh8yFnu25d7Eq/PHS21PClpwjOTeU2jRSq11vu66rf90/cZr47" crossorigin="anonymous">
</head>
<html>
<form action="/login" method="post">
<div>
<label>Username:</label>
<input type="text" name="username"/>
</div>
<div>
<label>Password:</label>
<input type="password" name="password"/>
</div>
<div>
<input class="pure-button" type="submit" value="login"/>
</div>
</form>
</html>
<script></script>
1 change: 1 addition & 0 deletions public/loginDetails.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading