Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
bf7dbb6
changes to package-lock
sgoldfarb2 Nov 21, 2020
b95a9cf
Merge branch 'main' of https://github.com/hanger-app/hanger into main
sgoldfarb2 Nov 21, 2020
4bf8212
Merge branch 'main' of https://github.com/hanger-app/hanger into main
sgoldfarb2 Nov 21, 2020
340e5b9
init Store/ UserContext
mggower Nov 23, 2020
8ade10a
Merge branch 'main' of https://github.com/Hanger-Iteration/hanger int…
sgoldfarb2 Nov 23, 2020
3c58f1f
begin refactor
mggower Nov 23, 2020
a4cc819
pullupstream original
mggower Nov 23, 2020
dfe7844
UserContext, Restructure Components, New Dashboard
mggower Nov 23, 2020
d67deb8
Making adjustments to Router paths
mggower Nov 24, 2020
da5ffb4
initialized passportjs and created clientid and secretkey from google…
sgoldfarb2 Nov 24, 2020
5d26dd7
day restructure
mggower Nov 24, 2020
85b5fb9
inserting oauth user information into our sql db
sgoldfarb2 Nov 24, 2020
c2d619f
Delete settings.json
jgrubb16 Nov 24, 2020
5201feb
Merge pull request #1 from mggower/state
jgrubb16 Nov 24, 2020
becd9ed
Store/Store.js for App Abstraction
mggower Nov 24, 2020
b886870
pull from upstream 904PM after FIRST PR
mggower Nov 24, 2020
943a2e8
added user table query methods and donation status method
Nov 24, 2020
1271d6c
ItemCard ~ ItemView & ItemDescribe
mggower Nov 24, 2020
bef4842
added files to gitignore. working through passportjs
sgoldfarb2 Nov 24, 2020
f37c710
Merge branch 'main' of https://github.com/Hanger-Iteration/hanger int…
sgoldfarb2 Nov 24, 2020
2f72e25
reacthookform onChange validation
mggower Nov 24, 2020
46e30b0
we have cookie sessions enabled, we are able to see our user in req.u…
sgoldfarb2 Nov 24, 2020
82e0e6f
created controllers file, changed fileController to closetController,…
Nov 24, 2020
ab21961
update clothing item form/ prepare for db query
mggower Nov 24, 2020
a71acb5
finished google authentication except for handling certain routes whi…
sgoldfarb2 Nov 24, 2020
f3a5cbf
removed profileroutes page because it is not currently being utilized
sgoldfarb2 Nov 24, 2020
da7ba5b
begining NewItem Component, before PR
mggower Nov 24, 2020
e0cf1f9
added userLogin middleware
Nov 24, 2020
6cd4ab8
Merge pull request #2 from mggower/view
jgrubb16 Nov 24, 2020
2e839e9
Merge branch 'main' of https://github.com/Hanger-Iteration/hanger int…
sgoldfarb2 Nov 24, 2020
a813bdd
Merge branch 'oauth' into main
sgoldfarb2 Nov 24, 2020
c3ae4d3
Merge pull request #3 from sgoldfarb2/main
mggower Nov 24, 2020
a2b3034
merge changes
Nov 24, 2020
7b092e8
Merge pull request #4 from bdluro/main
jgrubb16 Nov 24, 2020
2db7bba
stash
mggower Nov 24, 2020
6f37c84
Group Pull-Requests up to data 354pm
mggower Nov 24, 2020
37dbeea
webpack changes
jgrubb16 Nov 24, 2020
0686642
new pull changes with webpack changes
jgrubb16 Nov 24, 2020
65c2662
MERGE CONFLICTS REESOLVED SIGH
mggower Nov 24, 2020
4687f78
New changes to google router in sending response in JSON
jgrubb16 Nov 25, 2020
d3cdcbd
Merge branch 'main' of https://github.com/Hanger-Iteration/hanger int…
mggower Nov 25, 2020
60389d0
Added Fb OAuth
jgrubb16 Nov 25, 2020
959e603
Added react cookie functionality to front/backend
jgrubb16 Nov 25, 2020
3774152
Merge pull request #6 from jgrubb16/main
mggower Nov 25, 2020
9e121d0
Merge branch 'main' of https://github.com/Hanger-Iteration/hanger int…
mggower Nov 25, 2020
1915003
updates to route endpoints, closetController middleware
Nov 25, 2020
f03cda6
linking fetchreq
mggower Nov 25, 2020
5617cd1
conditional rendering on login
mggower Nov 25, 2020
2f514e7
accessing user info check
mggower Nov 25, 2020
20e0058
Merge pull request #7 from mggower/fetch
jgrubb16 Nov 25, 2020
1fcbebd
updated api routes and middleware
Nov 25, 2020
d5d5934
merged server changes
Nov 25, 2020
ec621df
merge jordan
mggower Nov 25, 2020
efce502
added oauth page code
Nov 25, 2020
a209412
final countday
mggower Nov 25, 2020
50d8539
approved changes
Nov 25, 2020
1ea60c3
Merge pull request #8 from bdluro/main
sgoldfarb2 Nov 25, 2020
6ab2fd3
Merge branch 'jordan' into final
mggower Nov 26, 2020
7b4e65b
post demo note merging
mggower Nov 26, 2020
f2d8de5
Merge pull request #9 from mggower/final
jgrubb16 Jul 13, 2021
7d474ad
ChangesFromJuly14
jgrubb16 Jul 14, 2021
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
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,9 @@ ehthumbs.db
Thumbs.db

# bundle.js file
bundle.js
bundle.js

#vscode setting
.vscode
# keys.js file
keys.js
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"workbench.colorCustomizations": {
"statusBar.background": "#2980b9",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#409ad5",
"titleBar.activeBackground": "#2980b9",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#2980b999",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#2980B9"
}
24 changes: 24 additions & 0 deletions config/keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//add this file to gitignore

module.exports = {
google: {
// this clientID and clientSecret are given to us from google
clientID:
'979104596982-qkkdoare2fms3gaqne9v3pkbfs6bnppt.apps.googleusercontent.com',
clientSecret: '2h4K44PG0SUQzPq6eU1abQs7',
},
postgres: {
// here is our postgres URL
PG_URI:
'postgres://fojeewoc:yKLXZvm6DqRW840uEqmWDnT3OdGmYW_n@suleiman.db.elephantsql.com:5432/fojeewoc',
},
session: {
// this cookieKey is going to encrypt our cookie so that folks can't just see our cookie
cookieKey: 'dfkjghsjdhasdakjsdan',
},

facebook: {
clientID: '383299809591566',
AppSecret: 'cd417d5c4a4272542fe535826b91e7c1',
},
};
110 changes: 110 additions & 0 deletions config/passport-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20');
const keys = require('./keys');
const db = require('../models/closetModels');
const FacebookStrategy = require('passport-facebook').Strategy;

//serialize user's oauth_id for our cookie
passport.serializeUser((user, done) => {
done(null, user.rows[0]._id);
});

passport.deserializeUser(async (id, done) => {
// we need to pass in the user we're making the cookie for in done, so we will grab that user (again) via their oath_id in our query string
const userQuery = 'SELECT * FROM users WHERE oauth_id = $1';
const queryParam = [id];
//query db to find user based on their oath_id
const user = await db.query(userQuery, queryParam);
//pass user into done
done(null, user);
});

passport.use(
new GoogleStrategy(
{
//options for the strategy
//need to add a redirectURL, found in our google developer console
callbackURL: '/auth/google/redirect',
//need a client ID and a client secret
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret,
},
async (req, accessToken, refreshToken, profile, done) => {
//passport callback function
// check if user exists in our db first
try {
const findUserStr = `SELECT EXISTS (SELECT * FROM USERS WHERE oauth_id=$1)`;
//finduser params
const authID = profile.id;
const query2 = [authID];

//insert string params
const { givenName, familyName } = profile.name;
const emails = profile.emails[0].value;
const profileImage = profile.photos[0].value;
const insertUser = `INSERT INTO USERS (first_name1, last_name1, username, email, profile_Image, display_name_1, oauth_id) VALUES
($1, $2, $3, $4, $5, $6, $7)`;
const findUserQuery = [
givenName,
familyName,
emails,
emails,
profileImage,
givenName,
authID,
];
//check if user exists in db
const response = await db.query(findUserStr, query2);
//if user does not exists, quuery the db again to add the user
if (!response.rows[0].exists) await db.query(insertUser, findUserQuery);
//otherwise query the database to find the ID of the newly added user on line 37
const userQuery = 'SELECT * FROM USERS WHERE oauth_id = $1';
//assign a var the value of findind the newly added or already added user in table and assign it as second arg in done()
const user = await db.query(userQuery, query2);
done(null, user);
} catch (error) {
console.log('we got here somehow');
}
}
)
);
passport.use(
new FacebookStrategy(
{
clientID: keys.facebook.clientID,
clientSecret: keys.facebook.AppSecret,
callbackURL: 'http://localhost:3000/auth/facebook/callback',
},
async (accessToken, refreshToken, profile, done) => {
console.log(profile);
try {
const findUserStr = `SELECT EXISTS (SELECT * FROM USERS WHERE oauth_id=$1)`;
//finduser params
const authID = profile.id;
const query2 = [authID];

//insert string params
const displayName = profile.displayName;
let first_Name = displayName.split(' ')[0];
let last_Name = displayName.split(' ')[1];

// const profileImage = profile.photos[0].value;
const insertUser = `INSERT INTO USERS (first_name1, last_name1, username, email, profile_Image, display_name_1, oauth_id) VALUES
($1, $2, $3, 'N/A', 'N/A', $3, $4)`;

const findUserQuery = [first_Name, last_Name, displayName, authID];
//check if user exists in db
const response = await db.query(findUserStr, query2);
//if user does not exists, quuery the db again to add the user
if (!response.rows[0].exists) await db.query(insertUser, findUserQuery);
//otherwise query the database to find the ID of the newly added user on line 37
const userQuery = 'SELECT * FROM USERS WHERE oauth_id = $1';
//assign a var the value of findind the newly added or already added user in table and assign it as second arg in done()
const user = await db.query(userQuery, query2);
done(null, user);
} catch (error) {
console.log('we got here somehow');
}
}
)
);
167 changes: 167 additions & 0 deletions controllers/closetController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
const db = require('../models/closetModels');

const closetController = {};

// adds a new item to a user's closet
closetController.newClothingItem = async (req, res, next) => {
const {
itemName,
itemClothingType,
itemColor,
itemImage,
user_id,
season,
size,
availability,
} = req.body;

const queryStr =
'INSERT INTO Closet (itemName, itemClothingType, itemColor, itemImage, user_id, season, size, availability) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)';
const queryParams = [
itemName,
itemClothingType,
itemColor,
itemImage,
user_id,
season,
size,
availability,
];

try {
await db.query(queryStr, queryParams);
return next();
} catch (error) {
return next({
log: `Database error`,
status: 502,
message: { err: `${error.stack}` },
});
}
};

// retrieves all clothes from Clothes table
closetController.getClothes = async (req, res, next) => {
// would this be req.params??
const userId = req.params.id;
const queryStr =
'SELECT u._id, c.* FROM Users u LEFT OUTER JOIN Closet c ON c.user_id = $1';
// const queryStr = 'SELECT * FROM Closet ORDER BY _id ASC';
try {
const data = await db.query(queryStr, [userId]);
res.locals.clothes = data.rows;
return next();
} catch (error) {
return next(error);
}
};

// updates how many times an item has been worn and date of last wear
// id of item is passed through as key/value on request body
closetController.updateClosetItem = async (req, res, next) => {
const worn = req.body.worn;
const { id, itemname, itemclothingtype, itemcolor } = req.body;
console.log(id);
console.log(worn);
const firstQuery = 'SELECT times_worn FROM Closet WHERE _id = $1';

if (worn) {
try {
const data = await db.query(firstQuery, [id]);
let { times_worn } = data.rows[0];
console.log(times_worn);
times_worn += 1;
const todaysDate = new Date();

const queryStr =
'UPDATE Closet SET itemname = $1, itemclothingtype = $2, itemcolor = $3, last_worn = $4, times_worn = $5 WHERE _id= $6';
const queryParams = [
itemname,
itemclothingtype,
itemcolor,
todaysDate,
times_worn,
id,
];
await db.query(queryStr, queryParams);
return next();
} catch (error) {
return next({
log: `Database error`,
status: 502,
message: { err: `${error.stack}` },
});
}
}
};

// removes a piece of clothing from the Closet table
// request body includes key/value of clothing item id
closetController.deleteClothingItem = async (req, res, next) => {
const id = req.params.id;

// query string is to delete item from closet table where id matches passed in id
const queryStr = 'DELETE FROM Closet WHERE _id = $1';
const queryParams = [id];

try {
await db.query(queryStr, queryParams);
return next();
} catch (error) {
return next({
log: `Database error`,
status: 502,
message: { err: `${error.stack}` },
});
}
};

// update donation status in closet table
// select donation_status matching clothing item _id
closetController.donationStatusUpdate = async (req, res, next) => {
const id = req.body.id;
console.log(id);
const firstQuery = 'SELECT donation_status FROM Closet WHERE _id = $1';

try {
const data = await db.query(firstQuery, [id]);
let { donation_status } = data.rows[0];
console.log(donation_status);
// swap donation_status based on current value
donation_status = donation_status === 'Inactive' ? 'Active' : 'Inactive';

const queryStr = 'UPDATE Closet SET donation_status = $1 WHERE _id= $2';
const queryParams = [donation_status, id];

await db.query(queryStr, queryParams);
return next();
} catch (error) {
return next({
log: `Database error`,
status: 502,
message: { err: `${error.stack}` },
});
}
};

// query to find donation items for marketplace
// pulls everything matching donation status of 'Active'
closetController.getMarketplaceItems = async (req, res, next) => {
console.log('inside marketplace middleware!');
const queryStr = 'SELECT * FROM Closet WHERE donation_status = $1';
queryParams = ['Active'];

try {
const data = await db.query(queryStr, queryParams);
res.locals.clothes = data.rows;
return next();
} catch (error) {
return next({
log: `Database error`,
status: 502,
message: { err: `${error.stack}` },
});
}
};

module.exports = closetController;
Loading