Skip to content
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
38 changes: 19 additions & 19 deletions controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@ const User = require('../db/models/User');

// GET /signup
router.get('/signup', (req, res) => {
res.render('signup.hbs', { message: req.flash('signupMessage') });
res.render('signup.hbs', { message: req.flash('signupMessage') });
});

// POST /signup
router.post('/signup', (req, res) => {
var signupStrategy = passport.authenticate('local-signup', {
successRedirect: '/users/' + req.body.email,
failureRedirect: '/users/signup',
failureFlash: true
});
var signupStrategy = passport.authenticate('local-signup', {
successRedirect: '/users/' + req.body.email,
failureRedirect: '/users/signup',
failureFlash: true
});

return signupStrategy(req, res);
return signupStrategy(req, res);
});

// GET /login
router.get('/login', (req, res) => {
res.render('login.hbs', { message: req.flash('loginMessage') });
res.render('login.hbs', { message: req.flash('loginMessage') });
});

// POST /login
router.post('/login', (req, res) => {
var loginProperty = passport.authenticate('local-login', {
successRedirect: '/users/' + req.body.email,
failureRedirect: '/users/login',
failureFlash: true
});
var loginProperty = passport.authenticate('local-login', {
successRedirect: '/users/' + req.body.email,
failureRedirect: '/users/login',
failureFlash: true
});

return loginProperty(req, res);
return loginProperty(req, res);
});
// GET /logout
router.get('/logout', (req, res) => {
req.logout();
res.redirect('/');
req.logout();
res.redirect('/');
});

//GET create page
router.get('/create/', (req, res) => {
res.render('create');
res.render('create');
});

// Restricted page create/update/delete functionality
router.get('/:email', (req, res) => {
User.findOne({ email: req.params.email }).then(res.render('userhome'));
User.findOne({ email: req.params.email }).then(res.render('userhome'));
});

router.get('/', (req, res) => {
res.render('userhome');
res.render('userhome');
});

module.exports = router;
84 changes: 42 additions & 42 deletions db/cheerup-seed.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
[
{
"body": "you are more beloved than you know."
},
{
"body": "the world is your oyster."
},
{
"body": "it's okay to not be the best at something."
},
{
"body": "your best is good enough."
},
{
"body": "you have the courage and strength to keep going."
},
{
"body": "be as kind to yourself as you are to others."
},
{
"body": "i'm proud of you and everything is going to be great."
},
{
"body": "you are smart. you are kind. you are important."
},
{
"body": "nothing good comes fast or easy."
},
{
"body": "there is nobody else in the world like you."
},
{
"body": "you are amazing. own that shit."
},
{
"body": "on the other side of the clouds is a bright blue sky."
},
{
"body": "forget all of the reasons that it won't work and believe the one reason why it will."
},
{
"body": "you are divine perfection."
}
{
"body": "you are more beloved than you know."
},
{
"body": "the world is your oyster."
},
{
"body": "it's okay to not be the best at something."
},
{
"body": "your best is good enough."
},
{
"body": "you have the courage and strength to keep going."
},
{
"body": "be as kind to yourself as you are to others."
},
{
"body": "i'm proud of you and everything is going to be great."
},
{
"body": "you are smart. you are kind. you are important."
},
{
"body": "nothing good comes fast or easy."
},
{
"body": "there is nobody else in the world like you."
},
{
"body": "you are amazing. own that shit."
},
{
"body": "on the other side of the clouds is a bright blue sky."
},
{
"body": "forget all of the reasons that it won't work and believe the one reason why it will."
},
{
"body": "you are divine perfection."
}
]
14 changes: 7 additions & 7 deletions db/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ mongoose.Promise = Promise;
// const mongoURI = "mongodb://localhost/book-e";
let mongoURI = '';
if (process.env.NODE_ENV === 'production') {
mongoURI = process.env.DB_URL;
mongoURI = process.env.DB_URL;
} else {
mongoURI = 'mongodb://localhost/cheerup';
mongoURI = 'mongodb://localhost/cheerup';
}

// connect to the database, with the imported mongoose instance
mongoose
.connect(mongoURI, { useNewUrlParser: true })
.then(instance =>
console.log(`Connected to db: ${instance.connections[0].name}`)
)
.catch(error => console.log('Connection failed!', error));
.connect(mongoURI, { useNewUrlParser: true })
.then(instance =>
console.log(`Connected to db: ${instance.connections[0].name}`)
)
.catch(error => console.log('Connection failed!', error));

// now, our mongoose instance has a configured connection to our local db, in addition
// to its model configuration
Expand Down
36 changes: 18 additions & 18 deletions db/models/Cheerup.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
const mongoose = require('../connection');

const CheerupSchema = new mongoose.Schema({
body: {
type: String,
required: true
},
likedBy: [
{
ref: 'User',
type: mongoose.Schema.Types.ObjectId,
required: false
}
],
createdBy: [
{
ref: 'User',
type: mongoose.Schema.Types.ObjectId,
required: false
}
]
body: {
type: String,
required: true
},
likedBy: [
{
ref: 'User',
type: mongoose.Schema.Types.ObjectId,
required: false
}
],
createdBy: [
{
ref: 'User',
type: mongoose.Schema.Types.ObjectId,
required: false
}
]
});

const Cheerup = mongoose.model('Cheerup', CheerupSchema);
Expand Down
40 changes: 20 additions & 20 deletions db/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ const mongoose = require('../connection.js');
const bcrypt = require('bcrypt-nodejs');

const UserSchema = mongoose.Schema({
local: {
email: String,
password: String
},
likes: [
{
ref: 'Cheerup',
type: mongoose.Schema.Types.ObjectId,
required: false
}
],
userCreated: [
{
ref: 'Cheerup',
type: mongoose.Schema.Types.ObjectId,
required: false
}
]
local: {
email: String,
password: String
},
likes: [
{
ref: 'Cheerup',
type: mongoose.Schema.Types.ObjectId,
required: false
}
],
userCreated: [
{
ref: 'Cheerup',
type: mongoose.Schema.Types.ObjectId,
required: false
}
]
});

UserSchema.methods.encrypt = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};

UserSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
return bcrypt.compareSync(password, this.local.password);
};

module.exports = mongoose.model('User', UserSchema);
18 changes: 9 additions & 9 deletions db/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const cheerupSeeds = require('./cheerup-seed.json');

//clear db of cheerup seeds
Cheerup.deleteMany({})
.then(() => {
console.log('deleted all cheerups');
return Cheerup.insertMany(cheerupSeeds);
})
.then(() => {
console.log('inserted cheerup seeds');
process.exit();
})
.catch(err => console.error(err));
.then(() => {
console.log('deleted all cheerups');
return Cheerup.insertMany(cheerupSeeds);
})
.then(() => {
console.log('inserted cheerup seeds');
process.exit();
})
.catch(err => console.error(err));
42 changes: 42 additions & 0 deletions esin-feedback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Feedback

See https://git.generalassemb.ly/seir-826/project-2/blob/master/evaluation.md for description of rubric.

## Technical Requirements - Excelling

Includes many well-structured models, and advanced functionality such as authorization, 3rd-party API integration, or other technology not covered in class

- Great job incorporating Passport into your app on top of the CRUD functionality!
- Awesome job creating js logic to limit the number of characters to 140 characters in your cheerup!

## Creativity and Interface - Excelling

The app is fully responsive, incorporates CSS technologies like Grid & Flexbox. App incorporates modern UI themes, and/or adds unique flair.

- Your app looks really professional and refined! I thought the overall design was really awesome (especially the fonts and color palette that you picked)!
- Your app looks amazing on mobile as well!

## Code Quality - Excelling

No major code quality issues, makes use of JS best practices appropriately, and follows techniques such as separation of concerns, abstraction, and encapsulation

- Make sure to remove any unused code from your HTML/JS/CSS files! There's some commented out code in your HTML file that can be removed.
- Make sure to use `let` instead of `var` in your js code.
- Consider breaking up your large CSS file into separate CSS files

## Functionality - Excelling

App has advanced functionality that works with minimal errors, and may make use of advanced tools such as APIs, plugins, etc.

- Passport!!! Wooot!

## Planning/Process/Submission - Performing

Submission contains clear evidence of planning, adequate documentation, include all from previous category, as well as additional information such as unsolved issues. Submission includes a readme and planning directory.

- Your readme is also informative! I thought the format made a lot of sense and was easy to understand.

## Additional Feedback

- Take a look at some of my inline comments on your code.
- Take a look at how I've used the prettier VSCode plugin to automatically clean up your code formatting!
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ app.use(passport.initialize());
app.use(passport.session());

app.use(function(req, res, next) {
console.log(req.user);
res.locals.currentUser = req.user;
next();
console.log(req.user);
res.locals.currentUser = req.user;
next();
});

//parser interprets key-value pairs in URLs
Expand All @@ -48,7 +48,7 @@ app.use('/assets', express.static('public'));

//redirect any requests to homepage
app.get('/', (req, res) => {
res.redirect('/cheerups/');
res.redirect('/cheerups/');
});
//hand off requests on '/users' route to users controller
app.use('/users/', usersController);
Expand All @@ -58,5 +58,5 @@ app.use('/cheerups/', cheerupsController);
app.set('port', process.env.PORT || 8080);

app.listen(app.get('port'), () => {
console.log(`✅ PORT: ${app.get('port')} 🌟`);
console.log(`✅ PORT: ${app.get('port')} 🌟`);
});
Loading