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

Eivind branch #20

Open
wants to merge 83 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
93679e1
backend is ... in existence
paglenn Jul 3, 2023
4a64617
Merge pull request #1 from StabRabbit41/paul-backend-fix
JasonY000 Jul 4, 2023
5f836f6
initial frontend possible webpack issue
morahgeist Jul 4, 2023
69fe8f6
created userCreate and tests
paglenn Jul 5, 2023
0769e8b
delete user functionality and associated testing
paglenn Jul 5, 2023
8d256d3
Merge pull request #2 from StabRabbit41/paul-user-create
paglenn Jul 5, 2023
be45089
working website
EivindDelFierro Jul 5, 2023
c4b2b6d
working website
EivindDelFierro Jul 5, 2023
d1b0f71
merged tests
EivindDelFierro Jul 5, 2023
e599aa6
Co-authored-by: Morah Geist <morahgeist@users.noreply.github.com>
EivindDelFierro Jul 5, 2023
f395c8b
fixed package.json
EivindDelFierro Jul 5, 2023
4587ce8
user-auth-tests
paglenn Jul 5, 2023
6ed98e1
Merge branch 'dev' into paul-user-auth-tests
paglenn Jul 5, 2023
393faa5
completed authUser in userController
JasonY000 Jul 5, 2023
81add06
Merge pull request #4 from StabRabbit41/paul-user-auth-tests
dianemoon Jul 5, 2023
e625af4
Merge branch 'dev' into jasonBranch
JasonY000 Jul 5, 2023
74eeacd
authUser passed tests
JasonY000 Jul 5, 2023
b5942b7
Merge pull request #5 from StabRabbit41/jasonBranch
paglenn Jul 5, 2023
c143232
test for adding favorites
paglenn Jul 5, 2023
5804543
Added the addFavorite middleware in userController. Added the patch r…
dianemoon Jul 5, 2023
5673306
communicating with server, working menu, cards rendering
EivindDelFierro Jul 5, 2023
e37405b
Merge pull request #6 from StabRabbit41/paul-favorite-test
paglenn Jul 5, 2023
a8c3d6a
test passes for addFavorite
dianemoon Jul 5, 2023
753d84c
Merge pull request #7 from StabRabbit41/diane-branch
JasonY000 Jul 5, 2023
d41b335
creating middleware for server.js, stepping away for lunch
dianemoon Jul 5, 2023
b9e4afb
added cors and some statuses
paglenn Jul 5, 2023
3ba2d14
Merge pull request #8 from StabRabbit41/paul-cors-and-status
EivindDelFierro Jul 5, 2023
b3b07c4
updated header files
EivindDelFierro Jul 5, 2023
c4739a0
Merge branch 'dev' into Eivind-branch
EivindDelFierro Jul 5, 2023
7c17ff2
Merge pull request #9 from StabRabbit41/Eivind-branch
paglenn Jul 5, 2023
330a1d8
staged
EivindDelFierro Jul 5, 2023
3745565
Merge branch 'dev' into Eivind-branch
EivindDelFierro Jul 5, 2023
c2e3ca4
Merge pull request #10 from StabRabbit41/Eivind-branch
dianemoon Jul 5, 2023
2a7e276
im not sure abotu this commit
dianemoon Jul 5, 2023
3dd2d31
Merge branch 'dev' into Diane-branch
dianemoon Jul 5, 2023
047e229
update
JasonY000 Jul 5, 2023
1722c92
Created base login/signup and welcomescreen app
EivindDelFierro Jul 5, 2023
497b143
backend request for html
paglenn Jul 5, 2023
ee1db56
routed to correct file WelcomeScreen
paglenn Jul 5, 2023
1749187
both routes
paglenn Jul 5, 2023
828c4b6
fixed css parsing error
JasonY000 Jul 5, 2023
ecb939e
Merge pull request #11 from StabRabbit41/paul-backend-hookup
dianemoon Jul 5, 2023
3797f91
'merge webpack fix with dev'
JasonY000 Jul 5, 2023
8c0b747
Merge pull request #12 from StabRabbit41/jasonBranch
paglenn Jul 5, 2023
16b3503
menuContainerTest created
dianemoon Jul 5, 2023
283fdf0
Working login and signup
EivindDelFierro Jul 5, 2023
1894d97
menuContainerTest
dianemoon Jul 5, 2023
88d9707
Merge branch 'dev' into Eivind-Branch.
EivindDelFierro Jul 5, 2023
8b9caab
Merge pull request #13 from StabRabbit41/Eivind-Branch
dianemoon Jul 5, 2023
4d58730
yea
dianemoon Jul 5, 2023
9874a41
Merge branch 'dev' into Diane-branch
dianemoon Jul 5, 2023
f06b3cf
login component
EivindDelFierro Jul 5, 2023
a2788c4
mg initial styles
morahgeist Jul 6, 2023
ae2355b
Co-authored-by: EivindDelFierro <EivindDelFierro@users.noreply.github…
morahgeist Jul 6, 2023
05dc01d
mg redone styles with fav icon and favorites menu item
morahgeist Jul 6, 2023
7caea2f
beginning of last day of iteration project
dianemoon Jul 6, 2023
e899910
improved exercise menu logic
EivindDelFierro Jul 6, 2023
8e15a97
mg fav menu changed to btn
morahgeist Jul 6, 2023
8f55108
Merge pull request #14 from StabRabbit41/mg-styles
EivindDelFierro Jul 6, 2023
13b8e11
overlay working
morahgeist Jul 6, 2023
017fe10
Merge pull request #15 from StabRabbit41/mg-styles
EivindDelFierro Jul 6, 2023
d919ce9
Merge branch 'dev' into Eivind-Branch
EivindDelFierro Jul 6, 2023
fe95698
Merge pull request #16 from StabRabbit41/Eivind-Branch
EivindDelFierro Jul 6, 2023
8e2217b
logout functionality
paglenn Jul 6, 2023
271e72b
Merge pull request #17 from StabRabbit41/paul-logout
EivindDelFierro Jul 6, 2023
04e023a
Updated favorites buttons logic
EivindDelFierro Jul 6, 2023
23dc2a2
Merge branch 'dev' into Eivind-branch
EivindDelFierro Jul 6, 2023
bf7d869
Merge branch 'dev' into diane-branch
paglenn Jul 6, 2023
b8ea53a
Merge pull request #18 from StabRabbit41/diane-branch
paglenn Jul 6, 2023
4ec74c2
Merge branch 'dev' into Eivind-branch
EivindDelFierro Jul 6, 2023
188c33b
mg login screen and change font
morahgeist Jul 6, 2023
3eb1598
semi-working favorites render
EivindDelFierro Jul 6, 2023
6d797eb
Merge branch 'dev' into mg-styles
paglenn Jul 6, 2023
8d133bb
Merge pull request #19 from StabRabbit41/mg-styles
paglenn Jul 6, 2023
4aa6102
working timer
morahgeist Jul 6, 2023
36f10ff
add fade to welcome screen
EivindDelFierro Jul 6, 2023
70fa28d
Co-authored-by: Paul Glenn <paglenn@users.noreply.github.com>
EivindDelFierro Jul 6, 2023
8c7bdae
Merge pull request #20 from StabRabbit41/Eivind-branch
paglenn Jul 6, 2023
de8abf2
Merge branch 'dev' into mgTimer
EivindDelFierro Jul 6, 2023
caf10af
Merge pull request #21 from StabRabbit41/mgTimer
EivindDelFierro Jul 6, 2023
fe81918
fixed some styles and stretch logic
EivindDelFierro Jul 6, 2023
d6f076a
Merge branch 'dev' into Eivind-branch
EivindDelFierro Jul 6, 2023
79b5957
Clock has full functionality
EivindDelFierro Jul 6, 2023
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
Prev Previous commit
Next Next commit
authUser passed tests
JasonY000 committed Jul 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 74eeacda3b3479e9ca4de481f10c44952c217eda
25 changes: 15 additions & 10 deletions Server/controller/UserController.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ userController.registerUser = asyncHandler(async (req, res, next) => {

//if (User.find({ username })) throw new Error("User already exists");
const userCheck = await User.find({ username });
console.log('username : ', username, ' : ', userCheck);
//console.log('username : ', username, ' : ', userCheck);
if (userCheck.length > 0) throw new Error('User already exists');
// if we find the user we need to throw an error
res.locals.registeredUser = await User.create({
@@ -25,28 +25,33 @@ userController.authUser = async (req, res, next) => {
const { username, password } = req.body;
// get user from db
const userCheck = await User.find({ username });
//console.log('username : ', username, ' : ', userCheck);
console.log('username : ', username, ' : ', userCheck);
// check if user is in db
if (userCheck.length <= 0) {
return next({ message: { err: 'user not found' } });
}
//compare password
bcrypt.compare(password, userCheck.password, function (err, result) {
if (result === true) {
res.locals.user = userCheck[0];
return next();
} else {
return next({ message: { err: 'user not found or wrong password' } });
const match = bcrypt.compare(
password,
userCheck[0].password,
function (err, result) {
if (result === true) {
//console.log('this is the log ', userCheck[0]);
res.locals.user = userCheck[0];
return next();
} else {
return next({ message: { err: 'user not found or wrong password' } });
}
}
});
);
};

// Delete a user
// username and password must be passed in request body

userController.deleteUser = async (req, res, next) => {
const { username, password } = req.body;
console.log('entering deletion middleware ');
//console.log('entering deletion middleware ');

try {
// find the userand delete
29 changes: 15 additions & 14 deletions Server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// goal: set up express routing
// enviroment variable configuration
require("dotenv").config();
require('dotenv').config();
// steps
// create a controller.js
// this will contain routers
@@ -9,12 +9,12 @@ require("dotenv").config();
// define endpoints and actions
// add listener for PORT

const express = require("express");
const express = require('express');
const app = express();
const path = require("path");
const controller = require("./controller/ExerciseController.js");
const startServer = require("./database/dbConnection.js");
const userController = require("./controller/UserController.js");
const path = require('path');
const controller = require('./controller/ExerciseController.js');
const startServer = require('./database/dbConnection.js');
const userController = require('./controller/UserController.js');

const PORT = 3000;

@@ -33,25 +33,26 @@ startServer();

// to create user into database // takes in body // username, password

app.post("/user", userController.registerUser, (req, res) => {
app.post('/user', userController.registerUser, (req, res) => {
console.log();
return res.status(200).json(res.locals.registeredUser);
});

// delete user from database
app.delete("/user", userController.deleteUser, (req, res) =>
app.delete('/user', userController.deleteUser, (req, res) =>
res.status(200).json(res.locals.deletedUser)
);

// TODO:
// get user from database

// to authenticate user based on input username and password
app.get("/login", userController.authUser, (req, res) => {
return res.status(200).json(res.locals.users);
app.get('/login', userController.authUser, (req, res) => {
return res.status(200).json(res.locals.user);
});

// /API/exercises?muscle=${muscle}&type=stretching
app.get("/api", controller.getStretches, (req, res) => {
app.get('/api', controller.getStretches, (req, res) => {
return res.status(200).json(res.locals.apiRes);
});

@@ -63,16 +64,16 @@ app.get("/api", controller.getStretches, (req, res) => {
app.use(() =>
next({
status: 404,
log: "Route not found",
log: 'Route not found',
})
);

// global error handler
app.use((err, req, res, next) => {
const defaultErr = {
log: "Express error handler caught unknown middleware error",
log: 'Express error handler caught unknown middleware error',
status: 400,
message: { err: "An error occurred" },
message: { err: 'An error occurred' },
};
const errorObj = Object.assign({}, defaultErr, err);
console.log(errorObj.log);
54 changes: 27 additions & 27 deletions __tests__/userControllerTest.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
const server = "http://localhost:3000";
const request = require("supertest");
const fs = require("fs");
const server = 'http://localhost:3000';
const request = require('supertest');
const fs = require('fs');
//const { describe, expect, test } = require("@jest/globals");
// we've commented out the line above ^ because the global variables are already available once we install jest

// test user creation

// TODO: make sure tests that create a user also delete them so not to clutter?
// not super important but iwll make our DB easier to visually inspect
xdescribe("User Creation", () => {
describe('User Creation', () => {
// first let's check that it returns an object
xit("responds with 200 status and object", () => {
xit('responds with 200 status and object', () => {
const username = `Paul${Date.now()}`;

const password = "Paul";
const password = 'Paul';
return request(server)
.post("/user")
.post('/user')
.send({ username, password })
.expect(200)
.expect("Content-Type", /application\/json/);
.expect('Content-Type', /application\/json/);
});

xit("password is not the same as the original (should be hashed)", () => {
xit('password is not the same as the original (should be hashed)', () => {
const username = `Paul${Date.now()}`;

const password = "Paul";
const password = 'Paul';
return request(server)
.post("/user")
.post('/user')
.send({ username, password })
.then((response) => {
expect(response.body.password).not.toEqual(password);
});
});

it("attempt to create a duplicate user returns a 400 status code and error object", () => {
const username = "Paul";
const password = "Paul";
it('attempt to create a duplicate user returns a 400 status code and error object', () => {
const username = 'Paul';
const password = 'Paul';
return request(server)
.post("/user")
.post('/user')
.send({ username, password })
.then((response) => {
expect(response.status).toEqual(400); // expect a 400 status code
expect(response).toHaveProperty("error");
expect(response).toHaveProperty('error');
});
});
});

xdescribe("User Deletion", () => {
it("deletes user from database", () => {
describe('User Deletion', () => {
it('deletes user from database', () => {
const username = `Paul${Date.now()}`;
const password = "Paul";
const password = 'Paul';

return request(server)
.post("/user")
.post('/user')
.send({ username, password })
.then(() => {
request(server)
.delete("/user")
.delete('/user')
.send({ username, password })
.then((response) => {
expect(response.body.deletedCount).toEqual(1);
@@ -65,13 +65,13 @@ xdescribe("User Deletion", () => {
});
});

xdescribe("User Authentication", () => {
const username = "Paul";
const password = "Paul";
it("should return user if user password is correct", () => {
describe('User Authentication', () => {
const username = 'Paul';
const password = 'Paul';
it('should return user if user password is correct', () => {
// login route request
return request
.get("/login")
return request(server)
.get('/login')
.send({ username, password })
.then((response) => {
expect(response.body.username).toEqual(username);