Vulcan/client/views/users/user_email.js
Tom Coleman 72d8115b1b New router is working, to some degree.
I switched over to router 2.0, and refactored the permissions a bit.
There's still a bit of work needed to get the permissions fully up to speed.
2012-11-21 14:28:18 +11:00

40 lines
No EOL
1.1 KiB
JavaScript

Template.user_email.events = {
'submit form': function(e){
e.preventDefault();
if(!Meteor.user()) throwError('You must be logged in.');
var $target=$(e.target);
var user=Session.get('selectedUserId')? Meteor.users.findOne(Session.get('selectedUserId')) : Meteor.user();
var update = {
"profile.email": $target.find('[name=email]').val()
};
// TODO: enable change email
var email = $target.find('[name=email]').val();
Meteor.users.update(user._id, {
$set: update
}, function(error){
if(error){
throwError(error.reason);
} else {
throwError('Thanks for signing up!');
trackEvent("new sign-up", {'userId': user._id, 'auth':'twitter'});
Meteor.Router.navigate('/');
}
});
}
};
Template.user_email.profileIncomplete = function() {
return Meteor.user() && !this.loading && !userProfileComplete(this);
}
Template.user_email.user = function(){
var current_user=Meteor.user();
if(Session.get('selectedUserId') && !current_user.loading && current_user.isAdmin){
return Meteor.users.findOne(Session.get('selectedUserId'));
}else{
return current_user;
}
}