Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
899305d
Removed unused import of 'mongoose' and 'colors
hollyxj Apr 5, 2023
f2854a1
Merge pull request #1 from Brian-Pob/holly
Brian-Pob Apr 5, 2023
0026ba2
Removed unused Import
tylerwelsh Apr 5, 2023
36ddd30
Merge pull request #2 from Brian-Pob/tyler
hollyxj Apr 5, 2023
98a0adb
Removed unnecessary return statement
tylerwelsh Apr 5, 2023
c4dcfdb
Product carousel - Extract this nested ternary operation into an inde…
hollyxj Apr 5, 2023
9690b4d
Merge pull request #3 from Brian-Pob/tyler
hollyxj Apr 5, 2023
968d2b3
Merge pull request #4 from Brian-Pob/holly
tylerwelsh Apr 5, 2023
be27420
OrderScreen.js - Extract this nested ternary operation into an indepe…
hollyxj Apr 5, 2023
c3b251f
OrderListScreen.js - Extract this nested ternary operation into an in…
hollyxj Apr 5, 2023
534f14b
Merge pull request #5 from Brian-Pob/holly
hollyxj Apr 5, 2023
5ac9594
HomeScreen.js - Extract this nested ternary operation into an indepen…
hollyxj Apr 5, 2023
e6d7f63
Merge pull request #6 from Brian-Pob/holly
hollyxj Apr 5, 2023
b6cee39
working on ordrescreen.js smells
Brian-Pob Apr 5, 2023
27ecdf8
working on ordrescreen.js smells again
Brian-Pob Apr 5, 2023
e48da0f
Merge branch 'master' into brian
Brian-Pob Apr 5, 2023
8edf6a0
Merge pull request #7 from Brian-Pob/brian
hollyxj Apr 5, 2023
de59b76
Rating.js - Extract this nested ternary operations into a separate St…
hollyxj Apr 5, 2023
0874ec8
Merge pull request #8 from Brian-Pob/holly
hollyxj Apr 5, 2023
5acedc3
Update OrderScreen.js
tylerwelsh Apr 7, 2023
e360490
Update PlaceOrderScreen.js
tylerwelsh Apr 7, 2023
1a2b236
Update Rating.js
tylerwelsh Apr 7, 2023
afae162
Update serviceWorker.js
tylerwelsh Apr 7, 2023
1bf03a2
Merge pull request #9 from Brian-Pob/tyler
Brian-Pob Apr 7, 2023
ae0ef32
Fixed ternary operation in ProductScreen.js
Apr 8, 2023
b763f48
Revert "Fixed ternary operation in ProductScreen.js"
Apr 8, 2023
bc48384
Update ternary condition to indepdent conditions
stevethekey Apr 8, 2023
11ce175
Refactored comments to improve the cognitive complexity
stevethekey Apr 8, 2023
47ddc5c
started implementing social login with auth0
Brian-Pob Apr 17, 2023
d438139
fix logging out on refresh
Brian-Pob Apr 19, 2023
792bace
auth0 updates
Brian-Pob Apr 19, 2023
c2569d5
refactored auth0 login with callback route
Brian-Pob Apr 20, 2023
cc25132
updates to login and register
Brian-Pob Apr 20, 2023
042c9e2
profile kinda works now
Brian-Pob Apr 20, 2023
5652031
fixed orders. cleaned up code
Brian-Pob Apr 24, 2023
717a215
Completed phase 2
tylerwelsh Apr 25, 2023
1b55d7d
Got project to run successfully
hollyxj Apr 26, 2023
93216b6
Fixed Rating.js to show 5 stars instead of 10
hollyxj Apr 26, 2023
253173a
Feature 5 progress: Added ContactScreen.js, contactRoutes.js, contact…
hollyxj Apr 26, 2023
0104c8a
Merge pull request #11 from Brian-Pob/Steven
stevethekey Apr 27, 2023
86813c8
Feature 5 progress - it is saying email sent successfully. Now I just…
hollyxj Apr 27, 2023
e3600e9
Feature 5 progress - trying to get email to send through mailgun-js o…
hollyxj Apr 27, 2023
ba23514
Remove mailgun api key from comments
hollyxj Apr 27, 2023
a389b42
Project is able to run again.
hollyxj Apr 27, 2023
a89b761
Feature 5 progress - getting the correct subject and message in the c…
hollyxj Apr 27, 2023
59eb1ab
replaced login references and functionality
Brian-Pob Apr 27, 2023
92f3dd5
Feature 5 working! Email is sending! Just have to clean up code and f…
hollyxj Apr 27, 2023
d05b234
removed login from backend
Brian-Pob Apr 27, 2023
620d710
Revert "removed login from backend"
Brian-Pob Apr 27, 2023
c441537
Feature 5 - Postfactoring: Removed debugging console logs across all …
hollyxj Apr 28, 2023
a5f0f39
Update README.md
hollyxj Apr 28, 2023
510fb2d
Merge branch 'master' of https://github.com/Brian-Pob/swe2_proshop_me…
hollyxj Apr 28, 2023
6c992e8
prepare to merge holly into master
hollyxj Apr 28, 2023
5168ffb
final updates to hollys changes
Brian-Pob Apr 28, 2023
6c4b6a2
Merge pull request #12 from Brian-Pob/holly
Brian-Pob Apr 28, 2023
43efc9c
Merge branch 'master' of https://github.com/Brian-Pob/swe2_proshop_me…
Brian-Pob Apr 28, 2023
4450f1c
package-locks updated
Brian-Pob Apr 28, 2023
630d837
Merge pull request #10 from Brian-Pob/brian
hollyxj Apr 28, 2023
738301f
updating my branch from master
hollyxj Apr 28, 2023
9d8c8e2
Feature 5 - Postfactoring: Added more comments to improve code readab…
hollyxj Apr 28, 2023
4c7bb81
Merge pull request #13 from Brian-Pob/holly
hollyxj Apr 28, 2023
d62f4f8
Added functionality to move item fro "later" to "cart"
tylerwelsh Apr 28, 2023
38e6b52
Merge branch 'master' of https://github.com/Brian-Pob/swe2_proshop_me…
tylerwelsh Apr 28, 2023
c0422e4
fixing merge from master to tyler
tylerwelsh Apr 28, 2023
cd4cf43
Fixed a bug where the save for later item was not being removed propeely
tylerwelsh Apr 28, 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
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.19.1
Empty file added .scannerwork/.sonar_lock
Empty file.
6 changes: 6 additions & 0 deletions .scannerwork/report-task.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
projectKey=swe2-mern
serverUrl=http://localhost:9000
serverVersion=9.9.0.65466
dashboardUrl=http://localhost:9000/dashboard?id=swe2-mern
ceTaskId=AYdS6heQ9gZZmSRSi5Kr
ceTaskUrl=http://localhost:9000/api/ce/task?id=AYdS6heQ9gZZmSRSi5Kr
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Create a .env file in then root and add the following
```
NODE_ENV = development
PORT = 5000
EMAIL_ADDRESS = your email address
EMAIL_PASSWORD = your email password (gmail app password)
MONGO_URI = your mongodb uri
JWT_SECRET = 'abc123'
PAYPAL_CLIENT_ID = your paypal client id
Expand Down
50 changes: 50 additions & 0 deletions backend/controllers/contactController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import nodemailer from 'nodemailer'

// @desc Send email
// @route POST /api/send-email
// @access Public
const sendMail = async (req, res) => {
// Get the subject and message the user entered from the request body
const subject = req.body['subject']['subject'];
const message = req.body['subject']['message'];

// Make sure all fields are filled in
if (!subject || !message) {
// If all fields are not filled in, show an error message
return res.status(400).json({ message: 'All fields are required' });
}

// Create reusable transporter object using the default SMTP transport
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
// Email address defined in .env file
user: process.env.EMAIL_ADDRESS,
// Email app password defined in .env file
pass: process.env.EMAIL_PASSWORD,
}
});

// Set the email options
var mailOptions = {
from: process.env.EMAIL_ADDRESS,
to: process.env.EMAIL_ADDRESS,
// Set the subject to the subject the user entered on the form
subject: subject,
// Set the message to the message the user entered on the form
text: message
};

// Send the email
transporter.sendMail(mailOptions, function(error, info){
if (error) {
// Log error if failed
console.log(error);
} else {
// Log the email was sent
console.log('Email sent: ' + info.response);
}
});
}

export { sendMail };
1 change: 0 additions & 1 deletion backend/controllers/orderController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const addOrderItems = asyncHandler(async (req, res) => {
if (orderItems && orderItems.length === 0) {
res.status(400)
throw new Error('No order items')
return
} else {
const order = new Order({
orderItems,
Expand Down
122 changes: 62 additions & 60 deletions backend/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncHandler from 'express-async-handler'
import generateToken from '../utils/generateToken.js'
import User from '../models/userModel.js'
import asyncHandler from 'express-async-handler';
import User from '../models/userModel.js';
import generateToken from '../utils/generateToken.js';

// @desc Auth user & get token
// @route POST /api/users/login
// @access Public
const authUser = asyncHandler(async (req, res) => {
const { email, password } = req.body
const { email, password } = req.body;

const user = await User.findOne({ email })
const user = await User.findOne({ email });

if (user && (await user.matchPassword(password))) {
res.json({
Expand All @@ -17,162 +17,164 @@ const authUser = asyncHandler(async (req, res) => {
email: user.email,
isAdmin: user.isAdmin,
token: generateToken(user._id),
})
});
} else {
res.status(401)
throw new Error('Invalid email or password')
res.status(401);
throw new Error('Invalid email or password');
}
})
});

// @desc Register a new user
// @route POST /api/users
// @access Public
const registerUser = asyncHandler(async (req, res) => {
const { name, email, password } = req.body
const { name, email, password, isAdmin } = req.body;

const userExists = await User.findOne({ email })
const userExists = await User.findOne({ email });

if (userExists) {
res.status(400)
throw new Error('User already exists')
res.status(400);
throw new Error('User already exists');
}

const user = await User.create({
name,
email,
password,
})
isAdmin,
});

if (user) {
console.log('user', user);
res.status(201).json({
_id: user._id,
name: user.name,
email: user.email,
isAdmin: user.isAdmin,
token: generateToken(user._id),
})
});
} else {
res.status(400)
throw new Error('Invalid user data')
res.status(400);
throw new Error('Invalid user data');
}
})
});

// @desc Get user profile
// @route GET /api/users/profile
// @access Private
const getUserProfile = asyncHandler(async (req, res) => {
const user = await User.findById(req.user._id)
const user = await User.findById(req.user._id);

if (user) {
res.json({
_id: user._id,
name: user.name,
email: user.email,
isAdmin: user.isAdmin,
})
});
} else {
res.status(404)
throw new Error('User not found')
res.status(404);
throw new Error('User not found');
}
})
});

// @desc Update user profile
// @route PUT /api/users/profile
// @access Private
const updateUserProfile = asyncHandler(async (req, res) => {
const user = await User.findById(req.user._id)
const user = await User.findById(req.user._id);

if (user) {
user.name = req.body.name || user.name
user.email = req.body.email || user.email
user.name = req.body.name || user.name;
user.email = req.body.email || user.email;
if (req.body.password) {
user.password = req.body.password
user.password = req.body.password;
}

const updatedUser = await user.save()
const updatedUser = await user.save();

res.json({
_id: updatedUser._id,
name: updatedUser.name,
email: updatedUser.email,
isAdmin: updatedUser.isAdmin,
token: generateToken(updatedUser._id),
})
});
} else {
res.status(404)
throw new Error('User not found')
res.status(404);
throw new Error('User not found');
}
})
});

// @desc Get all users
// @route GET /api/users
// @access Private/Admin
const getUsers = asyncHandler(async (req, res) => {
const users = await User.find({})
res.json(users)
})
const users = await User.find({});
res.json(users);
});

// @desc Delete user
// @route DELETE /api/users/:id
// @access Private/Admin
const deleteUser = asyncHandler(async (req, res) => {
const user = await User.findById(req.params.id)
const user = await User.findById(req.params.id);

if (user) {
await user.remove()
res.json({ message: 'User removed' })
await user.remove();
res.json({ message: 'User removed' });
} else {
res.status(404)
throw new Error('User not found')
res.status(404);
throw new Error('User not found');
}
})
});

// @desc Get user by ID
// @route GET /api/users/:id
// @access Private/Admin
const getUserById = asyncHandler(async (req, res) => {
const user = await User.findById(req.params.id).select('-password')
const user = await User.findById(req.params.id).select('-password');

if (user) {
res.json(user)
res.json(user);
} else {
res.status(404)
throw new Error('User not found')
res.status(404);
throw new Error('User not found');
}
})
});

// @desc Update user
// @route PUT /api/users/:id
// @access Private/Admin
const updateUser = asyncHandler(async (req, res) => {
const user = await User.findById(req.params.id)
const user = await User.findById(req.params.id);

if (user) {
user.name = req.body.name || user.name
user.email = req.body.email || user.email
user.isAdmin = req.body.isAdmin
user.name = req.body.name || user.name;
user.email = req.body.email || user.email;
user.isAdmin = req.body.isAdmin;

const updatedUser = await user.save()
const updatedUser = await user.save();

res.json({
_id: updatedUser._id,
name: updatedUser.name,
email: updatedUser.email,
isAdmin: updatedUser.isAdmin,
})
});
} else {
res.status(404)
throw new Error('User not found')
res.status(404);
throw new Error('User not found');
}
})
});

export {
authUser,
registerUser,
getUserProfile,
updateUserProfile,
getUsers,
deleteUser,
getUserById,
getUserProfile,
getUsers,
registerUser,
updateUser,
}
updateUserProfile,
};
41 changes: 22 additions & 19 deletions backend/middleware/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
import jwt from 'jsonwebtoken'
import asyncHandler from 'express-async-handler'
import User from '../models/userModel.js'
import asyncHandler from 'express-async-handler';
import jwt from 'jsonwebtoken';
import User from '../models/userModel.js';

const protect = asyncHandler(async (req, res, next) => {
let token
let token;

if (
req.headers.authorization &&
req.headers.authorization.startsWith('Bearer')
) {
try {
token = req.headers.authorization.split(' ')[1]
token = req.headers.authorization.split(' ')[1];

const decoded = jwt.verify(token, process.env.JWT_SECRET)
const decoded = jwt.verify(token, process.env.JWT_SECRET);

req.user = await User.findById(decoded.id).select('-password')
req.user = await User.findById(decoded.id).select('-password');

next()
next();
} catch (error) {
console.error(error)
res.status(401)
throw new Error('Not authorized, token failed')
console.error(error);
res.status(401);
throw new Error('Not authorized, token failed');
}
}

if (!token) {
res.status(401)
throw new Error('Not authorized, no token')
res.status(401);
console.error('Not authorized, no token');
throw new Error('Not authorized, no token');
}
})
});

const admin = (req, res, next) => {
if (req.user && req.user.isAdmin) {
next()
next();
} else {
res.status(401)
throw new Error('Not authorized as an admin')
res.status(401);
console.error('user', req.user);
console.error('Not authorized as an admin');
throw new Error('Not authorized as an admin');
}
}
};

export { protect, admin }
export { admin, protect };
8 changes: 8 additions & 0 deletions backend/routes/contactRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import express from 'express';
const router = express.Router();
import { sendMail } from '../controllers/contactController.js';

// Add a route for the new endpoint using the Express router.
router.route('/').post(sendMail);

export default router;
Loading