diff --git a/README.md b/README.md index f12a7e7..101ce08 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,43 @@ # MowManApp -push notification app for lawn care companys +push notification app for lawn care companys. +uses google oauth to login and mongoDB to connect +check out the site here http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com/userHub +WARNING: website uses http and is not encrypted. Any private information entered could be exposed. + +HOW TO USE: +1. use git clone "https://github.com/PricetonB/MowManApp.git" to clone the code to your directory +2. create .env file with the following parameters + +GOOGLE_CLIENT_ID="" +GOOGLE_CLIENT_SECRET="" +can be obtained from google cloud console in "apis" under "credentials" after creating account and setting u keys + + + +SMTP_HOST="smtp.gmail.com" +SMTP_PORT="587" +these are default credentials for gmail + +SMTP_USER="" +SMTP_PASS="" +you need to create a gmail account for your app. +Enable two factor authentication and create "App Password" in settings. +user will be your app email address and pass will be your App Password (Gmail account password will not work) + + +EXPRESS_SESSION_SECRET="ght42d8c5970f662658f705fd5jv8tk30d589b7ed0ea9740e56dgkty78290f28" +EXPRESS_LISTENING_PORT=3000 +create a random string for express session secret and specify port you want to use + +MONGO_URL="mongodb+srv://username.randomletters" +create a database on mongoDB Atlas website and get url for the database. +You may also need to add your ip address to mongoDB Atlas whitelist. + + +3. in the "auth.js" file set the baseUrl if your not using local host:3000. + +4. in the "public" directory set the baseUrl at the top of every .js file if your not using localhost:3000 + +5. type npm install in MowManApp directory. + +6. type npm start in the MowManApp directory. \ No newline at end of file diff --git a/auth.js b/auth.js index bfa840e..e862f5a 100644 --- a/auth.js +++ b/auth.js @@ -6,6 +6,8 @@ const GoogleStrategy = require('passport-google-oauth2').Strategy; require('dotenv').config(); + + GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID; GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET; diff --git a/database.js b/database.js index 8761c19..9c15a4e 100644 --- a/database.js +++ b/database.js @@ -1,11 +1,15 @@ const express = require("express"); const mongoose = require("mongoose"); const app = express(); +require('dotenv').config(); + + +MONGO_URL = process.env.MONGO_URL; // Connect to MongoDB mongoose.connect( - "mongodb+srv://pricetonbraswell:8ZxWtId9Y5mQ10mY@mowmandb.ch05rsi.mongodb.net/Node-API?retryWrites=true&w=majority&appName=MowManDB", + MONGO_URL, { useNewUrlParser: true, useUnifiedTopology: true } ).then(() => { console.log("Connected to MongoDB MowManDB!"); diff --git a/notes.txt b/notes.txt index 0943661..c94088e 100644 --- a/notes.txt +++ b/notes.txt @@ -1,7 +1,6 @@ -AWS DNS CALLBACK: http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com:80/google/callback AWS DNS URL: http://ec2-3-144-135-34.us-east-2.compute.amazonaws.com:80 pm2 start app.js --watch diff --git a/routes/customers.js b/routes/customers.js index 06ea8fe..f7f9451 100644 --- a/routes/customers.js +++ b/routes/customers.js @@ -37,59 +37,4 @@ router.delete('/deleteCustomer/:customerId', isLoggedIn, customerController.dele module.exports = router; -/* -route.get /userHub/customers - returns html file that has list of customers -route.get /userHub/customers/:id - returns html file that has specific customer info and delete button -route.get /userHub/customers/:id/delete - deletes customer from database - - - - - -const express = require('express'); -const path = require('path'); -const mongoose = require('mongoose'); -const router = express.Router(); -const { User, Profile, Customer } = require('../database'); - - -// Middleware to check if the user is logged in -function isLoggedIn(req, res, next) { - if (req.user) { - return next(); - } else { - res.sendStatus(401); - } -} - -// GET route to serve the customers HTML file -router.get('/customersHTML', isLoggedIn, (req, res) => { - res.sendFile(path.join(__dirname, '../public', 'customers.html')); -}); - -// GET route to fetch customers data -router.get('/customersData', isLoggedIn, async (req, res) => { - - try { - const profileId = req.user.profile_id; // Assuming `req.user.profile_id` is available - const profile = await Profile.findById(profileId).populate('customers'); - - if (!profile) { - console.log('Profile not found when getting customer data'); - return res.status(404).json({ message: 'Profile not found' }); - } - - const customers = await Customer.find({ _id: { $in: profile.customers } }); - res.status(200).json({ customers }); - console.log("customers found and sent to client side heres customers:"); - console.log(customers); - - } catch (error) { - console.error('Error fetching customers:', error); - res.status(500).json({ message: 'Error fetching customers', error }); - } -}); - -module.exports = router; -*/ diff --git a/routes/userHub.js b/routes/userHub.js index 4245eee..951a519 100644 --- a/routes/userHub.js +++ b/routes/userHub.js @@ -17,8 +17,6 @@ router.get('/userHub', isLoggedIn, (req, res) => { res.sendFile(path.join(__dirname, '../public', 'userHub.html')); }); - - // POST route to add a new customer router.post('/user', isLoggedIn, (req, res) => { res.send('Post request successful'); diff --git a/services/appointmentService.js b/services/appointmentService.js index 7e03a3f..17c4cd9 100644 --- a/services/appointmentService.js +++ b/services/appointmentService.js @@ -1,5 +1,7 @@ const { Appointment, Profile } = require('../database'); + +// addAppointment function to add a new appointment to the database const addAppointment = async (appointmentData) => { try { // Create a new appointment instance using the provided data @@ -22,6 +24,7 @@ const addAppointment = async (appointmentData) => { } }; +// setAppointmentInactive function to set an appointment to inactive in the database const setAppointmentInactive = async (appointmentID) => { try { // Logic to set appointment to inactive in the database @@ -32,6 +35,7 @@ const setAppointmentInactive = async (appointmentID) => { } }; +// deleteAppointment function to delete an appointment from the database const deleteAppointment = async (appointmentID) => { try { // Logic to delete the appointment from the database @@ -48,6 +52,7 @@ const deleteAppointment = async (appointmentID) => { } }; +// getUsersAppointments function to fetch all appointments associated with a user's profile const getUsersAppointments = async (profileId) => { try { // Fetch appointments for the given profile ID diff --git a/services/customerService.js b/services/customerService.js index 17e3583..9c0988f 100644 --- a/services/customerService.js +++ b/services/customerService.js @@ -1,9 +1,6 @@ -// services/customerService.js const { Profile, Customer } = require('../database'); - - // Add a new customer to the database const addCustomer = async (customerData, user) => { const { name, email, phone } = customerData; @@ -25,9 +22,6 @@ const addCustomer = async (customerData, user) => { ); }; - - - // Get all customers associated with the user's profile const getCustomersData = async (user) => { const profileId = user.profile_id; // Assuming `user.profile_id` is available @@ -41,9 +35,6 @@ const getCustomersData = async (user) => { return customers; }; - - - // Delete a customer by ID const deleteCustomer = async (customerId) => { await Customer.findByIdAndDelete(customerId); diff --git a/services/emailService.js b/services/emailService.js index b15402f..e6a7403 100644 --- a/services/emailService.js +++ b/services/emailService.js @@ -1,6 +1,7 @@ const nodemailer = require('nodemailer'); const { Profile, Customer, Setting, Appointment } = require('../database'); + // Set up the Nodemailer transport const transporter = nodemailer.createTransport({ host: process.env.SMTP_HOST, @@ -12,6 +13,7 @@ const transporter = nodemailer.createTransport({ } }); +// Function to send email notifications to customers const sendEmailNotification = async (appointmentID) => { try { // Fetch the appointment document by appointmentID @@ -64,8 +66,6 @@ const sendEmailNotification = async (appointmentID) => { }; - - module.exports = { sendEmailNotification };