diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/authentication/controllers/user.ts | 8 | ||||
-rw-r--r-- | src/server/authentication/models/User.ts | 4 | ||||
-rw-r--r-- | src/server/index.ts | 38 |
3 files changed, 46 insertions, 4 deletions
diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index 93986adf8..a496959d1 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -12,6 +12,8 @@ import * as pug from 'pug'; * GET / * Whenever a user navigates to the root of Dash * (doesn't specify a sub-route), redirect to login. + * If the user is already signed in, it will effectively + * automatically redirect them to /home instead */ export let getEntry = (req: Request, res: Response) => { res.redirect("/login"); @@ -29,6 +31,7 @@ export let getSignup = (req: Request, res: Response) => { } res.render("signup.pug", { title: "Sign Up", + user: req.user, errors: req.flash("Unable to facilitate sign up. Please try again.") }); }; @@ -61,7 +64,9 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { const user = new User({ email, password, + userDoc: "document here" }); + User.findOne({ email }, (err, existingUser) => { if (err) { return next(err); } if (existingUser) { @@ -94,7 +99,8 @@ export let getLogin = (req: Request, res: Response) => { return res.redirect("/home"); } res.render("login.pug", { - title: "Log In" + title: "Log In", + user: req.user }); }; diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts index ed2952e48..9e6c525c3 100644 --- a/src/server/authentication/models/User.ts +++ b/src/server/authentication/models/User.ts @@ -1,6 +1,5 @@ //@ts-ignore import * as bcrypt from "bcrypt-nodejs"; -import * as crypto from "crypto"; //@ts-ignore import * as mongoose from "mongoose"; var url = 'mongodb://localhost:27017/Dash' @@ -46,8 +45,7 @@ const userSchema = new mongoose.Schema({ password: String, passwordResetToken: String, passwordResetExpires: Date, - - workspaces: Array, + userDoc: String, facebook: String, twitter: String, diff --git a/src/server/index.ts b/src/server/index.ts index 7189b32a0..039d7f56a 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -13,6 +13,7 @@ import { FIELD_ID, Field } from '../fields/Field'; import { Database } from './database'; import { ServerUtils } from './ServerUtil'; import { ObjectID } from 'mongodb'; +import * as bcrypt from "bcrypt-nodejs"; import { Document } from '../fields/Document'; import * as io from 'socket.io' import * as passportConfig from './authentication/config/passport'; @@ -27,12 +28,15 @@ import flash = require('express-flash'); import * as bodyParser from 'body-parser'; import * as session from 'express-session'; import * as cookieParser from 'cookie-parser'; +import * as nodemailer from 'nodemailer'; import c = require("crypto"); const MongoStore = require('connect-mongo')(session); const mongoose = require('mongoose'); +import * as async from 'async'; const bluebird = require('bluebird'); import { performance } from 'perf_hooks' import * as path from 'path' +import User from './authentication/models/User'; const mongoUrl = 'mongodb://localhost:27017/Dash'; // mongoose.Promise = bluebird; @@ -106,6 +110,40 @@ app.get('/logout', getLogout); // *** +// FORGOT PASSWORD EMAIL HANDLING +app.post('/forgot', function (req, res, next) { + const email = req.body.email; + async.waterfall([ + function (done: any) { + const seed = new Uint16Array(); + seed.set([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); + let token = crypto.getRandomValues(seed); + done(token); + }, + function (token: Uint16Array, done: any) { + User.findOne({ email }, function (err, user: User) { + if (!user) { + // NO ACCOUNT WITH SUBMITTED EMAIL + return res.redirect('/forgot'); + } + user.resetPasswordToken = token; + user.resetPasswordExpires = Date.now() + 3600000; // 1 HOUR + user.save(function (err: any) { + done(err, token, user); + }); + }); + }, + function (token: Uint16Array, user: User, done: any) { + const transport = nodemailer.createTransport('SMTP', { + auth: { + user: 'test.nodemailer@gmail.com', + pass: 'placeholder' + } + }); + } + ]) +}) + let FieldStore: ObservableMap<FIELD_ID, Field> = new ObservableMap(); app.get("/hello", (req, res) => { |