2013-01-19 18:24:18 +09:00
|
|
|
Template.user_edit.helpers({
|
|
|
|
profileIncomplete : function() {
|
2013-10-09 20:50:26 +09:00
|
|
|
return this && !this.loading && !userProfileComplete(this);
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-24 14:24:03 +09:00
|
|
|
userName: function(){
|
|
|
|
return getUserName(this);
|
|
|
|
},
|
2013-02-22 15:41:15 +09:00
|
|
|
userEmail : function(){
|
2013-10-09 20:50:26 +09:00
|
|
|
return getEmail(this);
|
2013-02-22 15:41:15 +09:00
|
|
|
},
|
2013-11-07 09:57:57 +09:00
|
|
|
getTwitter: function(){
|
2013-11-11 22:09:24 +02:00
|
|
|
return getTwitterName(this) || "";
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
|
|
|
getGitHub: function(){
|
2013-11-11 22:09:24 +02:00
|
|
|
return getGitHubName(this) || "";
|
2013-11-07 09:57:57 +09:00
|
|
|
},
|
2013-10-24 11:15:07 +09:00
|
|
|
profileUrl: function(){
|
2013-10-24 14:24:03 +09:00
|
|
|
return Meteor.absoluteUrl()+"users/"+this.slug;
|
2013-10-24 11:15:07 +09:00
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsPosts : function(){
|
|
|
|
return getUserSetting('notifications.posts') ? 'checked' : '';
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsComments : function(){
|
|
|
|
return getUserSetting('notifications.comments') ? 'checked' : '';
|
2013-01-19 18:24:18 +09:00
|
|
|
},
|
2013-10-23 10:21:08 +08:00
|
|
|
hasNotificationsReplies : function(){
|
|
|
|
return getUserSetting('notifications.replies') ? 'checked' : '';
|
2013-01-19 18:24:18 +09:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2012-09-19 09:03:25 +09:00
|
|
|
Template.user_edit.events = {
|
2012-10-01 13:08:46 +10:00
|
|
|
'submit form': function(e){
|
2012-09-19 09:03:25 +09:00
|
|
|
e.preventDefault();
|
2013-10-09 20:50:26 +09:00
|
|
|
|
|
|
|
if(!Meteor.user())
|
|
|
|
throwError('You must be logged in.');
|
|
|
|
|
2012-10-01 13:59:23 +09:00
|
|
|
var $target=$(e.target);
|
2013-10-24 11:15:07 +09:00
|
|
|
var name = $target.find('[name=name]').val();
|
2013-10-09 20:50:26 +09:00
|
|
|
var user = this;
|
2012-10-01 13:08:46 +10:00
|
|
|
var update = {
|
2013-10-24 11:15:07 +09:00
|
|
|
"profile.name": name,
|
|
|
|
"profile.slug": slugify(name),
|
2012-10-01 13:59:23 +09:00
|
|
|
"profile.bio": $target.find('[name=bio]').val(),
|
2013-01-19 18:24:18 +09:00
|
|
|
"profile.email": $target.find('[name=email]').val(),
|
2013-11-07 09:57:57 +09:00
|
|
|
"profile.twitter": $target.find('[name=twitter]').val(),
|
|
|
|
"profile.github": $target.find('[name=github]').val(),
|
|
|
|
"profile.site": $target.find('[name=site]').val(),
|
2013-10-23 10:21:08 +08:00
|
|
|
"profile.notifications.posts": $('input[name=notifications_posts]:checked').length,
|
|
|
|
"profile.notifications.comments": $('input[name=notifications_comments]:checked').length,
|
2013-10-23 19:43:42 +09:00
|
|
|
"profile.notifications.replies": $('input[name=notifications_replies]:checked').length,
|
|
|
|
"invitesCount": parseInt($target.find('[name=invitesCount]').val())
|
2012-10-01 13:08:46 +10:00
|
|
|
};
|
2013-10-23 19:43:42 +09:00
|
|
|
|
2012-10-01 13:57:52 +09:00
|
|
|
var old_password = $target.find('[name=old_password]').val();
|
|
|
|
var new_password = $target.find('[name=new_password]').val();
|
2012-10-01 13:08:46 +10:00
|
|
|
|
2012-09-19 09:03:25 +09:00
|
|
|
if(old_password && new_password){
|
2013-10-21 19:01:52 +08:00
|
|
|
Accounts.changePassword(old_password, new_password, function(error){
|
|
|
|
// TODO: interrupt update if there's an error at this point
|
|
|
|
if(error)
|
|
|
|
throwError(error.reason);
|
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
2012-10-01 13:08:46 +10:00
|
|
|
|
|
|
|
Meteor.users.update(user._id, {
|
|
|
|
$set: update
|
|
|
|
}, function(error){
|
|
|
|
if(error){
|
|
|
|
throwError(error.reason);
|
|
|
|
} else {
|
|
|
|
throwError('Profile updated');
|
|
|
|
}
|
|
|
|
});
|
2012-09-19 09:03:25 +09:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:20:07 -07:00
|
|
|
};
|