mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00

Add the following hooks: - ``addToUserSchema``: fields to add to the (currently unused) user Schema - ``postAuthor``: templates to use when rendering the post author in the byline - ``userProfileDisplay``: additional templates to add to the user profile display. - ``userProfileEdit``: additional templates to add to the user profile editing form. - ``userProfileFinishSignup``: additional templates to show in the view for completing user signup (adding email, username, etc). - ``userEditRenderedCallbacks``: Callbacks executed on "rendered" for user_edit view. - ``userEditClientCallbacks``: Callbacks used to further process user properties before saving changes in user_edit view. - ``userProfileCompleteChecks``: Functions called to determine whether a user profile is "complete" (e.g. has email, username, and whatever else). These hooks facilitate package authors changing which profile fields are displayed, which profile fields are required, and how to display usernames next to posts.
105 lines
3.2 KiB
JavaScript
105 lines
3.2 KiB
JavaScript
Template[getTemplate('user_edit')].helpers({
|
|
profileIncomplete : function() {
|
|
return this && !this.loading && !userProfileComplete(this);
|
|
},
|
|
userName: function(){
|
|
return getUserName(this);
|
|
},
|
|
userEmail : function(){
|
|
return getEmail(this);
|
|
},
|
|
getTwitter: function(){
|
|
return getTwitterName(this) || "";
|
|
},
|
|
getGitHub: function(){
|
|
return getGitHubName(this) || "";
|
|
},
|
|
profileUrl: function(){
|
|
return Meteor.absoluteUrl()+"users/"+this.slug;
|
|
},
|
|
hasNotificationsUsers : function(){
|
|
return getUserSetting('notifications.users', '', this) ? 'checked' : '';
|
|
},
|
|
hasNotificationsPosts : function(){
|
|
return getUserSetting('notifications.posts', '', this) ? 'checked' : '';
|
|
},
|
|
hasNotificationsComments : function(){
|
|
return getUserSetting('notifications.comments', '', this) ? 'checked' : '';
|
|
},
|
|
hasNotificationsReplies : function(){
|
|
return getUserSetting('notifications.replies', '', this) ? 'checked' : '';
|
|
},
|
|
hasPassword: function () {
|
|
return hasPassword(Meteor.user());
|
|
},
|
|
getTemplate: function() {
|
|
return getTemplate(this.template);
|
|
},
|
|
userProfileEdit: function() {
|
|
return userProfileEdit;
|
|
}
|
|
});
|
|
|
|
Template[getTemplate('user_edit')].rendered = function() {
|
|
var instance = this;
|
|
userEditRenderedCallbacks.forEach(function(callback) {
|
|
callback(instance);
|
|
});
|
|
};
|
|
|
|
Template[getTemplate('user_edit')].events({
|
|
'submit #account-form': function(e){
|
|
e.preventDefault();
|
|
|
|
clearSeenErrors();
|
|
if(!Meteor.user())
|
|
throwError(i18n.t('You must be logged in.'));
|
|
|
|
var $target=$(e.target);
|
|
var name = $target.find('[name=name]').val();
|
|
var email = $target.find('[name=email]').val();
|
|
var user = this;
|
|
var update = {
|
|
"profile.name": name,
|
|
"profile.slug": slugify(name),
|
|
"profile.bio": $target.find('[name=bio]').val(),
|
|
"profile.email": email,
|
|
"profile.twitter": $target.find('[name=twitter]').val(),
|
|
"profile.github": $target.find('[name=github]').val(),
|
|
"profile.site": $target.find('[name=site]').val(),
|
|
"profile.notifications.users": $('input[name=notifications_users]:checked').length, // only actually used for admins
|
|
"profile.notifications.posts": $('input[name=notifications_posts]:checked').length,
|
|
"profile.notifications.comments": $('input[name=notifications_comments]:checked').length,
|
|
"profile.notifications.replies": $('input[name=notifications_replies]:checked').length
|
|
};
|
|
|
|
var old_password = $target.find('[name=old_password]').val();
|
|
var new_password = $target.find('[name=new_password]').val();
|
|
|
|
if(old_password && new_password){
|
|
Accounts.changePassword(old_password, new_password, function(error){
|
|
// TODO: interrupt update if there's an error at this point
|
|
if(error)
|
|
throwError(error.reason);
|
|
});
|
|
}
|
|
|
|
Meteor.users.update(user._id, {
|
|
$set: update
|
|
}, function(error){
|
|
if(error){
|
|
throwError(error.reason);
|
|
} else {
|
|
throwError(i18n.t('Profile updated'));
|
|
}
|
|
Deps.afterFlush(function() {
|
|
var element = $('.grid > .error');
|
|
$('html, body').animate({scrollTop: element.offset().top});
|
|
});
|
|
});
|
|
|
|
Meteor.call('changeEmail', email);
|
|
|
|
}
|
|
|
|
});
|