2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_email')].helpers({
|
2013-11-14 10:04:11 +09:00
|
|
|
user: function(){
|
|
|
|
return Meteor.user();
|
2014-08-12 17:47:11 +09:00
|
|
|
},
|
|
|
|
username: function () {
|
|
|
|
return getUserName(Meteor.user());
|
2013-11-14 10:04:11 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-07-05 11:24:28 +09:00
|
|
|
Template[getTemplate('user_email')].events({
|
2012-10-01 13:57:52 +09:00
|
|
|
'submit form': function(e){
|
|
|
|
e.preventDefault();
|
2014-12-06 17:34:08 +09:00
|
|
|
if(!Meteor.user())
|
|
|
|
flashMessage(i18n.t('you_must_be_logged_in'), 'error');
|
2012-10-01 13:59:23 +09:00
|
|
|
var $target=$(e.target);
|
2012-10-11 08:23:52 +09:00
|
|
|
var user=Session.get('selectedUserId')? Meteor.users.findOne(Session.get('selectedUserId')) : Meteor.user();
|
2012-10-01 13:57:52 +09:00
|
|
|
var update = {
|
2014-05-04 17:21:52 +01:00
|
|
|
"profile.email": $target.find('[name=email]').val(),
|
2014-05-04 18:48:47 +01:00
|
|
|
"username": $target.find('[name=username]').val(),
|
2014-06-17 15:20:01 +03:00
|
|
|
"slug": slugify($target.find('[name=username]').val())
|
2012-10-01 13:57:52 +09:00
|
|
|
};
|
2014-05-04 17:21:52 +01:00
|
|
|
|
2012-10-01 13:57:52 +09:00
|
|
|
// TODO: enable change email
|
2012-10-01 13:59:23 +09:00
|
|
|
var email = $target.find('[name=email]').val();
|
2012-10-01 13:57:52 +09:00
|
|
|
|
|
|
|
Meteor.users.update(user._id, {
|
|
|
|
$set: update
|
|
|
|
}, function(error){
|
|
|
|
if(error){
|
Replace "throwError" with "flashMessage" and type
Currently, ``throwError`` is used for all manner of messages, including
errors, "success" messages, and "info" messages. This makes appropriate
styling of the error message difficult. In addition, the name
``throwError`` seems to create confusion, implying that an error will
actually be thrown (e.g. stopping execution when a user isn't logged in
[0][1]), when in fact it just displays a message.
Replace ``throwError`` with ``flashMessage``, and reliably include a
message "type" (e.g. "error", "success", "info") every time. rename
``lib/errors.js`` to ``lib/messages.js`` to more accurately reflect its
function.
This commit doesn't rename the message collection (``Errors``), nor the
template responsible for rendering the messages (``error_item.html``) --
that should probably still be done, but has higher likelihood of
trouble for existing alternate themes and installations.
[0] https://github.com/TelescopeJS/Telescope/blob/6ccf7d7d4704d6a8e821fe48128f81c19983ffc9/client/views/users/user_edit.js#L43
[1] https://github.com/TelescopeJS/Telescope/blob/083a4c4dc48eca15fe9d4472e24e6b4e8adfc8d6/client/views/users/user_email.js#L13
2014-11-05 13:12:09 -07:00
|
|
|
flashMessage(error.reason, "error");
|
2012-10-01 13:57:52 +09:00
|
|
|
} else {
|
2014-12-06 17:34:08 +09:00
|
|
|
flashMessage(i18n.t('thanks_for_signing_up'), "success");
|
2014-08-05 12:25:26 +09:00
|
|
|
// Meteor.call('addCurrentUserToMailChimpList');
|
2012-10-01 14:52:32 +09:00
|
|
|
trackEvent("new sign-up", {'userId': user._id, 'auth':'twitter'});
|
2013-10-09 21:49:02 +09:00
|
|
|
Router.go('/');
|
2012-10-01 13:57:52 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-06-17 15:20:01 +03:00
|
|
|
});
|