Adding mock login and test data for RSVP get and submit. Must be removed along with reinstating DB connect calls if deploying real world production.

This commit is contained in:
Bradley 2021-06-04 11:11:00 -07:00
parent 5c4a2db2ce
commit 64e7d6f82d
7 changed files with 89 additions and 41 deletions

6
.env Normal file
View file

@ -0,0 +1,6 @@
MONGO_URL=
SECRET_COOKIE_PASSWORD=fjdk47fh48djsk3jdh8f9hdjshaj3eu4
ROOT_DOMAIN=localhost:3000
NEXT_PUBLIC_CLOUD_NAME=
NEXT_PUBLIC_FOLDER_NAME=
SITE_ENV=TEST_SITE

View file

@ -13,7 +13,9 @@ Features include:
- Travel information
- RSVP forms
## Names, Dates, Locations are all hardcoded to a value
## Detailed Info
Names, Dates, Locations are all hardcoded to a value
The site implements a basic auth with [next-iron-session](https://github.com/vvo/next-iron-session) to protect access without knowing the password to the site.
@ -25,6 +27,9 @@ Adding, Updating, and Deleting of guests and groups is currently done manually o
This admin branch is not included yet in this example site as no roles or permissions have been set up. However, this branch does include additional pages to add, edit, and delete these guests and groups.
*If deploying to production please remove all sections that have the following:*
```// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION```
## Tech
Overall a typical NextJS Application using ReactJS and basic authentication.

View file

@ -136,7 +136,6 @@ const Login = () => {
>
{errorMsg && <p className="error">Error: {errorMsg}</p>}
<fieldset aria-busy={loading} disabled={loading}>
<span>Temp password is "weddingsite". PLEASE CHANGE FOR YOUR PRODUCTION SITE!</span>
<label htmlFor="username">
<span>Username</span>
<input
@ -160,6 +159,8 @@ const Login = () => {
onChange={handleChange}
/>
</label>
<p>Temp password is "weddingsite".</p>
<p>PLEASE CHANGE FOR YOUR PRODUCTION SITE!</p>
<input
type="penguin"
name="penguin"

View file

@ -18,10 +18,11 @@ export default withSession(async (req, res) => {
return;
}
// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION
// In production just await connectDB()
if (process.env.SITE_ENV !== 'TEST_SITE') {
await connectDb();
// const { id: groupId } = await req.body;
// console.log(`groupId: ${groupId}`);
}
const response = {};
@ -57,6 +58,11 @@ export default withSession(async (req, res) => {
break;
case 'POST':
try {
// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION
if (process.env.SITE_ENV === 'TEST_SITE') {
console.log('DONE!')
res.status(200).json(JSON.stringify({ message: 'SUCCESS' }));
} else {
const { groupId, guests, note } = body;
for (const guest of guests) {
// console.log(`Updating ${guest.id} with status ${guest.rsvpStatus}`);
@ -78,6 +84,7 @@ export default withSession(async (req, res) => {
note,
});
res.status(200).json(JSON.stringify({ message: 'SUCCESS' }));
}
} catch (error) {
const { response: fetchResponse } = error;
console.error('error', error);

View file

@ -7,7 +7,11 @@ const { compare } = bcrypt;
export default withSession(async (req, res) => {
const { username, password, penguin } = await req.body;
// TODO: REMOVE THIS IF GOING TO PRODUCTION
// In production just await connectDB()
if (process.env.SITE_ENV !== 'TEST_SITE') {
await connectDb();
}
try {
if (username && password && penguin && penguin === 'penguin') {
@ -15,12 +19,11 @@ export default withSession(async (req, res) => {
// TODO: REMOVE THIS IF GOING TO PRODUCTION
if (process.env.SITE_ENV === 'TEST_SITE') {
const user = { isLoggedIn: isAuthorized, id: 'TEST_SITE_ID_123456' };
const user = { isLoggedIn: true, id: 'TEST_SITE_ID_123456' };
req.session.set('user', user);
await req.session.save();
res.json(user);
}
} else {
const userData = await User.findOne({ username });
const savedPassword = userData?.password || '';
isAuthorized = await compare(password, savedPassword);
@ -32,6 +35,7 @@ export default withSession(async (req, res) => {
} else {
res.status(400).json({ message: 'Unable to login' });
}
}
} else {
res.status(400).json({ message: 'Unable to login' });
}

View file

@ -16,7 +16,11 @@ export default withSession(async (req, res) => {
return;
}
// const { method } = req;
// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION
if (process.env.SITE_ENV === 'TEST_SITE') {
res.status(200).json({ status: 'SUCCESS', groupId: 'TESTID_12345' });
}
await connectDb();
const { firstName, lastName } = await req.body;

View file

@ -385,9 +385,30 @@ export default function SingleGroupPage({ group }) {
export async function getServerSideProps({ params }) {
try {
const group = {};
// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION
if (process.env.SITE_ENV === 'TEST_SITE') {
const group = {};
group.id = params.id;
group.guests = [{
id: 'TEST_GUEST_ID_12345',
firstName: 'Test',
lastName: 'Lastname',
rsvpStatus: false,
dietaryNotes: '',
songRequests: '',
hasPlusOne: true,
plusOne: false,
plusOneFirstName: '',
plusOneLastName: '',
}];
group.note = '';
return { props: { group } };
}
await connectDb();
const groupData = await Group.findById(params.id);
const group = {};
group.id = params.id;
const guestList = [];