mirror of
https://github.com/microsoft/TypeScript-Node-Starter.git
synced 2026-03-25 14:40:47 +00:00
Merge branch 'master' into refactor-remove-unused-imports
This commit is contained in:
@@ -34,6 +34,7 @@ const app = express();
|
||||
// Connect to MongoDB
|
||||
const mongoUrl = MONGODB_URI;
|
||||
(<any>mongoose).Promise = bluebird;
|
||||
|
||||
mongoose.connect(mongoUrl, { useMongoClient: true }).then(
|
||||
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
|
||||
).catch(err => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import passportFacebook from "passport-facebook";
|
||||
import _ from "lodash";
|
||||
|
||||
// import { User, UserType } from '../models/User';
|
||||
import { default as User } from "../models/User";
|
||||
import { User } from "../models/User";
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
|
||||
const LocalStrategy = passportLocal.Strategy;
|
||||
|
||||
@@ -2,7 +2,7 @@ import async from "async";
|
||||
import crypto from "crypto";
|
||||
import nodemailer from "nodemailer";
|
||||
import passport from "passport";
|
||||
import { default as User, UserModel, AuthToken } from "../models/User";
|
||||
import { User, UserDocument, AuthToken } from "../models/User";
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { IVerifyOptions } from "passport-local";
|
||||
import { WriteError } from "mongodb";
|
||||
@@ -37,7 +37,7 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => {
|
||||
return res.redirect("/login");
|
||||
}
|
||||
|
||||
passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => {
|
||||
passport.authenticate("local", (err: Error, user: UserDocument, info: IVerifyOptions) => {
|
||||
if (err) { return next(err); }
|
||||
if (!user) {
|
||||
req.flash("errors", info.message);
|
||||
@@ -138,7 +138,7 @@ export let postUpdateProfile = (req: Request, res: Response, next: NextFunction)
|
||||
return res.redirect("/account");
|
||||
}
|
||||
|
||||
User.findById(req.user.id, (err, user: UserModel) => {
|
||||
User.findById(req.user.id, (err, user: UserDocument) => {
|
||||
if (err) { return next(err); }
|
||||
user.email = req.body.email || "";
|
||||
user.profile.name = req.body.name || "";
|
||||
@@ -174,7 +174,7 @@ export let postUpdatePassword = (req: Request, res: Response, next: NextFunction
|
||||
return res.redirect("/account");
|
||||
}
|
||||
|
||||
User.findById(req.user.id, (err, user: UserModel) => {
|
||||
User.findById(req.user.id, (err, user: UserDocument) => {
|
||||
if (err) { return next(err); }
|
||||
user.password = req.body.password;
|
||||
user.save((err: WriteError) => {
|
||||
@@ -276,7 +276,7 @@ export let postReset = (req: Request, res: Response, next: NextFunction) => {
|
||||
});
|
||||
});
|
||||
},
|
||||
function sendResetPasswordEmail(user: UserModel, done: Function) {
|
||||
function sendResetPasswordEmail(user: UserDocument, done: Function) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: "SendGrid",
|
||||
auth: {
|
||||
@@ -350,7 +350,7 @@ export let postForgot = (req: Request, res: Response, next: NextFunction) => {
|
||||
});
|
||||
});
|
||||
},
|
||||
function sendForgotPasswordEmail(token: AuthToken, user: UserModel, done: Function) {
|
||||
function sendForgotPasswordEmail(token: AuthToken, user: UserDocument, done: Function) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: "SendGrid",
|
||||
auth: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import bcrypt from "bcrypt-nodejs";
|
||||
import crypto from "crypto";
|
||||
import mongoose from "mongoose";
|
||||
|
||||
export type UserModel = mongoose.Document & {
|
||||
export type UserDocument = mongoose.Document & {
|
||||
email: string,
|
||||
password: string,
|
||||
passwordResetToken: string,
|
||||
@@ -88,6 +88,4 @@ userSchema.methods.gravatar = function (size: number) {
|
||||
return `https://gravatar.com/avatar/${md5}?s=${size}&d=retro`;
|
||||
};
|
||||
|
||||
// export const User: UserType = mongoose.model<UserType>('User', userSchema);
|
||||
const User = mongoose.model("User", userSchema);
|
||||
export default User;
|
||||
export const User = mongoose.model<UserDocument>("User", userSchema);
|
||||
|
||||
@@ -21,6 +21,10 @@ if (!SESSION_SECRET) {
|
||||
}
|
||||
|
||||
if (!MONGODB_URI) {
|
||||
logger.error("No mongo connection string. Set MONGODB_URI environment variable.");
|
||||
if (prod) {
|
||||
logger.error("No mongo connection string. Set MONGODB_URI environment variable.");
|
||||
} else {
|
||||
logger.error("No mongo connection string. Set MONGODB_URI_LOCAL environment variable.");
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user