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

NancyCodes pull request 10-15 catch-up crew #175

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
.vscode
.env
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Introduction

A Simple ToDo App is built using the MVC Architecture, we have also implemented "authorization" so folx can sign up, customize & personalize the app

---

> Be sure to add that lovely star 😀 and fork it for your own copy

---

# Objectives

- It's a beginner level app created to understand how MVC concept and logins are added

---

# Who is this for?

- It's for beginners & intermediates with little more experience, to help understand the various aspects of building a node app with some complex features

---

# Packages/Dependencies used

bcrypt, connect-mongo, dotenv, ejs, express, express-flash, express-session, mongodb, mongoose, morgan, nodemon, passport, passport-local, validator

---

# Install all the dependencies or node packages used for development via Terminal

`npm install`

---

# Things to add

- Create a `.env` file and add the following as `key: value`
- PORT: 2121 (can be any port example: 3000)
- DB_STRING: `your database URI`
---

Have fun testing and improving it! 😎


4 changes: 3 additions & 1 deletion controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const User = require('../models/User')
}

exports.logout = (req, res) => {
req.logout()
req.logout(() => {
console.log('User has logged out.')
})
req.session.destroy((err) => {
if (err) console.log('Error : Failed to destroy the session during logout.', err)
req.user = null
Expand Down
3 changes: 1 addition & 2 deletions controllers/todos.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const Todo = require('../models/Todo')

module.exports = {
getTodos: async (req,res)=>{
console.log(req.user)
try{
const todoItems = await Todo.find({userId:req.user.id})
const itemsLeft = await Todo.countDocuments({userId:req.user.id,completed: false})
Expand Down
9 changes: 1 addition & 8 deletions middleware/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ module.exports = {
} else {
res.redirect('/')
}
},
ensureGuest: function (req, res, next) {
if (!req.isAuthenticated()) {
return next()
} else {
res.redirect('/dashboard')
}
},
}
}

2 changes: 1 addition & 1 deletion models/Todo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const mongoose = require('mongoose')
const mongoose = require('mongoose')

const TodoSchema = new mongoose.Schema({
todo: {
Expand Down
Loading