From 600ca2f8ad0a59a2e29d4d3f237c8be6197d5678 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Mon, 28 Dec 2015 13:52:28 -0800 Subject: [PATCH 1/2] Fix duplicate email sign in --- common/models/user.js | 49 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/common/models/user.js b/common/models/user.js index f2e49ae252f..95596ecd744 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -79,9 +79,31 @@ module.exports = function(User) { ctx.res.redirect('/email-signin'); }); - User.beforeRemote('create', function({ req }, notUsed, next) { + User.beforeRemote('create', function({ req, res }, _, next) { req.body.username = 'fcc' + uuid.v4().slice(0, 8); - next(); + if (!req.body.email) { + return next(); + } + return User.doesExist(null, req.body.email) + .then(exists => { + if (!exists) { + return next(); + } + + req.flash('error', { + msg: + `email ${req.body.email} is already in user, try signing in instead` + }); + + return res.redirect('/email-signin'); + }) + .catch(err => { + console.error(err); + req.flash('error', { + msg: 'Oops, something went wrong, please try again later' + }); + return res.redirect('/email-signup'); + }); }); User.on('resetPasswordRequest', function(info) { @@ -174,17 +196,15 @@ module.exports = function(User) { next(); }); - User.doesExist = function doesExist(username, email, cb) { + User.doesExist = function doesExist(username, email) { if (!username && !email) { - return nextTick(function() { - cb(null, false); - }); + return Promise.resolve(false); } debug('checking existence'); // check to see if username is on blacklist if (username && blacklistedUsernames.indexOf(username) !== -1) { - return cb(null, true); + return Promise.resolve(true); } var where = {}; @@ -194,19 +214,8 @@ module.exports = function(User) { where.email = email ? email.toLowerCase() : email; } debug('where', where); - User.count( - where, - function(err, count) { - if (err) { - debug('err checking existance: ', err); - return cb(err); - } - if (count > 0) { - return cb(null, true); - } - return cb(null, false); - } - ); + return User.count(where) + .then(count => count > 0); }; User.remoteMethod( From 80bb80b23a1407943c049a674191c8fad1943a1a Mon Sep 17 00:00:00 2001 From: Quincy Larson Date: Mon, 28 Dec 2015 16:28:53 -0600 Subject: [PATCH 2/2] minor updates to copy --- common/models/user.js | 3 ++- server/views/account/show.jade | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/common/models/user.js b/common/models/user.js index 95596ecd744..622d5f73f43 100644 --- a/common/models/user.js +++ b/common/models/user.js @@ -92,7 +92,8 @@ module.exports = function(User) { req.flash('error', { msg: - `email ${req.body.email} is already in user, try signing in instead` + `The ${req.body.email} email address is already associated with an account. + Try signing in with it here instead.` }); return res.redirect('/email-signin'); diff --git a/server/views/account/show.jade b/server/views/account/show.jade index 3f7b11a100e..f107eb7e73f 100644 --- a/server/views/account/show.jade +++ b/server/views/account/show.jade @@ -232,10 +232,10 @@ block content .modal-footer a.btn.btn-success.btn-block(href='#', data-dismiss='modal', aria-hidden='true') span.ion-happy - | Nevermind, I don't want to delete all my progress - .btn-spacer + | Nevermind, I don't want to delete all of my progress + .spacer form(action='/account/delete', method='POST') input(type='hidden', name='_csrf', value=_csrf) button.btn.btn-danger.btn-block(type='submit') span.ion-trash-b - | I am 100% sure I want to delete all my progress + | I am 100% sure I want to delete my account and all of my progress