From 34aab319212b48c6abb2811dc841956826ee89de Mon Sep 17 00:00:00 2001
From: Ruben van de Ven
+ {/*
{email.error} )} -
+ */}{ * Sign in using Email/Username and Password. */ passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, done) => { - User.findByEmailOrUsername(email) + User.findByUsername(email) .then((user) => { // eslint-disable-line consistent-return if (!user) { return done(null, false, { msg: `Email ${email} not found.` }); diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index 0ff791c6..31ca2ded 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -12,7 +12,7 @@ export * from './user.controller/apiKey'; export function userResponse(user) { return { - email: user.email, + // email: user.email, username: user.username, preferences: user.preferences, apiKeys: user.apiKeys, @@ -36,31 +36,32 @@ export function findUserByUsername(username, cb) { } export function createUser(req, res, next) { - const { username, email } = req.body; + const { username, _ } = req.body; const { password } = req.body; - const emailLowerCase = email.toLowerCase(); + // const emailLowerCase = email ? email.toLowerCase() : null; const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date.now() + (3600000 * 24); // 24 hours random((tokenError, token) => { const user = new User({ username, - email: emailLowerCase, + // email: emailLowerCase, password, verified: User.EmailConfirmation.Sent, verifiedToken: token, verifiedTokenExpires: EMAIL_VERIFY_TOKEN_EXPIRY_TIME, }); - User.findByEmailAndUsername(email, username, (err, existingUser) => { + User.findByUsername(username, (err, existingUser) => { if (err) { res.status(404).send({ error: err }); return; } if (existingUser) { - const fieldInUse = existingUser.email.toLowerCase() === emailLowerCase ? 'Email' : 'Username'; + const fieldInUse = 'Username'; res.status(422).send({ error: `${fieldInUse} is in use` }); return; } + user.save((saveErr) => { if (saveErr) { next(saveErr); @@ -73,17 +74,17 @@ export function createUser(req, res, next) { } const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; - const mailOptions = renderEmailConfirmation({ - body: { - domain: `${protocol}://${req.headers.host}`, - link: `${protocol}://${req.headers.host}/verify?t=${token}` - }, - to: req.user.email, - }); + // const mailOptions = renderEmailConfirmation({ + // body: { + // domain: `${protocol}://${req.headers.host}`, + // link: `${protocol}://${req.headers.host}/verify?t=${token}` + // }, + // to: req.user.email, + // }); - mail.send(mailOptions, (mailErr, result) => { // eslint-disable-line no-unused-vars - res.json(userResponse(req.user)); - }); + // mail.send(mailOptions, (mailErr, result) => { // eslint-disable-line no-unused-vars + res.json(userResponse(req.user)); + // }); }); }); }); @@ -142,18 +143,19 @@ export function resetPasswordInitiate(req, res) { async.waterfall([ random, (token, done) => { - User.findByEmail(req.body.email, (err, user) => { - if (!user) { - res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' }); - return; - } - user.resetPasswordToken = token; - user.resetPasswordExpires = Date.now() + 3600000; // 1 hour + // disable since we don't use email + // User.findByEmail(req.body.email, (err, user) => { + // if (!user) { + // res.json({ success: true, message: 'If the email is registered with the editor, an email has been sent.' }); + // return; + // } + // user.resetPasswordToken = token; + // user.resetPasswordExpires = Date.now() + 3600000; // 1 hour - user.save((saveErr) => { - done(saveErr, token, user); - }); - }); + // user.save((saveErr) => { + // done(saveErr, token, user); + // }); + // }); }, (token, user, done) => { const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; diff --git a/server/models/user.js b/server/models/user.js index ae019c63..7cb65cf4 100644 --- a/server/models/user.js +++ b/server/models/user.js @@ -50,7 +50,7 @@ const userSchema = new Schema({ verifiedToken: String, verifiedTokenExpires: Date, github: { type: String }, - email: { type: String, unique: true }, + email: { type: String }, tokens: Array, apiKeys: { type: [apiKeySchema] }, preferences: { @@ -192,10 +192,10 @@ userSchema.statics.findByUsername = function findByUsername(username, cb) { * @return {Promise