mirror of
https://github.com/vale981/Vulcan
synced 2025-03-08 19:11:38 -05:00
clean up
This commit is contained in:
parent
7e518007f1
commit
974b3c70b5
3 changed files with 74 additions and 68 deletions
|
@ -1,7 +1,6 @@
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
// ------------------------------------------------------------------------------------------- //
|
// Collection Hooks //
|
||||||
// ------------------------------------------ Hooks ------------------------------------------ //
|
//////////////////////////////////////////////////////
|
||||||
// ------------------------------------------------------------------------------------------- //
|
|
||||||
|
|
||||||
Comments.before.insert(function (userId, doc) {
|
Comments.before.insert(function (userId, doc) {
|
||||||
// note: only actually sanitizes on the server
|
// note: only actually sanitizes on the server
|
||||||
|
@ -25,6 +24,10 @@ Comments.before.update(function (userId, doc, fieldNames, modifier) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// Callbacks //
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
function afterCommentOperations (comment) {
|
function afterCommentOperations (comment) {
|
||||||
|
|
||||||
var userId = comment.userId;
|
var userId = comment.userId;
|
||||||
|
|
|
@ -1,3 +1,70 @@
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// Collection Hooks //
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate HTML body from Markdown on user bio insert
|
||||||
|
*/
|
||||||
|
Users.after.insert(function (userId, user) {
|
||||||
|
|
||||||
|
// run create user async callbacks
|
||||||
|
Telescope.callbacks.runAsync("onCreateUserAsync", user);
|
||||||
|
|
||||||
|
// check if all required fields have been filled in. If so, run profile completion callbacks
|
||||||
|
if (Users.hasCompletedProfile(user)) {
|
||||||
|
Telescope.callbacks.runAsync("profileCompletedAsync", user);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate HTML body from Markdown when user bio is updated
|
||||||
|
*/
|
||||||
|
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
||||||
|
// if bio is being modified, update htmlBio too
|
||||||
|
if (Meteor.isServer && modifier.$set && modifier.$set["telescope.bio"]) {
|
||||||
|
modifier.$set["telescope.htmlBio"] = Telescope.utils.sanitize(marked(modifier.$set["telescope.bio"]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disallow $rename
|
||||||
|
*/
|
||||||
|
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
||||||
|
if (!!modifier.$rename) {
|
||||||
|
throw new Meteor.Error("illegal $rename operator detected!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If user.telescope.email has changed, check for existing emails and change user.emails if needed
|
||||||
|
*/
|
||||||
|
if (Meteor.isServer) {
|
||||||
|
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
||||||
|
var user = doc;
|
||||||
|
// if email is being modified, update user.emails too
|
||||||
|
if (Meteor.isServer && modifier.$set && modifier.$set["telescope.email"]) {
|
||||||
|
var newEmail = modifier.$set["telescope.email"];
|
||||||
|
// check for existing emails and throw error if necessary
|
||||||
|
var userWithSameEmail = Users.findByEmail(newEmail);
|
||||||
|
if (userWithSameEmail && userWithSameEmail._id !== doc._id) {
|
||||||
|
throw new Meteor.Error("email_taken2", i18n.t("this_email_is_already_taken") + " (" + newEmail + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if user.emails exists, change it too
|
||||||
|
if (!!user.emails) {
|
||||||
|
user.emails[0].address = newEmail;
|
||||||
|
modifier.$set.emails = user.emails;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// Callbacks //
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up user object on creation
|
* Set up user object on creation
|
||||||
* @param {Object} user – the user object being iterated on and returned
|
* @param {Object} user – the user object being iterated on and returned
|
||||||
|
|
|
@ -249,67 +249,3 @@ Users.allow({
|
||||||
remove: _.partial(Telescope.allowCheck, Meteor.users)
|
remove: _.partial(Telescope.allowCheck, Meteor.users)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
// Collection Hooks //
|
|
||||||
// https://atmospherejs.com/matb33/collection-hooks //
|
|
||||||
//////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate HTML body from Markdown on user bio insert
|
|
||||||
*/
|
|
||||||
Users.after.insert(function (userId, user) {
|
|
||||||
|
|
||||||
// run create user async callbacks
|
|
||||||
Telescope.callbacks.runAsync("onCreateUserAsync", user);
|
|
||||||
|
|
||||||
// check if all required fields have been filled in. If so, run profile completion callbacks
|
|
||||||
if (Users.hasCompletedProfile(user)) {
|
|
||||||
Telescope.callbacks.runAsync("profileCompletedAsync", user);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate HTML body from Markdown when user bio is updated
|
|
||||||
*/
|
|
||||||
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
|
||||||
// if bio is being modified, update htmlBio too
|
|
||||||
if (Meteor.isServer && modifier.$set && modifier.$set["telescope.bio"]) {
|
|
||||||
modifier.$set["telescope.htmlBio"] = Telescope.utils.sanitize(marked(modifier.$set["telescope.bio"]));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disallow $rename
|
|
||||||
*/
|
|
||||||
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
|
||||||
if (!!modifier.$rename) {
|
|
||||||
throw new Meteor.Error("illegal $rename operator detected!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If user.telescope.email has changed, check for existing emails and change user.emails if needed
|
|
||||||
*/
|
|
||||||
if (Meteor.isServer) {
|
|
||||||
Users.before.update(function (userId, doc, fieldNames, modifier) {
|
|
||||||
var user = doc;
|
|
||||||
// if email is being modified, update user.emails too
|
|
||||||
if (Meteor.isServer && modifier.$set && modifier.$set["telescope.email"]) {
|
|
||||||
var newEmail = modifier.$set["telescope.email"];
|
|
||||||
// check for existing emails and throw error if necessary
|
|
||||||
var userWithSameEmail = Users.findByEmail(newEmail);
|
|
||||||
if (userWithSameEmail && userWithSameEmail._id !== doc._id) {
|
|
||||||
throw new Meteor.Error("email_taken2", i18n.t("this_email_is_already_taken") + " (" + newEmail + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
// if user.emails exists, change it too
|
|
||||||
if (!!user.emails) {
|
|
||||||
user.emails[0].address = newEmail;
|
|
||||||
modifier.$set.emails = user.emails;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue