Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 2 Complete #26

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 36 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
# Your Project Name
# Project 2: Fridge Magnets

This is the starter code for WDI projects. Please update this README file with information specific to your project. Replace this paragraph for instance, with a short description of your project. Then update the sections below. Refer to your project specificaion for instructions on how to submit your projects.
There has always been a problem in my family with different members of the family completed the same task without the knowledge of another family member. Through this project, I hope to develop a simple web application that family members will be informed once a task is completed.

## Getting Started

Provide instructions here about how to get your project running on our local machine. Do we just need to clone and open a certain file or do we need to install anything first.

### Prerequisites

What is needed to install and run the project, how do we install them

```
Code example
```

### How to Use

A step by step guide on how to install and use the project, for example if this is a game, how do we play it.


```
Code example
```

More steps...
## Live Version

```
until finished
```
Try it here:
https://fridgie-magnets.herokuapp.com/

## Function
* User first register for an account
* User can then create a new fridge which represents a group or a family
* In the fridge, members can add new task that needs to be completed to the fridge.
* User may either take up the task themselves, or wait until other members of the fridge takes up the task.
* Once the task is completed, another notification will be sent to all members of the fridge.
* Task will not be deleted until one of the members delete the task.

## Tests
## ERD

Did you write automated tests? If so, how do we run them.
<img src="/public/img/ERD.png" alt="ERD">

## Flow Chart

```
Code example
```
<img src="/public/img/flowchart.png" alt="ERD">

## Live Version
## Wire Frame

Where is this deployed online (github pages, heroku etc), give us the link and any access details we need.
<img src="/public/img/homepage1.png">
<img src="/public/img/registerpage.png">
<img src="/public/img/loginpage.png">
<img src="/public/img/profilepage.png">
<img src="/public/img/fridgepage.png">

## Built With

What did you use to build it, list the technologies, plugins, gems, packages etc.

* [jQuery](http://jquery.com/) - jQuery for example is something you likely used

## Workflow

Did you write user stories, draw wireframes, use task tracking, produce ERDs? Did you use source control, with regular commits? Include links to them here.

## Authors

Did you collaborate with others on this project, list them here
* HTML 5
* CSS 3
* JavaScript
* Node
* Express
* Mongoose
* TWilio API
* BootStrap 4

* **John McClain** - *Responsible for keeping vests white* - [GithubUserName](https://github.com/GithubUserName)
## Future Implementation

## Acknowledgments
* Calender events
* Current Date and Time on profile and fridge page
* Modify for small team task assignments or group work

* Hat tip to anyone who's code was used, for example [this was a useful starting point for creating this template](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2).
## Reference

* image: PxHere https://pxhere.com/
32 changes: 32 additions & 0 deletions config/ppConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const passport = require('passport')
const LocalStrategy = require('passport-local').Strategy
const User = require('../models/user')

passport.serializeUser(function(user,done){
console.log('serializeUser')
done(null, user.id)
})

passport.deserializeUser(function(id, done){
User.findById(id, function(err, user){
done(err, user)
})
})

passport.use(new LocalStrategy({
usernameField: 'user[email]',
passwordField: 'user[password]'
}, function(email, password, done){
User.findOne({email: email}, function(err, user){
if(err) return done(err)
if (!user) return done(null, false)
user.validPassword(password, (err, isMatch) => {
if (err) return done(null, false)
if (isMatch) return done(null, user)
return done(null, false, { message: 'mismatched'})
})

})
}))

module.exports = passport
21 changes: 21 additions & 0 deletions helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const isLoggedIn = (req, res, next) => {
if(req.user) {
res.redirect('/')
} else {
next()
}
}

// the opposite of the function above
const hasLoggedOut = (req, res, next) => {
if(req.user) {
next()
} else {
res.redirect('/')
}
}

module.exports = {
hasLoggedOut,
isLoggedIn
}
95 changes: 95 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const dotenv = require('dotenv').config({silent: true})
const express = require('express')
const app =express()
const mongoose = require('mongoose')
const exphbs = require('express-handlebars')
const bodyParser = require('body-parser')
const methodOverride = require('method-override')
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const passport = require('./config/ppConfig')
const path = require('path')

//helper files
const { hasLoggedOut, isLoggedIn } = require('./helpers')

const dbUrl = process.env.NODE_ENV === 'production' ? process.env.MONGODB_URI : 'mongodb://localhost/project2'
const port = process.env.NODE_ENV === 'production' ? process.env.PORT : 4000 // this is for our express server

//setup engines for handlebars
app.engine('handlebars', exphbs({ defaultLayout: 'main'}))
app.set('view engine', 'handlebars')

app.use(express.static(path.join(__dirname, 'public')))
app.use(function (req, res, next) {
console.log('Method: ' + req.method + ' Path: ' + req.url)
next()
})

// setup bodyParser
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({
extended: true
}))

// setup methodOverride
app.use(methodOverride('_method'))

// connecting to mongodb before we starting the server via mongoose
mongoose.Promise = global.Promise
mongoose.connect(dbUrl, {
useMongoClient: true
})
.then(
() => { console.log('db is connected') },
(err) => { console.log(err) }
)

//after connection
app.use(session({
secret: process.env.SESSION_SECRET,//hash session data
resave: false,
saveUninitialized: true,
store: new MongoStore({ mongooseConnection: mongoose.connection })
}));

//(below session configuration) activating
app.use(passport.initialize());
app.use(passport.session());//connecting to session

//set local data for all routes
app.use((req, res, next) => {
app.locals.user = req.user// we'll only `req.user` if we managed to log in
next()
})

//routes
const login_routes = require('./routes/login_routes')
const register_routes = require('./routes/register_routes')
const profile_routes = require('./routes/profile_routes')
const fridge_routes = require('./routes/fridge_routes')
const task_routes = require('./routes/task_routes')

//register routes

app.use('/login', isLoggedIn, login_routes)
app.use('/register', isLoggedIn, register_routes)
app.use('/profile', hasLoggedOut, profile_routes)
app.use('/fridge', fridge_routes)
app.use('/task', task_routes)

//home page
app.get('/',(req,res)=>{
res.render('home')
})

//logout routes
app.get('/logout', hasLoggedOut, (req, res) => {
req.logout()
res.redirect('/')
})

//opening the port for express
app.listen(port, ()=>{
console.log(`server is running on ${port}`);
})
19 changes: 19 additions & 0 deletions models/fridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema // constructor for all Schema

const fridgeSchema = new Schema({
name: String,
passcode:String,
members: [{
type: Schema.Types.ObjectId,
ref: 'User'
}],
task:[{
type: Schema.Types.ObjectId,
ref: 'Task'
}]
})

const Fridge = mongoose.model('Fridge', fridgeSchema)

module.exports = Fridge
21 changes: 21 additions & 0 deletions models/task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require('mongoose')
const Schema = mongoose.Schema

const taskSchema = new Schema({
fridge:{
type: Schema.Types.ObjectId,
ref: 'Fridge'
},
details: String,
assign: {
type: Schema.Types.ObjectId,
ref: 'User'
},
complete:{
type: Boolean
}
})

const Task = mongoose.model('Task', taskSchema)

module.exports = Task
49 changes: 49 additions & 0 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//require mongoose
const mongoose = require('mongoose')
const Schema = mongoose.Schema // constructor for all Schema
// const emailRegex = require('email-regex');

//require bcyrpt
const bcrypt = require('bcrypt')

const userSchema = new Schema({
name: String,
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true ,
minlength: [1, 'Password must be between 8 and 99 characters'],
maxlength: [99, 'Password must be between 8 and 99 characters'],
},
phoneNumber:{
type: Number
},
fridges: [{
type: Schema.Types.ObjectId,
ref: 'Fridge'
}]
})

userSchema.pre('save', function(next){
var user = this
if (!user.isModified('password')) return next();
bcrypt.hash(user.password, 10)
.then(hash => {
// call the next() when the password is hashed
user.password = hash
console.log('pre save flow', user)
next()
})
})

userSchema.methods.validPassword = function (plainPassword, callback) {
bcrypt.compare(plainPassword, this.password, callback)
}

const User = mongoose.model('User', userSchema)

module.exports = User
21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,24 @@
"main": "index.js",
"repository": "https://github.com/wdi-sg/project-2.git",
"author": "Prima Aulia Gusta <primaulia@gmail.com>",
"license": "MIT"
"license": "MIT",
"scripts": {
"start": "nodemon"
},
"dependencies": {
"bcrypt": "^1.0.3",
"body-parser": "^1.18.2",
"connect-mongo": "^2.0.0",
"dotenv": "^4.0.0",
"email-regex": "^1.0.0",
"express": "^4.16.2",
"express-handlebars": "^3.0.0",
"express-session": "^1.15.6",
"method-override": "^2.3.10",
"mongoose": "^4.12.4",
"nodemon": "^1.12.1",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"twilio": "^3.9.0"
}
}
Loading