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

Update front end with new backend features #9

Open
wants to merge 28 commits into
base: front-end
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8f27e9c
added user verification for editing blogs
maynperalta Oct 3, 2020
c4f0e74
Merge pull request #7 from vmcgargill/front-end
vmcgargill Oct 3, 2020
d0f99a4
Merge branch 'master' into edit-blogs
vmcgargill Oct 3, 2020
a2aca10
Merge pull request #5 from vmcgargill/edit-blogs
vmcgargill Oct 3, 2020
b5a4b24
Fixed delete category feature. Made some front end adjustments.
vmcgargill Oct 3, 2020
64033a7
Fixed blog search feature
vmcgargill Oct 3, 2020
3b8345e
Made some more front end changes to sharpen up the display.
vmcgargill Oct 3, 2020
1849d01
Fixed isBlogOwner middleware to be in different directory
vmcgargill Oct 3, 2020
31b5c6c
HUGE MILESTONE!! Completely revamped the error messages in the entire…
vmcgargill Oct 4, 2020
59aa479
Adding media queries to make site even more mobile responsive
vmcgargill Oct 4, 2020
dd2c1c2
Uncommenting the eslintrc.json file
vmcgargill Oct 4, 2020
af8f5db
Added navbar blog search by title feature in the navbar so users can …
vmcgargill Oct 4, 2020
a3c400c
Improved search engine. Made it so that you can also search for blogs…
vmcgargill Oct 4, 2020
d3bbfd2
Updated the update profile form with classes
vmcgargill Oct 4, 2020
2ef681b
Delete account feature has been added, tested, and is now fully funct…
vmcgargill Oct 5, 2020
513ec3a
Updating dependencies for package.lock.json
vmcgargill Oct 5, 2020
890c53d
Fixed the view member page and view blog page to match the filter blo…
vmcgargill Oct 6, 2020
70e11c0
Changinf the body from p elelment to pre element to show parargrapsh.…
vmcgargill Oct 6, 2020
1e93848
Final draft of project. Getting rid of all eslint errors. Fixed all i…
vmcgargill Oct 7, 2020
efa6796
Commenting out linebreak style so TravisCI build succeeds
vmcgargill Oct 7, 2020
af8cd86
Moving edit and delete profile buttons ABOVE the viewmember partial s…
vmcgargill Oct 7, 2020
778bca8
Added the memberprofile.handlebars file so that the edit profile butt…
vmcgargill Oct 7, 2020
ccc4dbd
Changed name of viewmember.js to memberprofile.js so names match
vmcgargill Oct 7, 2020
f52a6e4
Finished writing the readme.md. First draft is complete, it still nee…
vmcgargill Oct 8, 2020
a4a1da9
Making one small modification so that when user posts new blog, they …
vmcgargill Oct 8, 2020
9410298
Adding routes link to the table of contents in the readme.md
vmcgargill Oct 8, 2020
b6f224e
Fixed small typos on readme.md file.
vmcgargill Oct 9, 2020
0531411
Adding comment on navbaer error message explaining why we don't use t…
vmcgargill Oct 9, 2020
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
models/index.js
node_modules
node_modules
91 changes: 45 additions & 46 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,45 @@
// {
// "env": {
// "browser": true,
// "commonjs": true,
// "node": true,
// "es6": true
// },
// "rules": {
// "no-duplicate-case":"error",
// "no-empty":"error",
// "no-extra-semi":"error",
// "no-func-assign": "error",
// "no-irregular-whitespace":"error",
// "no-unreachable": "error",
// "curly": "error",
// "dot-notation": "error",
// "eqeqeq": "error",
// "no-empty-function": "error",
// "no-multi-spaces": "error",
// "no-mixed-spaces-and-tabs": "error",
// "no-trailing-spaces": "error",
// "default-case": "error",
// "no-fallthrough": "error",
// "no-unused-vars": "error",
// "no-use-before-define": "error",
// "no-redeclare": "error",
// "camelcase": "error",
// "brace-style": "error",
// "indent": [
// "error",
// 2
// ],
// "linebreak-style": [
// "error",
// "windows"
// ],
// "quotes": [
// "error",
// "double"
// ],
// "semi": [
// "error",
// "always"
// ]
// }
// }
{
"env": {
"browser": true,
"commonjs": true,
"node": true,
"es6": true
},
"rules": {
"no-duplicate-case":"error",
"no-empty":"error",
"no-extra-semi":"error",
"no-func-assign": "error",
"no-irregular-whitespace":"error",
"no-unreachable": "error",
"curly": "error",
"dot-notation": "error",
"eqeqeq": "error",
"no-empty-function": "error",
"no-multi-spaces": "error",
"no-mixed-spaces-and-tabs": "error",
"no-trailing-spaces": "error",
"default-case": "error",
"no-fallthrough": "error",
"no-use-before-define": "error",
"no-redeclare": "error",
"camelcase": "error",
"brace-style": "error",
"indent": [
"error",
2
],
// "linebreak-style": [
// "error",
// "windows"
// ],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
]
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
.vscode
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cache:
services:
- mysql
before_install:
- mysql -e 'CREATE DATABASE IF NOT EXISTS blog_machine;'
- mysql -e 'CREATE DATABASE IF NOT EXISTS blog_machine;'
Binary file added BlogMachine.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 106 additions & 6 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/middleware/isAuthenticated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(req, res, next) {
module.exports = function (req, res, next) {
// If the user is logged in, continue with the request to the restricted route
if (req.user) {
return next();
Expand Down
27 changes: 27 additions & 0 deletions config/middleware/isBlogOwner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const db = require("../../models");

// This is a middleware function that determines if the signed in user is the blog owner and if they are allowed to edit/delete a blog.
// Only blog owners are allowed to edit and delete their own blogs.
// A potential added feature would be to make certain users site admins.
// Then we could also allow site admins here for viewing the blogs.
module.exports = function (req, res, next) {
let blogId;

// Determines ing blog ID is query or parameter
if (req.query.blog_id) {
blogId = req.query.blog_id;
} else if (req.params.id) {
blogId = req.params.id;
}

// If user is blog owner, return next callback. Else if user is not blog owner, redirect them to the index page because they are not allowed to be there
db.Blog.findOne({
where: { id: blogId }
}).then(function (blog) {
if (blog.UserId === req.user.id) {
return next();
} else {
res.redirect("/");
}
});
};
29 changes: 0 additions & 29 deletions config/multer 2.js

This file was deleted.

13 changes: 8 additions & 5 deletions config/multer.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
const multer = require("multer");

// Storage defines the directory that the profile pictures are stared, in this case the uploads directory in the public layer.
const storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, "./public/upload/")
cb(null, "./public/upload/");
},
filename: function(req, file, cb) {
console.log(new Date().toISOString())
cb(null, new Date().toISOString().replace(/:/g, "c") + file.originalname)
console.log(new Date().toISOString());
cb(null, new Date().toISOString().replace(/:/g, "c") + file.originalname);
}
});

// Filters files to make sure only images or gifs are uploaded
const fileFilter = (req, file, cb) => {
if (file.mimetype === "image/jpeg" || file.mimetype === "image/png" || file.mimetype === "image/gif") {
cb(null, true);
} else {
cb(null, false);
}
}
};

// Upload multer function uses the storage function and fileFilter function seen above and determins the filesize to be 5 MB
const upload = multer({
storage: storage,
limits: {
fileSize: 5000000
},
fileFilter: fileFilter
})
});

module.exports = upload;
11 changes: 5 additions & 6 deletions config/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ passport.use(new LocalStrategy(
{
usernameField: "email"
},
function(email, password, done) {
function (email, password, done) {
db.User.findOne({
where: {
email: email
}
}).then(function(dbUser) {
}).then(function (dbUser) {
if (!dbUser) {
return done(null, false, {
message: "Incorrect email."
});
}
else if (!dbUser.validPassword(password)) {
} else if (!dbUser.validPassword(password)) {
return done(null, false, {
message: "Incorrect password."
});
Expand All @@ -28,11 +27,11 @@ passport.use(new LocalStrategy(
}
));

passport.serializeUser(function(user, cb) {
passport.serializeUser(function (user, cb) {
cb(null, user);
});

passport.deserializeUser(function(obj, cb) {
passport.deserializeUser(function (obj, cb) {
cb(null, obj);
});

Expand Down
Binary file removed default 2.png
Binary file not shown.
Binary file removed default.png
Binary file not shown.
16 changes: 11 additions & 5 deletions models/blog.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module.exports = function(sequelize, DataTypes) {
module.exports = function (sequelize, DataTypes) {
// Defines Blog table with title, body, and mood strings
var Blog = sequelize.define("Blog", {
title: {
type: DataTypes.STRING,
allowNull: false,
validate: {
len: [0, 50]
len: [1, 50]
}
},
body: {
type: DataTypes.TEXT,
allowNull: false,
validate: {
len: [0, 100000]
len: [1, 100000]
}
},
mood: {
Expand All @@ -23,18 +24,23 @@ module.exports = function(sequelize, DataTypes) {
}
});

Blog.associate = function(models) {
// Associates blogs with Users and Categories, creates CategoryId and UserId foreign key rows.
Blog.associate = function (models) {
// If user is deleted, all of their blogs are deleted
Blog.belongsTo(models.User, {
onDelete: "CASCADE"
}, {
foreignKey: {
allowNull: false
}
});
// Cannot deleted category that has blogs assigned to it, they are protected.
Blog.belongsTo(models.Category, {
foreignKey: {
allowNull: false
}
});
}
};

return Blog;
};
28 changes: 15 additions & 13 deletions models/category.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module.exports = function(sequelize, DataTypes) {
var Category = sequelize.define("Category", {
name: {
type: DataTypes.STRING,
allowNull: false
}
});

Category.associate = function(models) {
Category.hasMany(models.Blog);
};
module.exports = function (sequelize, DataTypes) {
// Created Category table with a name string row
var Category = sequelize.define("Category", {
name: {
type: DataTypes.STRING,
allowNull: false
}
});

return Category;
};
// Associates category with the many blogs assigned to 1 category
Category.associate = function (models) {
Category.hasMany(models.Blog);
};

return Category;
};
18 changes: 11 additions & 7 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const bcrypt = require("bcryptjs");

module.exports = function(sequelize, DataTypes) {
module.exports = function (sequelize, DataTypes) {
// Defines the user table with all user information
const User = sequelize.define("User", {
email: {
type: DataTypes.STRING,
Expand All @@ -21,6 +22,8 @@ module.exports = function(sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false
},
// Pictures are locally stored in the public/uploads/ directory instead of stored as a blob on the database.
// An additional feature could be to store pictures in database as blob row instead of as string of the file path.
picture: {
type: DataTypes.STRING,
allowNull: true
Expand Down Expand Up @@ -62,17 +65,18 @@ module.exports = function(sequelize, DataTypes) {
}
});

User.associate = function(models) {
User.hasMany(models.Blog, {
onDelete: "cascade"
});
// Associates users with the many blogs they own
User.associate = function (models) {
User.hasMany(models.Blog);
};

User.prototype.validPassword = function(password) {
// Makes sure hashed password can be compared to unhashed password
User.prototype.validPassword = function (password) {
return bcrypt.compareSync(password, this.password);
};

User.addHook("beforeCreate", function(user) {
// Creates a hook that makes sure password is hashed before added to the database.
User.addHook("beforeCreate", function (user) {
user.password = bcrypt.hashSync(user.password, bcrypt.genSaltSync(10), null);
});
return User;
Expand Down
Loading