mirror of
https://github.com/BradNut/weddingsite
synced 2025-09-08 17:40:36 +00:00
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:
parent
5c4a2db2ce
commit
64e7d6f82d
7 changed files with 89 additions and 41 deletions
6
.env
Normal file
6
.env
Normal 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
|
||||||
|
|
@ -13,7 +13,9 @@ Features include:
|
||||||
- Travel information
|
- Travel information
|
||||||
- RSVP forms
|
- 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.
|
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.
|
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
|
## Tech
|
||||||
|
|
||||||
Overall a typical NextJS Application using ReactJS and basic authentication.
|
Overall a typical NextJS Application using ReactJS and basic authentication.
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ const Login = () => {
|
||||||
>
|
>
|
||||||
{errorMsg && <p className="error">Error: {errorMsg}</p>}
|
{errorMsg && <p className="error">Error: {errorMsg}</p>}
|
||||||
<fieldset aria-busy={loading} disabled={loading}>
|
<fieldset aria-busy={loading} disabled={loading}>
|
||||||
<span>Temp password is "weddingsite". PLEASE CHANGE FOR YOUR PRODUCTION SITE!</span>
|
|
||||||
<label htmlFor="username">
|
<label htmlFor="username">
|
||||||
<span>Username</span>
|
<span>Username</span>
|
||||||
<input
|
<input
|
||||||
|
|
@ -160,6 +159,8 @@ const Login = () => {
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
<p>Temp password is "weddingsite".</p>
|
||||||
|
<p>PLEASE CHANGE FOR YOUR PRODUCTION SITE!</p>
|
||||||
<input
|
<input
|
||||||
type="penguin"
|
type="penguin"
|
||||||
name="penguin"
|
name="penguin"
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,11 @@ export default withSession(async (req, res) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: REMOVE THIS WHEN TAKING YOUR SITE TO PRODUCTION
|
||||||
|
// In production just await connectDB()
|
||||||
|
if (process.env.SITE_ENV !== 'TEST_SITE') {
|
||||||
await connectDb();
|
await connectDb();
|
||||||
|
}
|
||||||
// const { id: groupId } = await req.body;
|
|
||||||
// console.log(`groupId: ${groupId}`);
|
|
||||||
|
|
||||||
const response = {};
|
const response = {};
|
||||||
|
|
||||||
|
|
@ -57,6 +58,11 @@ export default withSession(async (req, res) => {
|
||||||
break;
|
break;
|
||||||
case 'POST':
|
case 'POST':
|
||||||
try {
|
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;
|
const { groupId, guests, note } = body;
|
||||||
for (const guest of guests) {
|
for (const guest of guests) {
|
||||||
// console.log(`Updating ${guest.id} with status ${guest.rsvpStatus}`);
|
// console.log(`Updating ${guest.id} with status ${guest.rsvpStatus}`);
|
||||||
|
|
@ -78,6 +84,7 @@ export default withSession(async (req, res) => {
|
||||||
note,
|
note,
|
||||||
});
|
});
|
||||||
res.status(200).json(JSON.stringify({ message: 'SUCCESS' }));
|
res.status(200).json(JSON.stringify({ message: 'SUCCESS' }));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const { response: fetchResponse } = error;
|
const { response: fetchResponse } = error;
|
||||||
console.error('error', error);
|
console.error('error', error);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,11 @@ const { compare } = bcrypt;
|
||||||
|
|
||||||
export default withSession(async (req, res) => {
|
export default withSession(async (req, res) => {
|
||||||
const { username, password, penguin } = await req.body;
|
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();
|
await connectDb();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (username && password && penguin && penguin === 'penguin') {
|
if (username && password && penguin && penguin === 'penguin') {
|
||||||
|
|
@ -15,12 +19,11 @@ export default withSession(async (req, res) => {
|
||||||
|
|
||||||
// TODO: REMOVE THIS IF GOING TO PRODUCTION
|
// TODO: REMOVE THIS IF GOING TO PRODUCTION
|
||||||
if (process.env.SITE_ENV === 'TEST_SITE') {
|
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);
|
req.session.set('user', user);
|
||||||
await req.session.save();
|
await req.session.save();
|
||||||
res.json(user);
|
res.json(user);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
const userData = await User.findOne({ username });
|
const userData = await User.findOne({ username });
|
||||||
const savedPassword = userData?.password || '';
|
const savedPassword = userData?.password || '';
|
||||||
isAuthorized = await compare(password, savedPassword);
|
isAuthorized = await compare(password, savedPassword);
|
||||||
|
|
@ -32,6 +35,7 @@ export default withSession(async (req, res) => {
|
||||||
} else {
|
} else {
|
||||||
res.status(400).json({ message: 'Unable to login' });
|
res.status(400).json({ message: 'Unable to login' });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res.status(400).json({ message: 'Unable to login' });
|
res.status(400).json({ message: 'Unable to login' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@ export default withSession(async (req, res) => {
|
||||||
return;
|
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();
|
await connectDb();
|
||||||
const { firstName, lastName } = await req.body;
|
const { firstName, lastName } = await req.body;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -385,9 +385,30 @@ export default function SingleGroupPage({ group }) {
|
||||||
|
|
||||||
export async function getServerSideProps({ params }) {
|
export async function getServerSideProps({ params }) {
|
||||||
try {
|
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();
|
await connectDb();
|
||||||
const groupData = await Group.findById(params.id);
|
const groupData = await Group.findById(params.id);
|
||||||
const group = {};
|
|
||||||
|
|
||||||
group.id = params.id;
|
group.id = params.id;
|
||||||
const guestList = [];
|
const guestList = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue