added email fixes

This commit is contained in:
Wyatt Johnson
2018-01-11 10:58:43 -07:00
parent 92b506c85a
commit 1dcf297a45
5 changed files with 42 additions and 28 deletions
+4 -3
View File
@@ -11,6 +11,7 @@ const uuid = require('uuid');
const debug = require('debug')('talk:services:passport');
const bowser = require('bowser');
const ms = require('ms');
const _ = require('lodash');
// Create a redis client to use for authentication.
const {createClientFactory} = require('./redis');
@@ -144,7 +145,7 @@ async function ValidateUserLogin(loginProfile, user, done) {
// If the profile doesn't have a metadata field, or it does not have a
// confirmed_at field, or that field is null, then send them back.
if (!profile.metadata || !profile.metadata.confirmed_at || profile.metadata.confirmed_at === null) {
if (_.get(profile, 'metadata.confirmed_at', null) === null) {
return done(errors.ErrNotVerified);
}
}
@@ -318,7 +319,7 @@ const CheckIfNeedsRecaptcha = (user, email) => {
throw new Error('ID indicated by loginProfile is not on user object');
}
if (profile.metadata && profile.metadata.recaptcha_required) {
if (_.get(profile, 'metadata.recaptcha_required', false)) {
return true;
}
@@ -501,7 +502,7 @@ passport.use(new LocalStrategy({
}
// Define the loginProfile being used to perform an additional
// verificaiton.
// verification.
let loginProfile = {id: email, provider: 'local'};
// Perform final steps to login the user.
+10 -13
View File
@@ -339,7 +339,7 @@ class UsersService {
}
/**
* Sets or unsets the recaptcha_required flag on a user's local profile.
* Sets or removes the recaptcha_required flag on a user's local profile.
*/
static flagForRecaptchaRequirement(email, required) {
return UserModel.update(
@@ -436,20 +436,17 @@ class UsersService {
}
static async sendEmail(user, options) {
const localProfile = user.profiles.find(
(profile) => profile.provider === 'local'
);
if (!localProfile) {
throw new Error('user does not have an email');
const email = user.firstEmail;
if (!email) {
// Rather than throwing an error here, we'll
console.warn(new Error('user does not have an email'));
return;
}
const {id: to} = localProfile;
options = merge(options, {
to,
});
return mailer.send(options);
return mailer.send(merge({}, options, {
to: email,
}));
}
static async changePassword(id, password) {