Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 018200a

Browse files
author
Orta
authored
Merge pull request #200 from peterblazejewicz/update/deps
Update project dependencies
2 parents c37be99 + ccf6ad8 commit 018200a

File tree

9 files changed

+528
-572
lines changed

9 files changed

+528
-572
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
MONGODB_URI=mongodb://<mlab_user>:<mlab_password>@<mlab_connection_url>
77

88
# This is standard running mongodb locally
9-
MONGODB_URI_LOCAL=mongodb://localhost:27017
9+
MONGODB_URI_LOCAL=mongodb://localhost:27017/<database>
1010

1111
# Put lots of randomness in these
1212
SESSION_SECRET=ashdfjhasdlkjfhalksdjhflak

package-lock.json

+419-465
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+51-51
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,68 @@
2727
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
2828
},
2929
"dependencies": {
30-
"async": "^2.6.0",
30+
"async": "^3.0.1",
3131
"bcrypt-nodejs": "^0.0.3",
32-
"bluebird": "^3.5.1",
33-
"body-parser": "^1.18.2",
34-
"compression": "^1.7.1",
35-
"connect-mongo": "^2.0.0",
36-
"dotenv": "^4.0.0",
37-
"errorhandler": "^1.5.0",
38-
"express": "^4.16.2",
32+
"bluebird": "^3.5.5",
33+
"body-parser": "^1.19.0",
34+
"compression": "^1.7.4",
35+
"connect-mongo": "^3.0.0",
36+
"dotenv": "^8.0.0",
37+
"errorhandler": "^1.5.1",
38+
"express": "^4.17.1",
3939
"express-flash": "0.0.2",
40-
"express-session": "^1.15.6",
41-
"express-validator": "^4.3.0",
42-
"fbgraph": "^1.4.1",
43-
"lodash": "^4.17.5",
44-
"lusca": "^1.5.2",
45-
"mongoose": "^5.4.2",
46-
"nodemailer": "^4.4.1",
40+
"express-session": "^1.16.2",
41+
"express-validator": "^6.0.1",
42+
"fbgraph": "^1.4.4",
43+
"lodash": "^4.17.11",
44+
"lusca": "^1.6.1",
45+
"mongoose": "^5.6.0",
46+
"nodemailer": "^6.2.1",
4747
"passport": "^0.4.0",
48-
"passport-facebook": "^2.1.1",
48+
"passport-facebook": "^3.0.0",
4949
"passport-local": "^1.0.0",
50-
"pug": "^2.0.3",
50+
"pug": "^2.0.4",
5151
"request": "^2.88.0",
52-
"request-promise": "^4.2.2",
53-
"winston": "^2.4.0"
52+
"request-promise": "^4.2.4",
53+
"winston": "^2.4.2"
5454
},
5555
"devDependencies": {
56-
"@types/async": "^2.0.45",
56+
"@types/async": "^3.0.0",
5757
"@types/bcrypt-nodejs": "^0.0.30",
58-
"@types/bluebird": "^3.5.20",
59-
"@types/body-parser": "^1.16.8",
60-
"@types/compression": "^0.0.35",
61-
"@types/connect-mongo": "^0.0.35",
62-
"@types/dotenv": "^4.0.2",
58+
"@types/bluebird": "^3.5.27",
59+
"@types/body-parser": "^1.17.0",
60+
"@types/compression": "^0.0.36",
61+
"@types/connect-mongo": "^0.0.42",
62+
"@types/dotenv": "^6.1.1",
6363
"@types/errorhandler": "^0.0.32",
64-
"@types/express": "^4.11.1",
65-
"@types/express-session": "^1.15.8",
66-
"@types/jest": "^22.1.3",
64+
"@types/express": "^4.17.0",
65+
"@types/express-session": "^1.15.13",
66+
"@types/jest": "^24.0.15",
6767
"@types/jquery": "^3.3.29",
68-
"@types/lodash": "^4.14.91",
69-
"@types/lusca": "^1.5.0",
70-
"@types/mongodb": "^3.0.5",
71-
"@types/mongoose": "^4.7.34",
68+
"@types/lodash": "^4.14.134",
69+
"@types/lusca": "^1.6.0",
70+
"@types/mongodb": "^3.1.28",
71+
"@types/mongoose": "^5.5.6",
7272
"@types/morgan": "^1.7.35",
73-
"@types/node": "^9.4.6",
74-
"@types/nodemailer": "^4.3.4",
75-
"@types/passport": "^0.4.3",
76-
"@types/passport-facebook": "^2.1.7",
77-
"@types/passport-local": "^1.0.32",
78-
"@types/request": "^2.47.0",
79-
"@types/shelljs": "^0.7.8",
80-
"@types/supertest": "^2.0.4",
81-
"@types/winston": "^2.3.7",
82-
"chai": "^4.1.2",
83-
"concurrently": "^3.5.1",
84-
"jest": "^24.0.0",
73+
"@types/node": "^12.0.10",
74+
"@types/nodemailer": "^6.2.0",
75+
"@types/passport": "^1.0.0",
76+
"@types/passport-facebook": "^2.1.9",
77+
"@types/passport-local": "^1.0.33",
78+
"@types/request": "^2.48.1",
79+
"@types/shelljs": "^0.8.5",
80+
"@types/supertest": "^2.0.7",
81+
"@types/winston": "^2.3.9",
82+
"chai": "^4.2.0",
83+
"concurrently": "^4.1.0",
84+
"jest": "^24.8.0",
8585
"node-sass": "^4.12.0",
86-
"nodemon": "^1.18.10",
87-
"shelljs": "^0.8.1",
88-
"supertest": "^3.0.0",
89-
"ts-jest": "^24.0.0",
90-
"ts-node": "^5.0.0",
91-
"tslint": "^5.9.1",
92-
"typescript": "^3.4.5"
86+
"nodemon": "^1.19.1",
87+
"shelljs": "^0.8.3",
88+
"supertest": "^4.0.2",
89+
"ts-jest": "^24.0.2",
90+
"ts-node": "^8.3.0",
91+
"tslint": "^5.18.0",
92+
"typescript": "^3.5.2"
9393
}
9494
}

src/app.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import flash from "express-flash";
99
import path from "path";
1010
import mongoose from "mongoose";
1111
import passport from "passport";
12-
import expressValidator from "express-validator";
1312
import bluebird from "bluebird";
1413
import { MONGODB_URI, SESSION_SECRET } from "./util/secrets";
1514

@@ -35,7 +34,7 @@ const app = express();
3534
const mongoUrl = MONGODB_URI;
3635
(<any>mongoose).Promise = bluebird;
3736

38-
mongoose.connect(mongoUrl, { useMongoClient: true }).then(
37+
mongoose.connect(mongoUrl, { useNewUrlParser: true} ).then(
3938
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
4039
).catch(err => {
4140
console.log("MongoDB connection error. Please make sure MongoDB is running. " + err);
@@ -49,7 +48,6 @@ app.set("view engine", "pug");
4948
app.use(compression());
5049
app.use(bodyParser.json());
5150
app.use(bodyParser.urlencoded({ extended: true }));
52-
app.use(expressValidator());
5351
app.use(session({
5452
resave: true,
5553
saveUninitialized: true,

src/controllers/contact.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import nodemailer from "nodemailer";
22
import { Request, Response } from "express";
3+
import { check, validationResult } from "express-validator";
34

45
const transporter = nodemailer.createTransport({
56
service: "SendGrid",
@@ -24,14 +25,14 @@ export const getContact = (req: Request, res: Response) => {
2425
* Send a contact form via Nodemailer.
2526
*/
2627
export const postContact = (req: Request, res: Response) => {
27-
req.assert("name", "Name cannot be blank").notEmpty();
28-
req.assert("email", "Email is not valid").isEmail();
29-
req.assert("message", "Message cannot be blank").notEmpty();
28+
check("name", "Name cannot be blank").not().isEmpty();
29+
check("email", "Email is not valid").isEmail();
30+
check("message", "Message cannot be blank").not().isEmpty();
3031

31-
const errors = req.validationErrors();
32+
const errors = validationResult(req);
3233

33-
if (errors) {
34-
req.flash("errors", errors);
34+
if (!errors.isEmpty()) {
35+
req.flash("errors", errors.array());
3536
return res.redirect("/contact");
3637
}
3738

src/controllers/user.ts

+35-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { User, UserDocument, AuthToken } from "../models/User";
66
import { Request, Response, NextFunction } from "express";
77
import { IVerifyOptions } from "passport-local";
88
import { WriteError } from "mongodb";
9-
import request from "express-validator";
9+
import { check, sanitize, validationResult } from "express-validator";
1010
import "../config/passport";
1111

1212
/**
@@ -27,21 +27,21 @@ export const getLogin = (req: Request, res: Response) => {
2727
* Sign in using email and password.
2828
*/
2929
export const postLogin = (req: Request, res: Response, next: NextFunction) => {
30-
req.assert("email", "Email is not valid").isEmail();
31-
req.assert("password", "Password cannot be blank").notEmpty();
32-
req.sanitize("email").normalizeEmail({ gmail_remove_dots: false });
30+
check("email", "Email is not valid").isEmail();
31+
check("password", "Password cannot be blank").isLength({min: 1});
32+
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
3333

34-
const errors = req.validationErrors();
34+
const errors = validationResult(req);
3535

36-
if (errors) {
37-
req.flash("errors", errors);
36+
if (!errors.isEmpty()) {
37+
req.flash("errors", errors.array());
3838
return res.redirect("/login");
3939
}
4040

4141
passport.authenticate("local", (err: Error, user: UserDocument, info: IVerifyOptions) => {
4242
if (err) { return next(err); }
4343
if (!user) {
44-
req.flash("errors", info.message);
44+
req.flash("errors", {msg: info.message});
4545
return res.redirect("/login");
4646
}
4747
req.logIn(user, (err) => {
@@ -79,15 +79,15 @@ export const getSignup = (req: Request, res: Response) => {
7979
* Create a new local account.
8080
*/
8181
export const postSignup = (req: Request, res: Response, next: NextFunction) => {
82-
req.assert("email", "Email is not valid").isEmail();
83-
req.assert("password", "Password must be at least 4 characters long").len({ min: 4 });
84-
req.assert("confirmPassword", "Passwords do not match").equals(req.body.password);
85-
req.sanitize("email").normalizeEmail({ gmail_remove_dots: false });
82+
check("email", "Email is not valid").isEmail();
83+
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
84+
check("confirmPassword", "Passwords do not match").equals(req.body.password);
85+
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
8686

87-
const errors = req.validationErrors();
87+
const errors = validationResult(req);
8888

89-
if (errors) {
90-
req.flash("errors", errors);
89+
if (!errors.isEmpty()) {
90+
req.flash("errors", errors.array());
9191
return res.redirect("/signup");
9292
}
9393

@@ -129,13 +129,13 @@ export const getAccount = (req: Request, res: Response) => {
129129
* Update profile information.
130130
*/
131131
export const postUpdateProfile = (req: Request, res: Response, next: NextFunction) => {
132-
req.assert("email", "Please enter a valid email address.").isEmail();
133-
req.sanitize("email").normalizeEmail({ gmail_remove_dots: false });
132+
check("email", "Please enter a valid email address.").isEmail();
133+
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
134134

135-
const errors = req.validationErrors();
135+
const errors = validationResult(req);
136136

137-
if (errors) {
138-
req.flash("errors", errors);
137+
if (!errors.isEmpty()) {
138+
req.flash("errors", errors.array());
139139
return res.redirect("/account");
140140
}
141141

@@ -165,13 +165,13 @@ export const postUpdateProfile = (req: Request, res: Response, next: NextFunctio
165165
* Update current password.
166166
*/
167167
export const postUpdatePassword = (req: Request, res: Response, next: NextFunction) => {
168-
req.assert("password", "Password must be at least 4 characters long").len({ min: 4 });
169-
req.assert("confirmPassword", "Passwords do not match").equals(req.body.password);
168+
check("password", "Password must be at least 4 characters long").isLength({ min: 4 });
169+
check("confirmPassword", "Passwords do not match").equals(req.body.password);
170170

171-
const errors = req.validationErrors();
171+
const errors = validationResult(req);
172172

173-
if (errors) {
174-
req.flash("errors", errors);
173+
if (!errors.isEmpty()) {
174+
req.flash("errors", errors.array());
175175
return res.redirect("/account");
176176
}
177177

@@ -245,13 +245,13 @@ export const getReset = (req: Request, res: Response, next: NextFunction) => {
245245
* Process the reset password request.
246246
*/
247247
export const postReset = (req: Request, res: Response, next: NextFunction) => {
248-
req.assert("password", "Password must be at least 4 characters long.").len({ min: 4 });
249-
req.assert("confirm", "Passwords must match.").equals(req.body.password);
248+
check("password", "Password must be at least 4 characters long.").isLength({ min: 4 });
249+
check("confirm", "Passwords must match.").equals(req.body.password);
250250

251-
const errors = req.validationErrors();
251+
const errors = validationResult(req);
252252

253-
if (errors) {
254-
req.flash("errors", errors);
253+
if (!errors.isEmpty()) {
254+
req.flash("errors", errors.array());
255255
return res.redirect("back");
256256
}
257257

@@ -320,13 +320,13 @@ export const getForgot = (req: Request, res: Response) => {
320320
* Create a random token, then the send user an email with a reset link.
321321
*/
322322
export const postForgot = (req: Request, res: Response, next: NextFunction) => {
323-
req.assert("email", "Please enter a valid email address.").isEmail();
324-
req.sanitize("email").normalizeEmail({ gmail_remove_dots: false });
323+
check("email", "Please enter a valid email address.").isEmail();
324+
sanitize("email").normalizeEmail({ gmail_remove_dots: false });
325325

326-
const errors = req.validationErrors();
326+
const errors = validationResult(req);
327327

328-
if (errors) {
329-
req.flash("errors", errors);
328+
if (!errors.isEmpty()) {
329+
req.flash("errors", errors.array());
330330
return res.redirect("/forgot");
331331
}
332332

src/models/User.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const userSchema = new mongoose.Schema({
5454
* Password hash middleware.
5555
*/
5656
userSchema.pre("save", function save(next) {
57-
const user = this;
57+
const user = this as UserDocument;
5858
if (!user.isModified("password")) { return next(); }
5959
bcrypt.genSalt(10, (err, salt) => {
6060
if (err) { return next(err); }

src/util/logger.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import winston from "winston";
2-
import { Logger } from "winston";
1+
import { Logger, LoggerOptions, transports } from "winston";
32

4-
const logger = new (Logger)({
5-
transports: [
6-
new (winston.transports.Console)({ level: process.env.NODE_ENV === "production" ? "error" : "debug" }),
7-
new (winston.transports.File)({ filename: "debug.log", level: "debug"})
8-
]
9-
});
3+
const options: LoggerOptions = {
4+
transports: [
5+
new transports.Console({
6+
level: process.env.NODE_ENV === "production" ? "error" : "debug"
7+
}),
8+
new transports.File({ filename: "debug.log", level: "debug" })
9+
]
10+
};
11+
12+
const logger = new Logger(options);
1013

1114
if (process.env.NODE_ENV !== "production") {
12-
logger.debug("Logging initialized at debug level");
15+
logger.debug("Logging initialized at debug level");
1316
}
1417

1518
export default logger;
16-

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"esModuleInterop": true,
5+
"allowSyntheticDefaultImports": true,
56
"target": "es6",
67
"noImplicitAny": true,
78
"moduleResolution": "node",

0 commit comments

Comments
 (0)