remove email verification step.

users are marked for future uses
This commit is contained in:
Berkeley Martinez
2015-06-15 15:43:12 -07:00
parent a334b9870c
commit c4d229e62d
2 changed files with 67 additions and 75 deletions

View File

@ -21,41 +21,6 @@ module.exports = function(User) {
User.validatesUniquenessOf('username'); User.validatesUniquenessOf('username');
debug('setting up user hooks'); debug('setting up user hooks');
// send verification email to new camper
User.afterRemote('create', function(ctx, user, next) {
debug('user created, sending email');
if (!user.email) { return next(); }
var mailOptions = {
type: 'email',
to: user.email,
from: 'Team@freecodecamp.com',
subject: 'Welcome to Free Code Camp!',
redirect: '/',
text: [
'Greetings from San Francisco!\n\n',
'Thank you for joining our community.\n',
'Feel free to email us at this address if you have ',
'any questions about Free Code Camp.\n',
'And if you have a moment, check out our blog: ',
'blog.freecodecamp.com.\n',
'Good luck with the challenges!\n\n',
'- the Free Code Camp Volunteer Team'
].join('')
};
user.verify(mailOptions, function(err) {
if (err) { return next(err); }
debug('verification email sent');
ctx.req.flash('success', {
msg: [
'Please check your email and click on the verification link '
+ 'before logging in.'
]
});
ctx.res.redirect('/');
});
});
User.afterRemote('confirm', function(ctx) { User.afterRemote('confirm', function(ctx) {
ctx.req.flash('success', { ctx.req.flash('success', {
msg: [ msg: [
@ -65,49 +30,28 @@ module.exports = function(User) {
ctx.res.redirect('/email-signin'); ctx.res.redirect('/email-signin');
}); });
User.afterRemote('login', function(ctx, instance, next) { User.afterRemote('login', function(ctx, user, next) {
var res = ctx.res; var res = ctx.res;
var req = ctx.req; var req = ctx.req;
// var args = ctx.args;
User.findOne({where: {email: ctx.args.credentials.email}}, var accessToken = {};
function(err, response) { var config = {
if (err) { signed: !!req.signedCookies,
return next(err); maxAge: accessToken.ttl
} };
if (response.emailVerified !== true) { if (accessToken && accessToken.id) {
return res.redirect('/'); res.cookie('access_token', accessToken.id, config);
} res.cookie('userId', accessToken.userId, config);
User.login({ }
email: ctx.args.credentials.email,
password: ctx.args.credentials.password, return req.logIn(user, function(err) {
ttl: Infinity if (err) {
}, function(err, accessToken) { return next(err);
if (err) { }
req.flash('errors', { req.flash('success', { msg: 'Success! You are logged in.' });
msg: [ return res.redirect('/');
'Invalid username or password.' });
]
});
return res.redirect('/');
}
var config = {
signed: !!req.signedCookies,
maxAge: accessToken.ttl
};
if (accessToken && accessToken.id) {
res.cookie('access_token', accessToken.id, config);
res.cookie('userId', accessToken.userId, config);
}
req.logIn(response, function(err) {
if (err) {
return next(err);
}
req.flash('success', { msg: 'Success! You are logged in.' });
return res.redirect('/');
});
});
});
return res.redirect('/');
}); });
User.afterRemote('logout', function(ctx, result, next) { User.afterRemote('logout', function(ctx, result, next) {

View File

@ -12,6 +12,7 @@ module.exports = function(app) {
var User = app.models.User; var User = app.models.User;
var UserIdentity = app.models.UserIdentity; var UserIdentity = app.models.UserIdentity;
var UserCredential = app.models.UserCredential; var UserCredential = app.models.UserCredential;
var Email = app.models.Email;
User.observe('before delete', function(ctx, next) { User.observe('before delete', function(ctx, next) {
debug('removing user', ctx.where); debug('removing user', ctx.where);
var id = ctx.where && ctx.where.id ? ctx.where.id : null; var id = ctx.where && ctx.where.id ? ctx.where.id : null;
@ -41,4 +42,51 @@ module.exports = function(app) {
} }
); );
}); });
// set email varified false on user email signup
// should not be set with oauth signin methods
User.beforeRemote('create', function(ctx, user, next) {
var body = ctx.req.body;
if (body) {
body.emailVerified = false;
}
next();
});
// send welcome email to new camper
User.afterRemote('create', function(ctx, user, next) {
debug('user created, sending email');
if (!user.email) { return next(); }
var mailOptions = {
type: 'email',
to: user.email,
from: 'Team@freecodecamp.com',
subject: 'Welcome to Free Code Camp!',
redirect: '/',
text: [
'Greetings from San Francisco!\n\n',
'Thank you for joining our community.\n',
'Feel free to email us at this address if you have ',
'any questions about Free Code Camp.\n',
'And if you have a moment, check out our blog: ',
'blog.freecodecamp.com.\n',
'Good luck with the challenges!\n\n',
'- the Free Code Camp Volunteer Team'
].join('')
};
debug('sending welcome email');
Email.send(mailOptions, function(err) {
if (err) { return next(err); }
ctx.req.logIn(user, function(err) {
if (err) { return next(err); }
ctx.req.flash('success', {
msg: [ 'thanks for joining freecodecamp!' ]
});
ctx.res.redirect('/');
});
});
});
}; };