aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.json4
-rw-r--r--src/server/authentication/controllers/user_controller.ts25
-rw-r--r--src/server/authentication/models/user_model.ts2
-rw-r--r--src/server/index.ts2
4 files changed, 19 insertions, 14 deletions
diff --git a/package.json b/package.json
index 22b3a6b21..7407a719f 100644
--- a/package.json
+++ b/package.json
@@ -73,7 +73,7 @@
"@types/lodash": "^4.14.121",
"@types/mobile-detect": "^1.3.4",
"@types/mongodb": "^3.1.22",
- "@types/mongoose": "^5.3.21",
+ "@types/mongoose": "^5.5.8",
"@types/node": "^10.12.30",
"@types/nodemailer": "^4.6.6",
"@types/passport": "^1.0.0",
@@ -144,7 +144,7 @@
"mobx-react-devtools": "^6.1.1",
"mobx-utils": "^5.4.0",
"mongodb": "^3.1.13",
- "mongoose": "^5.4.18",
+ "mongoose": "^5.6.4",
"node-sass": "^4.12.0",
"nodemailer": "^5.1.1",
"nodemon": "^1.18.10",
diff --git a/src/server/authentication/controllers/user_controller.ts b/src/server/authentication/controllers/user_controller.ts
index ca4fc171c..fa1cd647d 100644
--- a/src/server/authentication/controllers/user_controller.ts
+++ b/src/server/authentication/controllers/user_controller.ts
@@ -12,6 +12,9 @@ import * as nodemailer from 'nodemailer';
import c = require("crypto");
import { RouteStore } from "../../RouteStore";
import { Utils } from "../../../Utils";
+import { Schema } from "mongoose";
+import { Opt } from "../../../new_fields/Doc";
+import { MailOptions } from "nodemailer/lib/stream-transport";
/**
* GET /signup
@@ -45,21 +48,23 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => {
return res.redirect(RouteStore.signup);
}
- const email = req.body.email;
+ const email = req.body.email as String;
const password = req.body.password;
- const user = new User({
- email,
+ const model = {
+ email: { type: email, unique: true },
password,
userDocumentId: Utils.GenerateGuid()
- });
+ } as Partial<DashUserModel>;
+
+ const user = new User(model);
User.findOne({ email }, (err, existingUser) => {
if (err) { return next(err); }
if (existingUser) {
return res.redirect(RouteStore.login);
}
- user.save((err) => {
+ user.save((err: any) => {
if (err) { return next(err); }
req.logIn(user, (err) => {
if (err) { return next(err); }
@@ -181,15 +186,15 @@ export let postForgot = function (req: Request, res: Response, next: NextFunctio
}
});
const mailOptions = {
- to: user.email,
+ to: user.email.type,
from: 'brownptcdash@gmail.com',
subject: 'Dash Password Reset',
text: 'You are receiving this because you (or someone else) have requested the reset of the password for your account.\n\n' +
'Please click on the following link, or paste this into your browser to complete the process:\n\n' +
'http://' + req.headers.host + '/reset/' + token + '\n\n' +
'If you did not request this, please ignore this email and your password will remain unchanged.\n'
- };
- smtpTransport.sendMail(mailOptions, function (err) {
+ } as MailOptions;
+ smtpTransport.sendMail(mailOptions, function (err: Error | null) {
// req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.');
done(null, err, 'done');
});
@@ -254,12 +259,12 @@ export let postReset = function (req: Request, res: Response) {
}
});
const mailOptions = {
- to: user.email,
+ to: user.email.type,
from: 'brownptcdash@gmail.com',
subject: 'Your password has been changed',
text: 'Hello,\n\n' +
'This is a confirmation that the password for your account ' + user.email + ' has just been changed.\n'
- };
+ } as MailOptions;
smtpTransport.sendMail(mailOptions, function (err) {
done(null, err);
});
diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts
index ee85e1c05..fb62de1c8 100644
--- a/src/server/authentication/models/user_model.ts
+++ b/src/server/authentication/models/user_model.ts
@@ -16,7 +16,7 @@ mongoose.connection.on('disconnected', function () {
console.log('connection closed');
});
export type DashUserModel = mongoose.Document & {
- email: string,
+ email: { type: String, unique: true },
password: string,
passwordResetToken?: string,
passwordResetExpires?: Date,
diff --git a/src/server/index.ts b/src/server/index.ts
index 1c0dec05b..06f8358e1 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -58,7 +58,7 @@ clientUtils = `//AUTO-GENERATED FILE: DO NOT EDIT\n${clientUtils.replace('"mode"
fs.writeFileSync("./src/client/util/ClientUtils.ts", clientUtils, "utf8");
const mongoUrl = 'mongodb://localhost:27017/Dash';
-mongoose.connect(mongoUrl);
+mongoose.connection.readyState === 0 && mongoose.connect(mongoUrl);
mongoose.connection.on('connected', () => console.log("connected"));
// SESSION MANAGEMENT AND AUTHENTICATION MIDDLEWARE