Merge conflicts and clean up lint errors.
This commit is contained in:
@ -4,7 +4,6 @@ var defaultProfileImage =
|
|||||||
require('../utils/constantStrings.json').defaultProfileImage;
|
require('../utils/constantStrings.json').defaultProfileImage;
|
||||||
|
|
||||||
module.exports = function(UserIdent) {
|
module.exports = function(UserIdent) {
|
||||||
|
|
||||||
UserIdent.observe('before save', function(ctx, next) {
|
UserIdent.observe('before save', function(ctx, next) {
|
||||||
var userIdent = ctx.currentInstance || ctx.instance;
|
var userIdent = ctx.currentInstance || ctx.instance;
|
||||||
if (!userIdent) {
|
if (!userIdent) {
|
||||||
@ -17,7 +16,6 @@ module.exports = function(UserIdent) {
|
|||||||
debug('no user attached to identity!');
|
debug('no user attached to identity!');
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
debug('got user', user.username);
|
|
||||||
|
|
||||||
var picture = userIdent.profile && userIdent.profile[0] ?
|
var picture = userIdent.profile && userIdent.profile[0] ?
|
||||||
userIdent.profile[0].value :
|
userIdent.profile[0].value :
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
var debug = require('debug')('freecc:user:remote');
|
var debug = require('debug')('freecc:user:remote');
|
||||||
|
var blacklistedUsernames =
|
||||||
|
require('../../server/utils/constants').blacklistedUsernames;
|
||||||
|
|
||||||
module.exports = function(User) {
|
module.exports = function(User) {
|
||||||
// NOTE(berks): user email validation currently not needed but build in. This
|
// NOTE(berks): user email validation currently not needed but build in. This
|
||||||
@ -42,13 +44,6 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
User.beforeRemote('login', function(ctx, instance, next) {
|
|
||||||
debug('before called');
|
|
||||||
|
|
||||||
//debug(ctx, instance, next);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
User.afterRemote('confirm', function(ctx, instance, next) {
|
User.afterRemote('confirm', function(ctx, instance, next) {
|
||||||
ctx.req.flash('success', {
|
ctx.req.flash('success', {
|
||||||
msg: [
|
msg: [
|
||||||
@ -59,7 +54,6 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
User.afterRemote('login', function(ctx, instance, next) {
|
User.afterRemote('login', function(ctx, instance, next) {
|
||||||
debug('after called');
|
|
||||||
var res = ctx.res;
|
var res = ctx.res;
|
||||||
var req = ctx.req;
|
var req = ctx.req;
|
||||||
|
|
||||||
@ -101,6 +95,18 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
return res.redirect('/');
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
signed: !!req.signedCookies,
|
||||||
|
maxAge: 1000 * accessToken.ttl
|
||||||
|
};
|
||||||
|
if (accessToken && accessToken.id) {
|
||||||
|
res.cookie('access_token', accessToken.id, config);
|
||||||
|
res.cookie('userId', accessToken.userId, config);
|
||||||
|
}
|
||||||
|
res.redirect('/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -119,6 +125,12 @@ module.exports = function(User) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
debug('checking existence');
|
debug('checking existence');
|
||||||
|
|
||||||
|
// check to see if username is on blacklist
|
||||||
|
if (username && blacklistedUsernames.indexOf(username) !== -1) {
|
||||||
|
return cb(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
var where = {};
|
var where = {};
|
||||||
if (username) {
|
if (username) {
|
||||||
where.username = username.toLowerCase();
|
where.username = username.toLowerCase();
|
||||||
|
@ -1,140 +1,40 @@
|
|||||||
//var debug = require('debug')('freecc:extendUser');
|
var Rx = require('rx');
|
||||||
//
|
var debug = require('debug')('freecc:user:remote');
|
||||||
//module.exports = function(app) {
|
|
||||||
// var User = app.models.User;
|
function destroyById(id, Model) {
|
||||||
// // NOTE(berks): user email validation currently not needed but build in. This
|
return Rx.Observable.create(function(observer) {
|
||||||
// // work around should let us sneak by
|
Model.destroyById(id, function(err) {
|
||||||
// // see:
|
if (err) { return observer.onError(err); }
|
||||||
// // https://github.com/strongloop/loopback/issues/1137#issuecomment-109200135
|
observer.onCompleted();
|
||||||
// delete User.validations.email;
|
});
|
||||||
// debug('setting up user hooks');
|
return Rx.Disposable(Rx.helpers.noop);
|
||||||
// // send verification email to new camper
|
});
|
||||||
// User.afterRemote('create', function(ctx, user, next) {
|
}
|
||||||
// debug('user created, sending email');
|
|
||||||
// if (!user.email) { return next(); }
|
module.exports = function(app) {
|
||||||
//
|
var User = app.models.User;
|
||||||
// var mailOptions = {
|
var UserIdentity = app.models.UserIdentity;
|
||||||
// type: 'email',
|
var UserCredential = app.models.UserCredential;
|
||||||
// to: user.email,
|
User.observe('after delete', function(ctx, next) {
|
||||||
// from: 'Team@freecodecamp.com',
|
debug('removing user', ctx.where);
|
||||||
// subject: 'Welcome to Free Code Camp!',
|
var id = ctx.where && ctx.where.id ? ctx.where.id : null;
|
||||||
// redirect: '/',
|
if (!id) {
|
||||||
// text: [
|
return next();
|
||||||
// 'Greetings from San Francisco!\n\n',
|
}
|
||||||
// 'Thank you for joining our community.\n',
|
Rx.Observable.combineLatest(
|
||||||
// 'Feel free to email us at this address if you have ',
|
destroyById(id, UserIdentity),
|
||||||
// 'any questions about Free Code Camp.\n',
|
destroyById(id, UserCredential),
|
||||||
// 'And if you have a moment, check out our blog: ',
|
Rx.helpers.noop
|
||||||
// 'blog.freecodecamp.com.\n',
|
).subscribe(
|
||||||
// 'Good luck with the challenges!\n\n',
|
Rx.helpers.noop,
|
||||||
// '- the Free Code Camp Volunteer Team'
|
function(err) {
|
||||||
// ].join('')
|
debug('error deleting user %s stuff', id, err);
|
||||||
// };
|
next(err);
|
||||||
// user.verify(mailOptions, function(err) {
|
},
|
||||||
// if (err) { return next(err); }
|
function() {
|
||||||
// debug('verification email sent');
|
debug('user stuff deleted for user %s', id);
|
||||||
// ctx.req.flash('success', {
|
next();
|
||||||
// msg: [
|
}
|
||||||
// 'Please check your email and click on the verification link '
|
);
|
||||||
// + 'before logging in.'
|
});
|
||||||
// ]
|
};
|
||||||
// });
|
|
||||||
// ctx.res.redirect('/');
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// User.beforeRemote('login', function(ctx, results, next) {
|
|
||||||
// debug('before called');
|
|
||||||
// next();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// User.afterRemote('login', function(ctx, instance, next) {
|
|
||||||
// debug('after called');
|
|
||||||
// var res = ctx.res;
|
|
||||||
// var req = ctx.req;
|
|
||||||
//
|
|
||||||
// if (!instance || !instance.emailVerified) {
|
|
||||||
// req.flash('errors', {
|
|
||||||
// msg: [
|
|
||||||
// 'Please verify your email address.'
|
|
||||||
// ]
|
|
||||||
// });
|
|
||||||
// return res.redirect('/');
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var config = {
|
|
||||||
// signed: !!req.signedCookies,
|
|
||||||
// maxAge: 1000 * accessToken.ttl
|
|
||||||
// };
|
|
||||||
// if (accessToken && accessToken.id) {
|
|
||||||
// res.cookie('access_token', accessToken.id, config);
|
|
||||||
// res.cookie('userId', accessToken.userId, config);
|
|
||||||
// }
|
|
||||||
// res.redirect('/');
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// User.afterRemote('logout', function(ctx, result, next) {
|
|
||||||
// var res = ctx.result;
|
|
||||||
// res.clearCookie('access_token');
|
|
||||||
// res.clearCookie('userId');
|
|
||||||
// next();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// User.doesExist = function doesExist(username, email, cb) {
|
|
||||||
// if (!username && !email) {
|
|
||||||
// return process.nextTick(function() {
|
|
||||||
// cb(null, false);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// debug('checking existence');
|
|
||||||
// var where = {};
|
|
||||||
// if (username) {
|
|
||||||
// where.username = username.toLowerCase();
|
|
||||||
// } else {
|
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// User.remoteMethod(
|
|
||||||
// 'doesExist',
|
|
||||||
// {
|
|
||||||
// description: 'checks whether a user exists using email or username',
|
|
||||||
// accepts: [
|
|
||||||
// {
|
|
||||||
// arg: 'username',
|
|
||||||
// type: 'string'
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// arg: 'email',
|
|
||||||
// type: 'string'
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// returns: [
|
|
||||||
// {
|
|
||||||
// arg: 'exists',
|
|
||||||
// type: 'boolean'
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// http: {
|
|
||||||
// path: '/exists',
|
|
||||||
// verb: 'get'
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
//};
|
|
||||||
|
39
server/utils/constants.js
Normal file
39
server/utils/constants.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
exports.blacklistedUsernames = [
|
||||||
|
'bonfire',
|
||||||
|
'account',
|
||||||
|
'user',
|
||||||
|
'challenge',
|
||||||
|
'challenges',
|
||||||
|
'completed-challenge',
|
||||||
|
'completed-zipline-or-basejump',
|
||||||
|
'completed-bonfire',
|
||||||
|
'map',
|
||||||
|
'learn-to-code',
|
||||||
|
'about',
|
||||||
|
'api',
|
||||||
|
'explorer',
|
||||||
|
'field-guide',
|
||||||
|
'completed-field-guide',
|
||||||
|
'jobs',
|
||||||
|
'nonprofits',
|
||||||
|
'api',
|
||||||
|
'sitemap.xml',
|
||||||
|
'get-help',
|
||||||
|
'chat',
|
||||||
|
'twitch',
|
||||||
|
'get-pai',
|
||||||
|
'get-help',
|
||||||
|
'nonprofits',
|
||||||
|
'nonproifts-form',
|
||||||
|
'jobs-form',
|
||||||
|
'unsubscribe',
|
||||||
|
'unsubscribed',
|
||||||
|
'cats.json',
|
||||||
|
'agile',
|
||||||
|
'privacy',
|
||||||
|
'stories',
|
||||||
|
'signin',
|
||||||
|
'signout',
|
||||||
|
'forgot',
|
||||||
|
'reset'
|
||||||
|
];
|
Reference in New Issue
Block a user