From b140847f9f9de19879bd1bdf896b995c87761272 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 14:11:16 -0500 Subject: commenting and preliminary login styling --- views/stylesheets/authentication.css | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 views/stylesheets/authentication.css (limited to 'views/stylesheets/authentication.css') diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css new file mode 100644 index 000000000..dd49e31dc --- /dev/null +++ b/views/stylesheets/authentication.css @@ -0,0 +1,62 @@ +#email_label { + color: blue; + margin-top: 10px; +} + +h3, +label { + font-family: Arial, Helvetica, sans-serif; +} + +body { + background-color: lightslategray; +} + +#login_label { + text-align: left; +} + +#submit { + width: 224px; + height: 35px; + font-family: Arial, Helvetica, sans-serif; + font-size: 14px; + font-style: oblique; +} + +.overlay { + text-align: center; + position: absolute; + margin: auto; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 400px; + height: 300px; + background-color: white; + border-radius: 8px; + box-shadow: 10px 10px 10px #00000033; +} + +.inner { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + width: 230px; + height: 230px; + margin: auto; +} + +.form-control { + width: 200px; + margin-bottom: 15px; + height: 30px; + outline: none; + padding-left: 10px; + padding-right: 10px; + font-family: Arial, Helvetica, sans-serif; + font-size: 16px; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 28fc26cec5faa0ac1f70a37aa6a23d6cb2d61f03 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 14:17:45 -0500 Subject: fixed form --- views/login.pug | 34 +++++++++++++++++----------------- views/stylesheets/authentication.css | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'views/stylesheets/authentication.css') diff --git a/views/login.pug b/views/login.pug index c5ece88e4..fb97d3171 100644 --- a/views/login.pug +++ b/views/login.pug @@ -5,20 +5,20 @@ block content style include ./stylesheets/authentication.css form.form-horizontal(id='login-form', method='POST') - input(type='hidden', name='_csrf', value=_csrf) - .overlay - .inner - h3(id='login_label') Log In - .form-group - //- label.col-sm-3.control-label(for='email', id='email_label') Email - .col-sm-7 - input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required) - .form-group - //- label.col-sm-3.control-label(for='password') Password - .col-sm-7 - input.form-control(type='password', name='password', id='password', placeholder='Password', required) - .form-group - .col-sm-offset-3.col-sm-7 - button.btn.btn-success(id='submit', type='submit') - i.fa.fa-user-plus - | Submit \ No newline at end of file + input(type='hidden', name='_csrf', value=_csrf) + .overlay + .inner + h3(id='login_label') Log In + .form-group + //- label.col-sm-3.control-label(for='email', id='email_label') Email + .col-sm-7 + input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required) + .form-group + //- label.col-sm-3.control-label(for='password') Password + .col-sm-7 + input.form-control(type='password', name='password', id='password', placeholder='Password', required) + .form-group + .col-sm-offset-3.col-sm-7 + button.btn.btn-success(id='submit', type='submit') + i.fa.fa-user-plus + | Submit \ No newline at end of file diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index dd49e31dc..43f2f228c 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -46,7 +46,7 @@ body { left: 0; right: 0; width: 230px; - height: 230px; + height: 220px; margin: auto; } -- cgit v1.2.3-70-g09d2 From b441bb2b67f10ae1b83363d158a0ac1591f63e51 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 15:47:07 -0500 Subject: rough ui finished --- src/client/views/Main.tsx | 13 ++++++++ src/server/authentication/controllers/user.ts | 16 ++-------- src/server/index.ts | 14 +++++++-- views/login.pug | 8 +++-- views/resources/dashlogo.png | Bin 0 -> 7169 bytes views/signup.pug | 43 +++++++++++++------------- views/stylesheets/authentication.css | 38 ++++++++++++++++++++--- 7 files changed, 87 insertions(+), 45 deletions(-) create mode 100644 views/resources/dashlogo.png (limited to 'views/stylesheets/authentication.css') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 858c02eb4..2a3e2780b 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -100,6 +100,19 @@ Documents.initProtos(() => { ReactDOM.render((
+ + + diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index 72fdd5137..554781409 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -5,7 +5,6 @@ import { IVerifyOptions } from "passport-local"; import "../config/passport"; import * as request from "express-validator"; const flash = require("express-flash"); -import * as path from 'path' import * as session from "express-session"; import * as pug from 'pug'; @@ -18,17 +17,6 @@ export let getEntry = (req: Request, res: Response) => { res.redirect("/login"); } -export let getHome = (req: Request, res: Response) => { - // if user is not logged in, redirect to log in page - if (!req.user) { - res.redirect("/login"); - return; - } - // otherwise, connect them to Dash - // TODO: store and manage users' workspaces - res.sendFile(path.join(__dirname, '../../deploy/index.html')); -} - /** * GET /signup * Directs user to the signup page @@ -38,7 +26,7 @@ export let getSignup = (req: Request, res: Response) => { if (req.user) { let user = req.user; console.log(user); - return res.redirect("/"); + return res.redirect("/home"); } res.render("signup.pug", { title: "Sign Up" @@ -104,7 +92,7 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { */ export let getLogin = (req: Request, res: Response) => { if (req.user) { - return res.redirect("/"); + return res.redirect("/home"); } res.render("login.pug", { title: "Log In" diff --git a/src/server/index.ts b/src/server/index.ts index d097b4aec..7189b32a0 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -16,7 +16,7 @@ import { ObjectID } from 'mongodb'; import { Document } from '../fields/Document'; import * as io from 'socket.io' import * as passportConfig from './authentication/config/passport'; -import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, getHome } from './authentication/controllers/user'; +import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry } from './authentication/controllers/user'; const config = require('../../webpack.config'); const compiler = webpack(config); const port = 1050; // default port to listen @@ -32,6 +32,7 @@ const MongoStore = require('connect-mongo')(session); const mongoose = require('mongoose'); const bluebird = require('bluebird'); import { performance } from 'perf_hooks' +import * as path from 'path' const mongoUrl = 'mongodb://localhost:27017/Dash'; // mongoose.Promise = bluebird; @@ -77,7 +78,16 @@ app.use((req, res, next) => { // functions in the exports of user.ts // /home defines destination after a successful log in -app.get("/home", getHome); +app.get("/home", (req, res) => { + // if user is not logged in, redirect to log in page + if (!req.user) { + res.redirect("/login"); + return; + } + // otherwise, connect them to Dash + // TODO: store and manage users' workspaces + res.sendFile(path.join(__dirname, '../../deploy/index.html')); +}); // anyone attempting to navigate to localhost at this port will // first have to login diff --git a/views/login.pug b/views/login.pug index fb97d3171..c379a6605 100644 --- a/views/login.pug +++ b/views/login.pug @@ -6,9 +6,11 @@ block content include ./stylesheets/authentication.css form.form-horizontal(id='login-form', method='POST') input(type='hidden', name='_csrf', value=_csrf) - .overlay - .inner - h3(id='login_label') Log In + .overlay(id='overlay_login') + a(href="/signup") + img(id='new_user', src="https://bit.ly/2EuqPb4", alt="") + .inner.login + h3.auth_header Log In .form-group //- label.col-sm-3.control-label(for='email', id='email_label') Email .col-sm-7 diff --git a/views/resources/dashlogo.png b/views/resources/dashlogo.png new file mode 100644 index 000000000..3ba4e111b Binary files /dev/null and b/views/resources/dashlogo.png differ diff --git a/views/signup.pug b/views/signup.pug index a23f334af..8b5358137 100644 --- a/views/signup.pug +++ b/views/signup.pug @@ -2,24 +2,25 @@ extends ./layout block content - .page-header - h3 Sign up - form.form-horizontal(id='signup-form', method='POST') - input(type='hidden', name='_csrf', value=_csrf) - .form-group - label.col-sm-3.control-label(for='email') Email - .col-sm-7 - input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required) - .form-group - label.col-sm-3.control-label(for='password') Password - .col-sm-7 - input.form-control(type='password', name='password', id='password', placeholder='Password', required) - .form-group - label.col-sm-3.control-label(for='confirmPassword') Confirm Password - .col-sm-7 - input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password', required) - .form-group - .col-sm-offset-3.col-sm-7 - button.btn.btn-success(type='submit') - i.fa.fa-user-plus - | Signup \ No newline at end of file + style + include ./stylesheets/authentication.css + .page-header + form.form-horizontal(id='signup-form', method='POST') + input(type='hidden', name='_csrf', value=_csrf) + .overlay(id='overlay_signup') + .inner.signup + h3.auth_header Create An Account + .form-group + .col-sm-7 + input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required) + .form-group + .col-sm-7 + input.form-control(type='password', name='password', id='password', placeholder='Password', required) + .form-group + .col-sm-7 + input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password', required) + .form-group + .col-sm-offset-3.col-sm-7 + button.btn.btn-success(type='submit') + i.fa.fa-user-plus + | Signup \ No newline at end of file diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 43f2f228c..4f4c02c03 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -9,14 +9,28 @@ label { } body { - background-color: lightslategray; + background-color: #ccbbcc; } -#login_label { +#logo { + width: 100px; + height: 100px; + position: absolute; +} + +.auth_header { text-align: left; } -#submit { +.login { + height: 220px; +} + +.signup { + height: 273px; +} + +.btn { width: 224px; height: 35px; font-family: Arial, Helvetica, sans-serif; @@ -24,6 +38,22 @@ body { font-style: oblique; } +#overlay_signup { + height: 345px; +} + +#overlay_login { + height: 300px; +} + +#new_user { + width: 20px; + height: 20px; + position: absolute; + top: 15px; + right: 15px; +} + .overlay { text-align: center; position: absolute; @@ -33,7 +63,6 @@ body { left: 0; right: 0; width: 400px; - height: 300px; background-color: white; border-radius: 8px; box-shadow: 10px 10px 10px #00000033; @@ -46,7 +75,6 @@ body { left: 0; right: 0; width: 230px; - height: 220px; margin: auto; } -- cgit v1.2.3-70-g09d2 From cbbeafb8a0c53ddea92684021ead9bc08fa75d37 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 16:03:38 -0500 Subject: ui tweaks --- src/server/authentication/controllers/user.ts | 9 ++++++--- views/signup.pug | 2 ++ views/stylesheets/authentication.css | 6 ++++-- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'views/stylesheets/authentication.css') diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index 554781409..5ff44bda1 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -29,7 +29,8 @@ export let getSignup = (req: Request, res: Response) => { return res.redirect("/home"); } res.render("signup.pug", { - title: "Sign Up" + title: "Sign Up", + errors: req.flash("Unable to facilitate sign up. Please try again.") }); }; @@ -48,8 +49,10 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { const errors = req.validationErrors(); if (errors) { - req.flash("errors", "Unable to facilitate sign up. Please try again."); - console.log(errors.toString()); + res.render("signup.pug", { + title: "Sign Up", + errors: req.flash("Unable to facilitate sign up. Please try again.") + }); return res.redirect("/signup"); } diff --git a/views/signup.pug b/views/signup.pug index 8b5358137..9863b453e 100644 --- a/views/signup.pug +++ b/views/signup.pug @@ -8,6 +8,8 @@ block content form.form-horizontal(id='signup-form', method='POST') input(type='hidden', name='_csrf', value=_csrf) .overlay(id='overlay_signup') + a(href="/login") + img(id='to_login', src="https://bit.ly/2U6ouZk", alt="") .inner.signup h3.auth_header Create An Account .form-group diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 4f4c02c03..30a99563e 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -9,7 +9,8 @@ label { } body { - background-color: #ccbbcc; + /* background-color: #ccbbcc; */ + background-color: #bf0000; } #logo { @@ -46,7 +47,8 @@ body { height: 300px; } -#new_user { +#new_user, +#to_login { width: 20px; height: 20px; position: absolute; -- cgit v1.2.3-70-g09d2 From f4f7354e7096f70b7386f4e7b927fbfb697a08d4 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 16:05:22 -0500 Subject: changed background color --- views/stylesheets/authentication.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'views/stylesheets/authentication.css') diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 30a99563e..e84deb531 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -10,7 +10,7 @@ label { body { /* background-color: #ccbbcc; */ - background-color: #bf0000; + background-color: #251f1f; } #logo { -- cgit v1.2.3-70-g09d2 From 4669fb1df3758c9589e84e32d0c34dc9107457af Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 16:37:29 -0500 Subject: shadow --- views/stylesheets/authentication.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'views/stylesheets/authentication.css') diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index e84deb531..8787d7fa9 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -67,7 +67,7 @@ body { width: 400px; background-color: white; border-radius: 8px; - box-shadow: 10px 10px 10px #00000033; + box-shadow: 10px 10px 10px #00000099; } .inner { -- cgit v1.2.3-70-g09d2 From 686c1717ae193638c89b0b9fce39451d7f6ac2ca Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 16:46:51 -0500 Subject: remove user update and added border --- src/server/authentication/controllers/user.ts | 2 +- views/stylesheets/authentication.css | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'views/stylesheets/authentication.css') diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index 5ff44bda1..2f97f4d53 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -70,7 +70,7 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { if (err) { return next(err); } if (existingUser) { if (existingUser) { - existingUser.update({ $set: { email: please_work } }, (err, res) => { }); + // existingUser.update({ $set: { email: please_work } }, (err, res) => { }); } req.flash("errors", "Account with that email address already exists."); return res.redirect("/signup"); diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 8787d7fa9..d3e1fa20a 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -57,6 +57,7 @@ body { } .overlay { + border: 2px solid yellow; text-align: center; position: absolute; margin: auto; -- cgit v1.2.3-70-g09d2 From 0e46a734bc7159282cb7dfc78447ab3e1c00a4df Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Sun, 24 Feb 2019 19:17:14 -0500 Subject: updated profile --- src/server/authentication/controllers/user.ts | 14 +++----------- src/server/authentication/models/User.ts | 2 ++ views/stylesheets/authentication.css | 3 +++ 3 files changed, 8 insertions(+), 11 deletions(-) (limited to 'views/stylesheets/authentication.css') diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index 2f97f4d53..1ce82a911 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -3,10 +3,7 @@ import { Request, Response, NextFunction } from "express"; import * as passport from "passport"; import { IVerifyOptions } from "passport-local"; import "../config/passport"; -import * as request from "express-validator"; const flash = require("express-flash"); -import * as session from "express-session"; -import * as pug from 'pug'; /** * GET / @@ -25,7 +22,6 @@ export let getEntry = (req: Request, res: Response) => { export let getSignup = (req: Request, res: Response) => { if (req.user) { let user = req.user; - console.log(user); return res.redirect("/home"); } res.render("signup.pug", { @@ -61,11 +57,8 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { const user = new User({ email, - password + password, }); - - const please_work = "cool@gmail.com" - User.findOne({ email }, (err, existingUser) => { if (err) { return next(err); } if (existingUser) { @@ -116,14 +109,13 @@ export let postLogin = (req: Request, res: Response, next: NextFunction) => { if (errors) { req.flash("errors", "Unable to login at this time. Please try again."); - return res.redirect("/login"); + return res.redirect("/signup"); } passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => { if (err) { return next(err); } if (!user) { - req.flash("errors", info.message); - return res.redirect("/login"); + return res.redirect("/signup"); } req.logIn(user, (err) => { if (err) { return next(err); } diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts index 9752c4260..ed2952e48 100644 --- a/src/server/authentication/models/User.ts +++ b/src/server/authentication/models/User.ts @@ -47,6 +47,8 @@ const userSchema = new mongoose.Schema({ passwordResetToken: String, passwordResetExpires: Date, + workspaces: Array, + facebook: String, twitter: String, google: String, diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index d3e1fa20a..232e5a091 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -11,6 +11,9 @@ label { body { /* background-color: #ccbbcc; */ background-color: #251f1f; + /* background-image: url(https://bit.ly/2XibZvI); + background-repeat: no-repeat; + background-size: cover; */ } #logo { -- cgit v1.2.3-70-g09d2 From 6ee6c97b039d373c8580b8a5c90148799fbfd97a Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Mon, 25 Feb 2019 01:22:37 -0500 Subject: password email preliminary pass --- package-lock.json | 77 ++++++++++-------------------------- package.json | 4 +- src/server/index.ts | 61 +++++++++++++++++----------- views/forgot.pug | 22 +++++++++++ views/login.pug | 2 + views/stylesheets/authentication.css | 21 +++++++++- 6 files changed, 105 insertions(+), 82 deletions(-) create mode 100644 views/forgot.pug (limited to 'views/stylesheets/authentication.css') diff --git a/package-lock.json b/package-lock.json index 357728555..ef0ff5eda 100644 --- a/package-lock.json +++ b/package-lock.json @@ -908,7 +908,6 @@ "version": "4.10.1", "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz", "integrity": "sha512-p32cOF5q0Zqs9uBiONKYLm6BClCoBCM5O9JfeUSlnQLBTxYdTK+pW+nXflm8UkKd2UYlEbYz5qEi0JuZR9ckSw==", - "dev": true, "requires": { "bn.js": "^4.0.0", "inherits": "^2.0.1", @@ -1216,8 +1215,7 @@ "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", - "dev": true + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" }, "body-parser": { "version": "1.18.3", @@ -1363,8 +1361,7 @@ "brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", - "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", - "dev": true + "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" }, "browser-stdout": { "version": "1.3.1", @@ -1376,7 +1373,6 @@ "version": "1.2.0", "resolved": "http://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", - "dev": true, "requires": { "buffer-xor": "^1.0.3", "cipher-base": "^1.0.0", @@ -1390,7 +1386,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/browserify-cipher/-/browserify-cipher-1.0.1.tgz", "integrity": "sha512-sPhkz0ARKbf4rRQt2hTpAHqn47X3llLkUGn+xEJzLjwY8LRs2p0v7ljvI5EyoRO/mexrNunNECisZs+gw2zz1w==", - "dev": true, "requires": { "browserify-aes": "^1.0.4", "browserify-des": "^1.0.0", @@ -1401,7 +1396,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/browserify-des/-/browserify-des-1.0.2.tgz", "integrity": "sha512-BioO1xf3hFwz4kc6iBhI3ieDFompMhrMlnDFC4/0/vd5MokpuAc3R+LYbwTA9A5Yc9pq9UYPqffKpW2ObuwX5A==", - "dev": true, "requires": { "cipher-base": "^1.0.1", "des.js": "^1.0.0", @@ -1413,7 +1407,6 @@ "version": "4.0.1", "resolved": "http://registry.npmjs.org/browserify-rsa/-/browserify-rsa-4.0.1.tgz", "integrity": "sha1-IeCr+vbyApzy+vsTNWenAdQTVSQ=", - "dev": true, "requires": { "bn.js": "^4.1.0", "randombytes": "^2.0.1" @@ -1423,7 +1416,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/browserify-sign/-/browserify-sign-4.0.4.tgz", "integrity": "sha1-qk62jl17ZYuqa/alfmMMvXqT0pg=", - "dev": true, "requires": { "bn.js": "^4.1.1", "browserify-rsa": "^4.0.0", @@ -1484,8 +1476,7 @@ "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", - "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", - "dev": true + "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" }, "builtin-modules": { "version": "1.1.1", @@ -1671,7 +1662,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -2076,7 +2066,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.3.tgz", "integrity": "sha512-GbEHQPMOswGpKXM9kCWVrremUcBmjteUaQ01T9rkKCPDXfUHX0IoP9LpHYo2NPFampa4e+/pFDc3jQdxrxQLaw==", - "dev": true, "requires": { "bn.js": "^4.1.0", "elliptic": "^6.0.0" @@ -2094,7 +2083,6 @@ "version": "1.2.0", "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "dev": true, "requires": { "cipher-base": "^1.0.1", "inherits": "^2.0.1", @@ -2107,7 +2095,6 @@ "version": "1.1.7", "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "dev": true, "requires": { "cipher-base": "^1.0.3", "create-hash": "^1.1.0", @@ -2127,10 +2114,9 @@ } }, "crypto-browserify": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", - "integrity": "sha512-fz4spIh+znjO2VjL+IdhEpRJ3YN6sMzITSBijk6FK2UvTqruSQW+/cCZTSNsMiZNvUeq0CqurF+dAbyiGOY6Wg==", - "dev": true, + "version": "3.11.0", + "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.11.0.tgz", + "integrity": "sha1-NlKgkGq5sqfgw85mpAjpV6JIVSI=", "requires": { "browserify-cipher": "^1.0.0", "browserify-sign": "^4.0.0", @@ -2141,8 +2127,7 @@ "inherits": "^2.0.1", "pbkdf2": "^3.0.3", "public-encrypt": "^4.0.0", - "randombytes": "^2.0.0", - "randomfill": "^1.0.3" + "randombytes": "^2.0.0" } }, "crypto-random-string": { @@ -2424,7 +2409,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.0.tgz", "integrity": "sha1-wHTS4qpqipoH29YfmhXCzYPsjsw=", - "dev": true, "requires": { "inherits": "^2.0.1", "minimalistic-assert": "^1.0.0" @@ -2466,7 +2450,6 @@ "version": "5.0.3", "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz", "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==", - "dev": true, "requires": { "bn.js": "^4.1.0", "miller-rabin": "^4.0.0", @@ -2586,7 +2569,6 @@ "version": "6.4.1", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", "integrity": "sha512-BsXLz5sqX8OHcsh7CqBMztyXARmGQ3LWPtGjJi6DiJHq5C/qvi9P3OqgswKSDftbu8+IoI/QDTAm2fFnQ9SZSQ==", - "dev": true, "requires": { "bn.js": "^4.4.0", "brorand": "^1.0.1", @@ -2827,7 +2809,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", - "dev": true, "requires": { "md5.js": "^1.3.4", "safe-buffer": "^5.1.1" @@ -4150,7 +4131,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", - "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -4160,7 +4140,6 @@ "version": "1.1.7", "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.7.tgz", "integrity": "sha512-taOaskGt4z4SOANNseOviYDvjEJinIkRgmp7LbKP2YTTmVxWBl87s/uzK9r+44BclBSp2X7K1hqeNfz9JbBeXA==", - "dev": true, "requires": { "inherits": "^2.0.3", "minimalistic-assert": "^1.0.1" @@ -4176,7 +4155,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", - "dev": true, "requires": { "hash.js": "^1.0.3", "minimalistic-assert": "^1.0.0", @@ -5246,7 +5224,6 @@ "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1", @@ -5336,7 +5313,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/miller-rabin/-/miller-rabin-4.0.1.tgz", "integrity": "sha512-115fLhvZVqWwHPbClyntxEVfVDfl9DLLTuJvq3g2O/Oxi8AiNouAHvDSzHS0viUJc+V5vm3eq91Xwqn9dp4jRA==", - "dev": true, "requires": { "bn.js": "^4.0.0", "brorand": "^1.0.1" @@ -5369,14 +5345,12 @@ "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", - "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", - "dev": true + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" }, "minimalistic-crypto-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", - "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", - "dev": true + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" }, "minimatch": { "version": "3.0.4", @@ -9622,10 +9596,9 @@ } }, "parse-asn1": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.3.tgz", - "integrity": "sha512-VrPoetlz7B/FqjBLD2f5wBVZvsZVLnRUrxVLfRYhGXCODa/NWE4p3Wp+6+aV3ZPL3KM7/OZmxDIwwijD7yuucg==", - "dev": true, + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.4.tgz", + "integrity": "sha512-Qs5duJcuvNExRfFZ99HDD3z4mAi3r9Wl/FOjEOijlxwCZs7E7mW2vjTpgQ4J8LpTF8x5v+1Vn5UQFejmWT11aw==", "requires": { "asn1.js": "^4.0.0", "browserify-aes": "^1.0.0", @@ -9766,7 +9739,6 @@ "version": "3.0.17", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==", - "dev": true, "requires": { "create-hash": "^1.1.2", "create-hmac": "^1.1.4", @@ -10097,7 +10069,6 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/public-encrypt/-/public-encrypt-4.0.3.tgz", "integrity": "sha512-zVpa8oKZSz5bTMTFClc1fQOnyyEzpl5ozpi1B5YcvBrdohMjH2rfsBtyXcuNuwjsDIXmBYlF2N5FlJYhR29t8Q==", - "dev": true, "requires": { "bn.js": "^4.1.0", "browserify-rsa": "^4.0.0", @@ -10281,21 +10252,10 @@ "integrity": "sha1-T2ih3Arli9P7lYSMMDJNt11kNgs=" }, "randombytes": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", - "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", - "dev": true, - "requires": { - "safe-buffer": "^5.1.0" - } - }, - "randomfill": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/randomfill/-/randomfill-1.0.4.tgz", - "integrity": "sha512-87lcbR8+MhcWcUiQ+9e+Rwx8MyR2P7qnt15ynUlbm3TU/fjbgz4GsvfSUDTemtCCtVCqb4ZcEFlyPNTh9bBTLw==", - "dev": true, + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "requires": { - "randombytes": "^2.0.5", "safe-buffer": "^5.1.0" } }, @@ -10722,7 +10682,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1" @@ -10964,7 +10923,6 @@ "version": "2.4.11", "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", - "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -13245,6 +13203,11 @@ "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz", "integrity": "sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=" }, + "xoauth2": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/xoauth2/-/xoauth2-1.2.0.tgz", + "integrity": "sha1-8u76wRRyyXHqO8RuVU60sSMhRuU=" + }, "xregexp": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.0.0.tgz", diff --git a/package.json b/package.json index 4371df90d..931b5ac56 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "connect-flash": "^0.1.1", "connect-mongo": "^2.0.3", "cookie-parser": "^1.4.4", + "crypto-browserify": "^3.11.0", "express": "^4.16.4", "express-flash": "0.0.2", "express-session": "^1.15.6", @@ -116,6 +117,7 @@ "socket.io": "^2.2.0", "socket.io-client": "^2.2.0", "url-loader": "^1.1.2", - "uuid": "^3.3.2" + "uuid": "^3.3.2", + "xoauth2": "^1.2.0" } } diff --git a/src/server/index.ts b/src/server/index.ts index 039d7f56a..9480eaacb 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -36,16 +36,10 @@ 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'; +import User, { UserModel } from './authentication/models/User'; const mongoUrl = 'mongodb://localhost:27017/Dash'; -// mongoose.Promise = bluebird; -mongoose.connect(mongoUrl)//.then( -// () => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ }, -// ).catch((err: any) => { -// console.log("MongoDB connection error. Please make sure MongoDB is running. " + err); -// process.exit(); -// }); +mongoose.connect(mongoUrl) mongoose.connection.on('connected', function () { console.log("connected"); }) @@ -110,38 +104,61 @@ app.get('/logout', getLogout); // *** +app.get('/forgot', function (req, res) { + res.render("forgot.pug", { + title: "Recover Password", + user: req.user, + }); +}) + // 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); + const seed = new Uint32Array(20); + let token = seed; + done(null, token); }, - function (token: Uint16Array, done: any) { - User.findOne({ email }, function (err, user: User) { + function (token: Uint32Array, done: any) { + User.findOne({ email }, function (err, user: UserModel) { if (!user) { // NO ACCOUNT WITH SUBMITTED EMAIL return res.redirect('/forgot'); } - user.resetPasswordToken = token; - user.resetPasswordExpires = Date.now() + 3600000; // 1 HOUR + user.passwordResetToken = token.toString(); + user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR user.save(function (err: any) { - done(err, token, user); + done(null, token, user); }); }); }, - function (token: Uint16Array, user: User, done: any) { - const transport = nodemailer.createTransport('SMTP', { + function (token: Uint16Array, user: UserModel, done: any) { + const smptTransport = nodemailer.createTransport({ + service: 'Gmail', auth: { - user: 'test.nodemailer@gmail.com', - pass: 'placeholder' + user: 'samwilkins333@gmail.com', + pass: 'browngfx1' } }); + const mailOptions = { + to: user.email, + from: 'passwordreset@dash.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' + }; + smptTransport.sendMail(mailOptions, function (err) { + // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); + done(null, err, 'done'); + }); } - ]) + ], function (err) { + if (err) return next(err); + res.redirect('/forgot'); + }) }) let FieldStore: ObservableMap = new ObservableMap(); diff --git a/views/forgot.pug b/views/forgot.pug new file mode 100644 index 000000000..4036b49db --- /dev/null +++ b/views/forgot.pug @@ -0,0 +1,22 @@ + +extends ./layout + +block content + style + include ./stylesheets/authentication.css + form.form-horizontal(id='forgot-form', method='POST') + input(type='hidden', name='_csrf', value=_csrf) + .overlay(id='overlay_forgot') + a(href="/login") + img(id='to_login', src="https://bit.ly/2U6ouZk", alt="") + .inner.forgot + h3.auth_header Recover Password + .form-group + //- label.col-sm-3.control-label(for='email', id='email_label') Email + .col-sm-7 + input.form-control(type='email', name='email', id='email', placeholder='Email', autofocus, required) + .form-group + .col-sm-offset-3.col-sm-7 + button.btn.btn-success(id='submit', type='submit') + i.fa.fa-user-plus + | Submit \ No newline at end of file diff --git a/views/login.pug b/views/login.pug index c379a6605..9bc40a495 100644 --- a/views/login.pug +++ b/views/login.pug @@ -9,6 +9,8 @@ block content .overlay(id='overlay_login') a(href="/signup") img(id='new_user', src="https://bit.ly/2EuqPb4", alt="") + a(href="/forgot") + img(id='forgot', src="https://bit.ly/2XjHpSo", alt="") .inner.login h3.auth_header Log In .form-group diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 232e5a091..0922ad730 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -30,6 +30,10 @@ body { height: 220px; } +.forgot { + height: 175px; +} + .signup { height: 273px; } @@ -50,13 +54,26 @@ body { height: 300px; } +#overlay_forgot { + height: 250px; +} + #new_user, #to_login { + right: 15px; +} + +#new_user, +#to_login, +#forgot { + top: 15px; width: 20px; height: 20px; position: absolute; - top: 15px; - right: 15px; +} + +#forgot { + left: 15px; } .overlay { -- cgit v1.2.3-70-g09d2 From 0d36924c90682c57e96c1e7bfd95a3cc10e6c662 Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Mon, 25 Feb 2019 03:38:02 -0500 Subject: after pop, hard reset --- src/client/views/Main.tsx | 6 ++ src/server/authentication/controllers/user.ts | 135 +++++++++++++++++++++++++- src/server/authentication/models/User.ts | 4 +- src/server/index.ts | 68 ++----------- views/reset.pug | 22 +++++ views/signup.pug | 2 +- views/stylesheets/authentication.css | 6 +- 7 files changed, 176 insertions(+), 67 deletions(-) create mode 100644 views/reset.pug (limited to 'views/stylesheets/authentication.css') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index cbc19d7fe..567f17752 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -171,6 +171,12 @@ function init() { right: '0px', width: '150px' }} onClick={() => UndoManager.Redo()}>Redo +
), document.getElementById('root')); }) diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts index a496959d1..19cd09676 100644 --- a/src/server/authentication/controllers/user.ts +++ b/src/server/authentication/controllers/user.ts @@ -7,6 +7,10 @@ import * as request from "express-validator"; const flash = require("express-flash"); import * as session from "express-session"; import * as pug from 'pug'; +import * as async from 'async'; +import * as nodemailer from 'nodemailer'; +import c = require("crypto"); + /** * GET / @@ -46,8 +50,6 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); - req.flash("Working on something!!!"); - const errors = req.validationErrors(); if (errors) { @@ -146,4 +148,133 @@ export let getLogout = (req: Request, res: Response) => { sess.destroy((err) => { if (err) { console.log(err); } }); } res.redirect('/login'); +} + +export let getForgot = function (req: Request, res: Response) { + res.render("forgot.pug", { + title: "Recover Password", + user: req.user, + }); +} + +export let postForgot = function (req: Request, res: Response, next: NextFunction) { + const email = req.body.email; + async.waterfall([ + function (done: any) { + let token: string; + c.randomBytes(20, function (err: any, buffer: Buffer) { + if (err) { + done(null); + return; + } + done(null, buffer.toString('hex')); + }) + }, + function (token: Buffer, done: any) { + User.findOne({ email }, function (err, user: UserModel) { + if (!user) { + // NO ACCOUNT WITH SUBMITTED EMAIL + return res.redirect('/forgot'); + } + user.passwordResetToken = token.toString('utf8'); + console.log(user.passwordResetToken); + user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR + user.save(function (err: any) { + done(null, token, user); + }); + }); + }, + function (token: Uint16Array, user: UserModel, done: any) { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + 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) { + // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); + done(null, err, 'done'); + }); + } + ], function (err) { + if (err) return next(err); + res.redirect('/forgot'); + }) +} + +export let getReset = function (req: Request, res: Response) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { + if (!user || err) { + return res.redirect('/forgot'); + } + res.render("reset.pug", { + title: "Reset Password", + user: req.user, + }); + }); +} + +export let postReset = function (req: Request, res: Response) { + async.waterfall([ + function (done: any) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { + if (!user || err) { + return res.redirect('back'); + } + + req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); + req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); + + if (req.validationErrors()) { + return res.redirect('back'); + } + + user.password = req.body.password; + user.passwordResetToken = undefined; + user.passwordResetExpires = undefined; + + user.save(function (err) { + req.logIn(user, function (err) { + if (err) { + console.log(err); + return; + } + }); + done(user, err); + }); + }); + }, + function (user: UserModel, done: any) { + console.log(`SENDING EMAIL TO ${user.email}`); + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + 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' + }; + smtpTransport.sendMail(mailOptions, function (err) { + done(null, err); + }); + } + ], function (err) { + res.redirect('/login'); + }); } \ No newline at end of file diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts index 30fcecd81..433e2f6c3 100644 --- a/src/server/authentication/models/User.ts +++ b/src/server/authentication/models/User.ts @@ -18,8 +18,8 @@ mongoose.connection.on('disconnected', function () { export type UserModel = mongoose.Document & { email: string, password: string, - passwordResetToken: string, - passwordResetExpires: Date, + passwordResetToken: string | undefined, + passwordResetExpires: Date | undefined, tokens: AuthToken[], profile: { diff --git a/src/server/index.ts b/src/server/index.ts index baf360ffa..f2b26afec 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -17,7 +17,7 @@ import * as bcrypt from "bcrypt-nodejs"; import { Document } from '../fields/Document'; import * as io from 'socket.io' import * as passportConfig from './authentication/config/passport'; -import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry } from './authentication/controllers/user'; +import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, postReset, getForgot, postForgot, getReset } from './authentication/controllers/user'; const config = require('../../webpack.config'); const compiler = webpack(config); const port = 1050; // default port to listen @@ -28,11 +28,9 @@ 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' @@ -88,7 +86,6 @@ app.get("/home", (req, res) => { }); app.get("/getUserDocId", (req, res) => { - console.log(req.user) if (!req.user) { return; } @@ -119,64 +116,15 @@ app.get('/logout', getLogout); // *** -app.get('/forgot', function (req, res) { - res.render("forgot.pug", { - title: "Recover Password", - user: req.user, - }); -}) - // FORGOT PASSWORD EMAIL HANDLING -app.post('/forgot', function (req, res, next) { - const email = req.body.email; - async.waterfall([ - function (done: any) { - const seed = new Uint32Array(20); - let token = seed; - done(null, token); - }, - function (token: Uint32Array, done: any) { - User.findOne({ email }, function (err, user: UserModel) { - if (!user) { - // NO ACCOUNT WITH SUBMITTED EMAIL - return res.redirect('/forgot'); - } - user.passwordResetToken = token.toString(); - user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR - user.save(function (err: any) { - done(null, token, user); - }); - }); - }, - function (token: Uint16Array, user: UserModel, done: any) { - const smptTransport = nodemailer.createTransport({ - service: 'Gmail', - auth: { - user: 'brownptcdash@gmail.com', - pass: 'browngfx1' - } - }); - const mailOptions = { - to: user.email, - 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' - }; - smptTransport.sendMail(mailOptions, function (err) { - // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); - done(null, err, 'done'); - }); - } - ], function (err) { - if (err) return next(err); - res.redirect('/forgot'); - }) -}) -let FieldStore: ObservableMap = new ObservableMap(); +app.get('/forgot', getForgot) +app.post('/forgot', postForgot) +// RESET PASSWORD EMAIL HANDLING +app.get('/reset/:token', getReset); +app.post('/reset/:token', postReset); + +let FieldStore: ObservableMap = new ObservableMap(); app.get("/hello", (req, res) => { res.send("

Hello

"); }) diff --git a/views/reset.pug b/views/reset.pug new file mode 100644 index 000000000..8b6fa952b --- /dev/null +++ b/views/reset.pug @@ -0,0 +1,22 @@ + +extends ./layout + +block content + style + include ./stylesheets/authentication.css + form.form-horizontal(id='reset-form', method='POST') + input(type='hidden', name='_csrf', value=_csrf) + .overlay(id='overlay_reset') + .inner.reset + h3.auth_header Reset Password + .form-group + .col-sm-7 + input.form-control(type='password', name='password', id='password', placeholder='Password', required) + .form-group + .col-sm-7 + input.form-control(type='password', name='confirmPassword', id='confirmPassword', placeholder='Confirm Password', required) + .form-group + .col-sm-offset-3.col-sm-7 + button.btn.btn-success(type='submit') + i.fa.fa-user-plus + | Reset \ No newline at end of file diff --git a/views/signup.pug b/views/signup.pug index 374710e6f..11b02a5eb 100644 --- a/views/signup.pug +++ b/views/signup.pug @@ -24,4 +24,4 @@ block content .col-sm-offset-3.col-sm-7 button.btn.btn-success(type='submit') i.fa.fa-user-plus - | Signup \ No newline at end of file + | Sign Up \ No newline at end of file diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index 0922ad730..bce8223ec 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -26,7 +26,8 @@ body { text-align: left; } -.login { +.login, +.reset { height: 220px; } @@ -46,7 +47,8 @@ body { font-style: oblique; } -#overlay_signup { +#overlay_signup, +#overlay_reset { height: 345px; } -- cgit v1.2.3-70-g09d2 From 042eb977ad7733919daf468001b17dbee4e1fa9f Mon Sep 17 00:00:00 2001 From: Sam Wilkins Date: Tue, 26 Feb 2019 18:58:07 -0500 Subject: beginning multiple workspaces backend and ui --- src/client/views/Main.tsx | 13 +- src/server/authentication/config/passport.ts | 2 +- src/server/authentication/controllers/user.ts | 279 -------------------- .../authentication/controllers/user_controller.ts | 291 +++++++++++++++++++++ src/server/authentication/models/User.ts | 90 ------- src/server/authentication/models/user_model.ts | 100 +++++++ src/server/index.ts | 43 ++- views/stylesheets/authentication.css | 29 +- views/workspace.pug | 13 + 9 files changed, 475 insertions(+), 385 deletions(-) delete mode 100644 src/server/authentication/controllers/user.ts create mode 100644 src/server/authentication/controllers/user_controller.ts delete mode 100644 src/server/authentication/models/User.ts create mode 100644 src/server/authentication/models/user_model.ts create mode 100644 views/workspace.pug (limited to 'views/stylesheets/authentication.css') diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 567f17752..e66816b6b 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -37,18 +37,25 @@ document.addEventListener("pointerdown", action(function (e: PointerEvent) { }), true) let mainDocId: string; -request.get(window.location.origin + "/getUserDocId", (error, response, body) => { +request.get(window.location.origin + "/getActiveWorkspaceId", (error, response, body) => { + const here = window.location.origin; if (body) { mainDocId = body; } else { mainDocId = Utils.GenerateGuid(); - request.post(window.location.origin + "/setUserDocId", { + request.post(here + "/addWorkspaceId", { body: { - userDocumentId: mainDocId + target: mainDocId }, json: true }) } + request.post(here + "/setActiveWorkspaceId", { + body: { + target: mainDocId + }, + json: true + }) init(); }) diff --git a/src/server/authentication/config/passport.ts b/src/server/authentication/config/passport.ts index 9f1303135..d90bedb18 100644 --- a/src/server/authentication/config/passport.ts +++ b/src/server/authentication/config/passport.ts @@ -2,7 +2,7 @@ import * as passport from 'passport' import * as passportLocal from 'passport-local'; import * as mongodb from 'mongodb'; import * as _ from "lodash"; -import { default as User } from '../models/User'; +import { default as User } from '../models/user_model'; import { Request, Response, NextFunction } from "express"; const LocalStrategy = passportLocal.Strategy; diff --git a/src/server/authentication/controllers/user.ts b/src/server/authentication/controllers/user.ts deleted file mode 100644 index 6c4139b2e..000000000 --- a/src/server/authentication/controllers/user.ts +++ /dev/null @@ -1,279 +0,0 @@ -import { default as User, UserModel, AuthToken } from "../models/User"; -import { Request, Response, NextFunction } from "express"; -import * as passport from "passport"; -import { IVerifyOptions } from "passport-local"; -import "../config/passport"; -import * as request from "express-validator"; -const flash = require("express-flash"); -import * as session from "express-session"; -import * as pug from 'pug'; -import * as async from 'async'; -import * as nodemailer from 'nodemailer'; -import c = require("crypto"); - - -/** - * 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"); -} - -/** - * GET /signup - * Directs user to the signup page - * modeled by signup.pug in views - */ -export let getSignup = (req: Request, res: Response) => { - if (req.user) { - let user = req.user; - return res.redirect("/home"); - } - res.render("signup.pug", { - title: "Sign Up", - user: req.user, - }); -}; - -/** - * POST /signup - * Create a new local account. - */ -export let postSignup = (req: Request, res: Response, next: NextFunction) => { - req.assert("email", "Email is not valid").isEmail(); - req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); - req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); - req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); - - const errors = req.validationErrors(); - - if (errors) { - res.render("signup.pug", { - title: "Sign Up", - user: req.user, - }); - return res.redirect("/signup"); - } - - const email = req.body.email; - const password = req.body.password; - - const user = new User({ - email, - password, - userDoc: "document here" - }); - - User.findOne({ email }, (err, existingUser) => { - if (err) { return next(err); } - if (existingUser) { - if (existingUser) { - // existingUser.update({ $set: { email: please_work } }, (err, res) => { }); - } - req.flash("errors", "Account with that email address already exists."); - return res.redirect("/signup"); - } - user.save((err) => { - if (err) { return next(err); } - req.logIn(user, (err) => { - if (err) { - return next(err); - } - res.redirect("/"); - }); - }); - }); - -}; - - -/** - * GET /login - * Login page. - */ -export let getLogin = (req: Request, res: Response) => { - if (req.user) { - return res.redirect("/home"); - } - res.render("login.pug", { - title: "Log In", - user: req.user - }); -}; - -/** - * POST /login - * Sign in using email and password. - * On failure, redirect to login page - */ -export let postLogin = (req: Request, res: Response, next: NextFunction) => { - req.assert("email", "Email is not valid").isEmail(); - req.assert("password", "Password cannot be blank").notEmpty(); - req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); - - const errors = req.validationErrors(); - - if (errors) { - req.flash("errors", "Unable to login at this time. Please try again."); - return res.redirect("/signup"); - } - - passport.authenticate("local", (err: Error, user: UserModel, info: IVerifyOptions) => { - if (err) { return next(err); } - if (!user) { - return res.redirect("/signup"); - } - req.logIn(user, (err) => { - if (err) { return next(err); } - req.flash("success", "Success! You are logged in."); - res.redirect("/home"); - }); - })(req, res, next); -}; - -/** - * GET /logout - * Invokes the logout function on the request - * and destroys the user's current session. - */ -export let getLogout = (req: Request, res: Response) => { - req.logout(); - const sess = req.session; - if (sess) { - sess.destroy((err) => { if (err) { console.log(err); } }); - } - res.redirect('/login'); -} - -export let getForgot = function (req: Request, res: Response) { - res.render("forgot.pug", { - title: "Recover Password", - user: req.user, - }); -} - -export let postForgot = function (req: Request, res: Response, next: NextFunction) { - const email = req.body.email; - async.waterfall([ - function (done: any) { - let token: string; - c.randomBytes(20, function (err: any, buffer: Buffer) { - if (err) { - done(null); - return; - } - done(null, buffer.toString('hex')); - }) - }, - function (token: string, done: any) { - User.findOne({ email }, function (err, user: UserModel) { - if (!user) { - // NO ACCOUNT WITH SUBMITTED EMAIL - return res.redirect('/forgot'); - } - user.passwordResetToken = token; - user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR - user.save(function (err: any) { - done(null, token, user); - }); - }); - }, - function (token: Uint16Array, user: UserModel, done: any) { - const smtpTransport = nodemailer.createTransport({ - service: 'Gmail', - auth: { - user: 'brownptcdash@gmail.com', - pass: 'browngfx1' - } - }); - const mailOptions = { - to: user.email, - 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) { - // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); - done(null, err, 'done'); - }); - } - ], function (err) { - if (err) return next(err); - res.redirect('/forgot'); - }) -} - -export let getReset = function (req: Request, res: Response) { - User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { - if (!user || err) { - return res.redirect('/forgot'); - } - res.render("reset.pug", { - title: "Reset Password", - user: req.user, - }); - }); -} - -export let postReset = function (req: Request, res: Response) { - async.waterfall([ - function (done: any) { - User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: UserModel) { - if (!user || err) { - return res.redirect('back'); - } - - req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); - req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); - - if (req.validationErrors()) { - return res.redirect('back'); - } - - user.password = req.body.password; - user.passwordResetToken = undefined; - user.passwordResetExpires = undefined; - - user.save(function (err) { - if (err) { - return res.redirect("/login"); - } - req.logIn(user, function (err) { - if (err) { - return; - } - }); - done(null, user); - }); - }); - }, - function (user: UserModel, done: any) { - const smtpTransport = nodemailer.createTransport({ - service: 'Gmail', - auth: { - user: 'brownptcdash@gmail.com', - pass: 'browngfx1' - } - }); - const mailOptions = { - to: user.email, - 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' - }; - smtpTransport.sendMail(mailOptions, function (err) { - done(null, err); - }); - } - ], function (err) { - res.redirect('/login'); - }); -} \ No newline at end of file diff --git a/src/server/authentication/controllers/user_controller.ts b/src/server/authentication/controllers/user_controller.ts new file mode 100644 index 000000000..899912ab7 --- /dev/null +++ b/src/server/authentication/controllers/user_controller.ts @@ -0,0 +1,291 @@ +import { default as User, DashUserModel, AuthToken } from "../models/user_model"; +import { Request, Response, NextFunction } from "express"; +import * as passport from "passport"; +import { IVerifyOptions } from "passport-local"; +import "../config/passport"; +import * as request from "express-validator"; +const flash = require("express-flash"); +import * as session from "express-session"; +import * as pug from 'pug'; +import * as async from 'async'; +import * as nodemailer from 'nodemailer'; +import c = require("crypto"); + + +/** + * 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"); +} + +/** + * GET /signup + * Directs user to the signup page + * modeled by signup.pug in views + */ +export let getSignup = (req: Request, res: Response) => { + if (req.user) { + let user = req.user; + return res.redirect("/home"); + } + res.render("signup.pug", { + title: "Sign Up", + user: req.user, + }); +}; + +/** + * POST /signup + * Create a new local account. + */ +export let postSignup = (req: Request, res: Response, next: NextFunction) => { + req.assert("email", "Email is not valid").isEmail(); + req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); + req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); + req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); + + const errors = req.validationErrors(); + + if (errors) { + res.render("signup.pug", { + title: "Sign Up", + user: req.user, + }); + return res.redirect("/signup"); + } + + const email = req.body.email; + const password = req.body.password; + + const user = new User({ + email, + password, + userDoc: "document here" + }); + + User.findOne({ email }, (err, existingUser) => { + if (err) { return next(err); } + if (existingUser) { + return res.redirect("/login"); + } + user.save((err) => { + if (err) { return next(err); } + req.logIn(user, (err) => { + if (err) { + return next(err); + } + res.redirect("/home"); + }); + }); + }); + +}; + + +/** + * GET /login + * Login page. + */ +export let getLogin = (req: Request, res: Response) => { + if (req.user) { + return res.redirect("/home"); + } + res.render("login.pug", { + title: "Log In", + user: req.user + }); +}; + +/** + * POST /login + * Sign in using email and password. + * On failure, redirect to login page + */ +export let postLogin = (req: Request, res: Response, next: NextFunction) => { + req.assert("email", "Email is not valid").isEmail(); + req.assert("password", "Password cannot be blank").notEmpty(); + req.sanitize("email").normalizeEmail({ gmail_remove_dots: false }); + + const errors = req.validationErrors(); + + if (errors) { + req.flash("errors", "Unable to login at this time. Please try again."); + return res.redirect("/signup"); + } + + passport.authenticate("local", (err: Error, user: DashUserModel, info: IVerifyOptions) => { + if (err) { return next(err); } + if (!user) { + return res.redirect("/signup"); + } + req.logIn(user, (err) => { + if (err) { return next(err); } + res.redirect("/home"); + }); + })(req, res, next); +}; + +export let getWorkspaces = (req: Request, res: Response) => { + const user: DashUserModel = req.user; + if (!user) { + return res.redirect("/login"); + } + res.render("workspace.pug", { + ids: user.allWorkspaceIds + }); +} + +/** + * GET /logout + * Invokes the logout function on the request + * and destroys the user's current session. + */ +export let getLogout = (req: Request, res: Response) => { + const dashUser: DashUserModel | undefined = req.user; + if (dashUser) { + dashUser.update({ $set: { didSelectSessionWorkspace: false } }, () => { }) + console.log("UPDATED :)"); + } else { + console.log("NO USER BY LOGOUT"); + } + req.logout(); + const sess = req.session; + if (sess) { + sess.destroy((err) => { if (err) { console.log(err); } }); + } + res.redirect('/login'); +} + +export let getForgot = function (req: Request, res: Response) { + res.render("forgot.pug", { + title: "Recover Password", + user: req.user, + }); +} + +export let postForgot = function (req: Request, res: Response, next: NextFunction) { + const email = req.body.email; + async.waterfall([ + function (done: any) { + let token: string; + c.randomBytes(20, function (err: any, buffer: Buffer) { + if (err) { + done(null); + return; + } + done(null, buffer.toString('hex')); + }) + }, + function (token: string, done: any) { + User.findOne({ email }, function (err, user: DashUserModel) { + if (!user) { + // NO ACCOUNT WITH SUBMITTED EMAIL + return res.redirect('/forgot'); + } + user.passwordResetToken = token; + user.passwordResetExpires = new Date(Date.now() + 3600000); // 1 HOUR + user.save(function (err: any) { + done(null, token, user); + }); + }); + }, + function (token: Uint16Array, user: DashUserModel, done: any) { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + 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) { + // req.flash('info', 'An e-mail has been sent to ' + user.email + ' with further instructions.'); + done(null, err, 'done'); + }); + } + ], function (err) { + if (err) return next(err); + res.redirect('/forgot'); + }) +} + +export let getReset = function (req: Request, res: Response) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: DashUserModel) { + if (!user || err) { + return res.redirect('/forgot'); + } + res.render("reset.pug", { + title: "Reset Password", + user: req.user, + }); + }); +} + +export let postReset = function (req: Request, res: Response) { + async.waterfall([ + function (done: any) { + User.findOne({ passwordResetToken: req.params.token, passwordResetExpires: { $gt: Date.now() } }, function (err, user: DashUserModel) { + if (!user || err) { + return res.redirect('back'); + } + + req.assert("password", "Password must be at least 4 characters long").len({ min: 4 }); + req.assert("confirmPassword", "Passwords do not match").equals(req.body.password); + + if (req.validationErrors()) { + return res.redirect('back'); + } + + user.password = req.body.password; + user.passwordResetToken = undefined; + user.passwordResetExpires = undefined; + + user.save(function (err) { + if (err) { + return res.redirect("/login"); + } + req.logIn(user, function (err) { + if (err) { + return; + } + }); + done(null, user); + }); + }); + }, + function (user: DashUserModel, done: any) { + const smtpTransport = nodemailer.createTransport({ + service: 'Gmail', + auth: { + user: 'brownptcdash@gmail.com', + pass: 'browngfx1' + } + }); + const mailOptions = { + to: user.email, + 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' + }; + smtpTransport.sendMail(mailOptions, function (err) { + done(null, err); + }); + } + ], function (err) { + res.redirect('/login'); + }); +} \ No newline at end of file diff --git a/src/server/authentication/models/User.ts b/src/server/authentication/models/User.ts deleted file mode 100644 index 433e2f6c3..000000000 --- a/src/server/authentication/models/User.ts +++ /dev/null @@ -1,90 +0,0 @@ -//@ts-ignore -import * as bcrypt from "bcrypt-nodejs"; -//@ts-ignore -import * as mongoose from "mongoose"; -var url = 'mongodb://localhost:27017/Dash' - -mongoose.connect(url, { useNewUrlParser: true }); - -mongoose.connection.on('connected', function () { - console.log('Stablished connection on ' + url); -}); -mongoose.connection.on('error', function (error) { - console.log('Something wrong happened: ' + error); -}); -mongoose.connection.on('disconnected', function () { - console.log('connection closed'); -}); -export type UserModel = mongoose.Document & { - email: string, - password: string, - passwordResetToken: string | undefined, - passwordResetExpires: Date | undefined, - tokens: AuthToken[], - - profile: { - name: string, - gender: string, - location: string, - website: string, - picture: string - }, - - comparePassword: comparePasswordFunction, -}; - -type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; - -export type AuthToken = { - accessToken: string, - kind: string -}; - -const userSchema = new mongoose.Schema({ - email: { type: String, unique: true }, - password: String, - passwordResetToken: String, - passwordResetExpires: Date, - - userDocumentId: String, - - facebook: String, - twitter: String, - google: String, - tokens: Array, - - profile: { - name: String, - gender: String, - location: String, - website: String, - picture: String - } -}, { timestamps: true }); - -/** - * Password hash middleware. - */ -userSchema.pre("save", function save(next) { - const user = this as UserModel; - if (!user.isModified("password")) { return next(); } - bcrypt.genSalt(10, (err, salt) => { - if (err) { return next(err); } - bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => { - if (err) { return next(err); } - user.password = hash; - next(); - }); - }); -}); - -const comparePassword: comparePasswordFunction = function (this: UserModel, candidatePassword, cb) { - bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => { - cb(err, isMatch); - }); -}; - -userSchema.methods.comparePassword = comparePassword; - -const User = mongoose.model("User", userSchema); -export default User; \ No newline at end of file diff --git a/src/server/authentication/models/user_model.ts b/src/server/authentication/models/user_model.ts new file mode 100644 index 000000000..dfd104ef8 --- /dev/null +++ b/src/server/authentication/models/user_model.ts @@ -0,0 +1,100 @@ +//@ts-ignore +import * as bcrypt from "bcrypt-nodejs"; +//@ts-ignore +import * as mongoose from "mongoose"; +var url = 'mongodb://localhost:27017/Dash' + +mongoose.connect(url, { useNewUrlParser: true }); + +mongoose.connection.on('connected', function () { + console.log('Stablished connection on ' + url); +}); +mongoose.connection.on('error', function (error) { + console.log('Something wrong happened: ' + error); +}); +mongoose.connection.on('disconnected', function () { + console.log('connection closed'); +}); +export type DashUserModel = mongoose.Document & { + email: string, + password: string, + passwordResetToken: string | undefined, + passwordResetExpires: Date | undefined, + + allWorkspaceIds: Array, + activeWorkspaceId: String, + didSelectSessionWorkspace: Boolean, + + profile: { + name: string, + gender: string, + location: string, + website: string, + picture: string + }, + + comparePassword: comparePasswordFunction, +}; + +type comparePasswordFunction = (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void; + +export type AuthToken = { + accessToken: string, + kind: string +}; + +const userSchema = new mongoose.Schema({ + email: { type: String, unique: true }, + password: String, + passwordResetToken: String, + passwordResetExpires: Date, + + allWorkspaceIds: { + type: Array, + default: [] + }, + activeWorkspaceId: String, + didSelectSessionWorkspace: { + type: Boolean, + default: false + }, + + facebook: String, + twitter: String, + google: String, + + profile: { + name: String, + gender: String, + location: String, + website: String, + picture: String + } +}, { timestamps: true }); + +/** + * Password hash middleware. + */ +userSchema.pre("save", function save(next) { + const user = this as DashUserModel; + if (!user.isModified("password")) { return next(); } + bcrypt.genSalt(10, (err, salt) => { + if (err) { return next(err); } + bcrypt.hash(user.password, salt, () => void {}, (err: mongoose.Error, hash) => { + if (err) { return next(err); } + user.password = hash; + next(); + }); + }); +}); + +const comparePassword: comparePasswordFunction = function (this: DashUserModel, candidatePassword, cb) { + bcrypt.compare(candidatePassword, this.password, (err: mongoose.Error, isMatch: boolean) => { + cb(err, isMatch); + }); +}; + +userSchema.methods.comparePassword = comparePassword; + +const User = mongoose.model("User", userSchema); +export default User; \ No newline at end of file diff --git a/src/server/index.ts b/src/server/index.ts index 50f01fe31..6136b8d94 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -17,7 +17,7 @@ import * as bcrypt from "bcrypt-nodejs"; import { Document } from '../fields/Document'; import * as io from 'socket.io' import * as passportConfig from './authentication/config/passport'; -import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, postReset, getForgot, postForgot, getReset } from './authentication/controllers/user'; +import { getLogin, postLogin, getSignup, postSignup, getLogout, getEntry, postReset, getForgot, postForgot, getReset, getWorkspaces } from './authentication/controllers/user_controller'; const config = require('../../webpack.config'); const compiler = webpack(config); const port = 1050; // default port to listen @@ -34,7 +34,7 @@ const MongoStore = require('connect-mongo')(session); const mongoose = require('mongoose'); import { performance } from 'perf_hooks' import * as path from 'path' -import User, { UserModel } from './authentication/models/User'; +import User, { DashUserModel } from './authentication/models/user_model'; const mongoUrl = 'mongodb://localhost:27017/Dash'; mongoose.connect(mongoUrl) @@ -81,27 +81,48 @@ app.use((req, res, next) => { // /home defines destination after a successful log in app.get("/home", (req, res) => { // if user is not logged in, redirect to log in page - if (!req.user) { - res.redirect("/login"); - return; + const dashUser: DashUserModel = req.user; + if (!dashUser) { + return res.redirect("/login"); } // otherwise, connect them to Dash // TODO: store and manage users' workspaces + if (dashUser.allWorkspaceIds.length > 0) { + if (!dashUser.didSelectSessionWorkspace) { + return res.redirect("/workspaces"); + } + } else { + console.log("OK, UPDATED TO TRUE"); + dashUser.update({ $set: { didSelectSessionWorkspace: true } }, () => { }) + } res.sendFile(path.join(__dirname, '../../deploy/index.html')); }); -app.get("/getUserDocId", (req, res) => { - if (!req.user) { +app.get("/workspaces", getWorkspaces); + +app.get("/getActiveWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { + return; + } + res.send(dashUser.activeWorkspaceId || ""); +}); + +app.post("/setActiveWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { return; } - res.send(req.user.userDocumentId || ""); + console.log(`Updating active workspace ID to ${req.body.target}`); + dashUser.update({ $set: { activeWorkspaceId: req.body.target } }, () => { }); }) -app.post("/setUserDocId", (req, res) => { - if (!req.user) { +app.post("/addWorkspaceId", (req, res) => { + const dashUser: DashUserModel = req.user; + if (!dashUser) { return; } - req.user.update({ $set: { userDocumentId: req.body.userDocumentId } }, () => { }); + dashUser.update({ $push: { allWorkspaceIds: req.body.target } }, () => { }); }) // anyone attempting to navigate to localhost at this port will diff --git a/views/stylesheets/authentication.css b/views/stylesheets/authentication.css index bce8223ec..dea0474e4 100644 --- a/views/stylesheets/authentication.css +++ b/views/stylesheets/authentication.css @@ -48,10 +48,37 @@ body { } #overlay_signup, -#overlay_reset { +#overlay_reset, +#overlay_workspaces { height: 345px; } +.workspace-header { + margin-left: 20px; +} + +.select-workspace { + margin-top: 15px; + margin-left: 20px; +} + +#overlay_workspaces { + overflow-y: scroll; + text-align: left; +} + +.workspaceId { + list-style-type: none; + font-family: Arial, Helvetica, sans-serif; + margin-left: -20px; + cursor: grab; + padding-bottom: 15px; +} + +.workspaceId:hover { + color: red; +} + #overlay_login { height: 300px; } diff --git a/views/workspace.pug b/views/workspace.pug new file mode 100644 index 000000000..8bbc3e02c --- /dev/null +++ b/views/workspace.pug @@ -0,0 +1,13 @@ + +extends ./layout + +block content + style + include ./stylesheets/authentication.css + form.form-horizontal(id='workspace-form', method='POST', action='/home') + input(type='hidden', name='_csrf', value=_csrf) + .overlay(id='overlay_workspaces') + h3.workspace-header Select A Workspace + ul.workspaceList + each val, index in ids + li.workspaceId(onclick='console.log("' + val + '")')= (index + 1) + ') ' + val \ No newline at end of file -- cgit v1.2.3-70-g09d2