Convert Ui Account Package to Js

pull/6795/head
Martin Schoeler 8 years ago
parent 1ced54e6a8
commit 05391b9585
  1. 4
      packages/rocketchat-ui-account/client/account.coffee
  2. 6
      packages/rocketchat-ui-account/client/account.js
  3. 21
      packages/rocketchat-ui-account/client/accountFlex.coffee
  4. 27
      packages/rocketchat-ui-account/client/accountFlex.js
  5. 145
      packages/rocketchat-ui-account/client/accountPreferences.coffee
  6. 188
      packages/rocketchat-ui-account/client/accountPreferences.js
  7. 203
      packages/rocketchat-ui-account/client/accountProfile.coffee
  8. 240
      packages/rocketchat-ui-account/client/accountProfile.js
  9. 14
      packages/rocketchat-ui-account/client/avatar/avatar.coffee
  10. 15
      packages/rocketchat-ui-account/client/avatar/avatar.js
  11. 105
      packages/rocketchat-ui-account/client/avatar/prompt.coffee
  12. 136
      packages/rocketchat-ui-account/client/avatar/prompt.js
  13. 13
      packages/rocketchat-ui-account/package.js

@ -1,4 +0,0 @@
Template.account.onRendered ->
Tracker.afterFlush ->
SideNav.setFlex "accountFlex"
SideNav.openFlex()

@ -0,0 +1,6 @@
Template.account.onRendered(function() {
return Tracker.afterFlush(function() {
SideNav.setFlex('accountFlex');
return SideNav.openFlex();
});
});

@ -1,21 +0,0 @@
Template.accountFlex.events
'mouseenter header': ->
SideNav.overArrow()
'mouseleave header': ->
SideNav.leaveArrow()
'click header': ->
SideNav.closeFlex()
'click .cancel-settings': ->
SideNav.closeFlex()
'click .account-link': ->
menu.close()
Template.accountFlex.helpers
allowUserProfileChange: ->
return RocketChat.settings.get("Accounts_AllowUserProfileChange")
allowUserAvatarChange: ->
return RocketChat.settings.get("Accounts_AllowUserAvatarChange")

@ -0,0 +1,27 @@
/*globals menu */
Template.accountFlex.events({
'mouseenter header'() {
return SideNav.overArrow();
},
'mouseleave header'() {
return SideNav.leaveArrow();
},
'click header'() {
return SideNav.closeFlex();
},
'click .cancel-settings'() {
return SideNav.closeFlex();
},
'click .account-link'() {
return menu.close();
}
});
Template.accountFlex.helpers({
allowUserProfileChange() {
return RocketChat.settings.get('Accounts_AllowUserProfileChange');
},
allowUserAvatarChange() {
return RocketChat.settings.get('Accounts_AllowUserAvatarChange');
}
});

@ -1,145 +0,0 @@
import toastr from 'toastr'
Template.accountPreferences.helpers
audioAssets: ->
return RocketChat.CustomSounds && RocketChat.CustomSounds.getList && RocketChat.CustomSounds.getList() || [];
newMessageNotification: ->
return Meteor.user()?.settings?.preferences?.newMessageNotification || 'chime'
newRoomNotification: ->
return Meteor.user()?.settings?.preferences?.newRoomNotification || 'door'
languages: ->
languages = TAPi18n.getLanguages()
result = []
for key, language of languages
result.push _.extend(language, { key: key })
return _.sortBy(result, 'key')
userLanguage: (key) ->
return (Meteor.user().language or defaultUserLanguage())?.split('-').shift().toLowerCase() is key
checked: (property, value, defaultValue) ->
if not Meteor.user()?.settings?.preferences?[property]? and defaultValue is true
currentValue = value
else if Meteor.user()?.settings?.preferences?[property]?
currentValue = !!Meteor.user()?.settings?.preferences?[property]
return currentValue is value
selected: (property, value, defaultValue) ->
if not Meteor.user()?.settings?.preferences?[property]
return defaultValue is true
else
return Meteor.user()?.settings?.preferences?[property] == value
highlights: ->
return Meteor.user()?.settings?.preferences?['highlights']?.join(', ')
desktopNotificationEnabled: ->
return (KonchatNotification.notificationStatus.get() is 'granted') or (window.Notification && Notification.permission is "granted")
desktopNotificationDisabled: ->
return (KonchatNotification.notificationStatus.get() is 'denied') or (window.Notification && Notification.permission is "denied")
desktopNotificationDuration: ->
return Meteor.user()?.settings?.preferences?.desktopNotificationDuration - 0
showRoles: ->
return RocketChat.settings.get('UI_DisplayRoles');
Template.accountPreferences.onCreated ->
settingsTemplate = this.parentTemplate(3)
settingsTemplate.child ?= []
settingsTemplate.child.push this
@useEmojis = new ReactiveVar not Meteor.user()?.settings?.preferences?.useEmojis? or Meteor.user().settings.preferences.useEmojis
instance = @
@autorun ->
if instance.useEmojis.get()
Tracker.afterFlush ->
$('#convertAsciiEmoji').show()
else
Tracker.afterFlush ->
$('#convertAsciiEmoji').hide()
@clearForm = ->
@find('#language').value = localStorage.getItem('userLanguage')
@save = ->
instance = @
data = {}
reload = false
selectedLanguage = $('#language').val()
if localStorage.getItem('userLanguage') isnt selectedLanguage
localStorage.setItem 'userLanguage', selectedLanguage
data.language = selectedLanguage
reload = true
data.newRoomNotification = $('select[name=newRoomNotification]').val()
data.newMessageNotification = $('select[name=newMessageNotification]').val()
data.useEmojis = $('input[name=useEmojis]:checked').val()
data.convertAsciiEmoji = $('input[name=convertAsciiEmoji]:checked').val()
data.saveMobileBandwidth = $('input[name=saveMobileBandwidth]:checked').val()
data.collapseMediaByDefault = $('input[name=collapseMediaByDefault]:checked').val()
data.viewMode = parseInt($('#viewMode').find('select').val())
data.hideUsernames = $('#hideUsernames').find('input:checked').val()
data.hideRoles = $('#hideRoles').find('input:checked').val()
data.hideFlexTab = $('#hideFlexTab').find('input:checked').val()
data.hideAvatars = $('#hideAvatars').find('input:checked').val()
data.mergeChannels = $('#mergeChannels').find('input:checked').val()
data.sendOnEnter = $('#sendOnEnter').find('select').val()
data.unreadRoomsMode = $('input[name=unreadRoomsMode]:checked').val()
data.autoImageLoad = $('input[name=autoImageLoad]:checked').val()
data.emailNotificationMode = $('select[name=emailNotificationMode]').val()
data.highlights = _.compact(_.map($('[name=highlights]').val().split(','), (e) -> return _.trim(e)))
data.desktopNotificationDuration = $('input[name=desktopNotificationDuration]').val()
data.unreadAlert = $('#unreadAlert').find('input:checked').val()
Meteor.call 'saveUserPreferences', data, (error, results) ->
if results
toastr.success t('Preferences_saved')
instance.clearForm()
if reload
setTimeout ->
Meteor._reload.reload()
, 1000
if error
handleError(error)
Template.accountPreferences.onRendered ->
Tracker.afterFlush ->
SideNav.setFlex "accountFlex"
SideNav.openFlex()
Template.accountPreferences.events
'click .submit button': (e, t) ->
t.save()
'change input[name=useEmojis]': (e, t) ->
t.useEmojis.set $(e.currentTarget).val() is '1'
'click .enable-notifications': ->
KonchatNotification.getDesktopPermission()
'click .test-notifications': ->
KonchatNotification.notify
duration: $('input[name=desktopNotificationDuration]').val()
payload:
sender:
username: 'rocket.cat'
title: TAPi18n.__('Desktop_Notification_Test')
text: TAPi18n.__('This_is_a_desktop_notification')
'change .audio': (e) ->
e.preventDefault()
audio = $(e.currentTarget).val()
if audio is 'none'
return
if audio
$audio = $('audio#' + audio)
$audio?[0]?.play()

@ -0,0 +1,188 @@
/*globals defaultUserLanguage, KonchatNotification */
import toastr from 'toastr';
Template.accountPreferences.helpers({
audioAssets() {
return (RocketChat.CustomSounds && RocketChat.CustomSounds.getList && RocketChat.CustomSounds.getList()) || [];
},
newMessageNotification() {
const user = Meteor.user();
return (user && user.settings && user.settings.preferences && user.settings.preferences.newMessageNotification) || 'chime';
},
newRoomNotification() {
const user = Meteor.user();
return (user && user.settings && user.settings.preferences && user.settings.preferences.newRoomNotification) || 'door';
},
languages() {
const languages = TAPi18n.getLanguages();
const result = [];
Object.keys(languages).forEach((key) => {
const language = languages[key];
result.push(_.extend(language, {
key
}));
});
return _.sortBy(result, 'key');
},
userLanguage(key) {
const user = Meteor.user();
let result = undefined;
if (user.language) {
result = user.language.split('-').shift().toLowerCase() === key;
} else if (defaultUserLanguage()) {
result = defaultUserLanguage().split('-').shift().toLowerCase() === key;
}
return result;
},
checked(property, value, defaultValue) {
const user = Meteor.user();
let currentValue;
if (user && user.settings && user.settings.preferences && user.settings.preferences[property] && defaultValue === true) {
currentValue = value;
} else if (user && user.settings && user.settings.preferences && user.settings.preferences[property]) {
currentValue = !!user.settings.preferences[property];
}
return currentValue === value;
},
selected(property, value, defaultValue) {
const user = Meteor.user();
if (!(user && user.settings && user.settings.preferences && user.settings.preferences[property])) {
return defaultValue === true;
} else {
return (user && user.settings && user.settings.preferences && user.settings.preferences[property]) === value;
}
},
highlights() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences['highlights'] && user.settings.preferences['highlights'].join(', ');
},
desktopNotificationEnabled() {
return (KonchatNotification.notificationStatus.get() === 'granted') || (window.Notification && Notification.permission === 'granted');
},
desktopNotificationDisabled() {
return (KonchatNotification.notificationStatus.get() === 'denied') || (window.Notification && Notification.permission === 'denied');
},
desktopNotificationDuration() {
const user = Meteor.user();
return user && user.settings && user.settings.preferences && user.settings.preferences.desktopNotificationDuration;
},
showRoles() {
return RocketChat.settings.get('UI_DisplayRoles');
}
});
Template.accountPreferences.onCreated(function() {
const settingsTemplate = this.parentTemplate(3);
if (settingsTemplate.child == null) {
settingsTemplate.child = [];
}
settingsTemplate.child.push(this);
const user = Meteor.user();
if (user && user.settings && user.settings.preferences) {
this.useEmojis = new ReactiveVar(user.settings.preferences.desktopNotificationDuration == null || user.settings.preferences.useEmojis);
}
let instance = this;
this.autorun(() => {
if (instance.useEmojis && instance.useEmojis.get()) {
return Tracker.afterFlush(function() {
return $('#convertAsciiEmoji').show();
});
} else {
return Tracker.afterFlush(function() {
return $('#convertAsciiEmoji').hide();
});
}
});
this.clearForm = function() {
return this.find('#language').value = localStorage.getItem('userLanguage');
};
return this.save = function() {
instance = this;
const data = {};
let reload = false;
const selectedLanguage = $('#language').val();
if (localStorage.getItem('userLanguage') !== selectedLanguage) {
localStorage.setItem('userLanguage', selectedLanguage);
data.language = selectedLanguage;
reload = true;
}
data.newRoomNotification = $('select[name=newRoomNotification]').val();
data.newMessageNotification = $('select[name=newMessageNotification]').val();
data.useEmojis = $('input[name=useEmojis]:checked').val();
data.convertAsciiEmoji = $('input[name=convertAsciiEmoji]:checked').val();
data.saveMobileBandwidth = $('input[name=saveMobileBandwidth]:checked').val();
data.collapseMediaByDefault = $('input[name=collapseMediaByDefault]:checked').val();
data.viewMode = parseInt($('#viewMode').find('select').val());
data.hideUsernames = $('#hideUsernames').find('input:checked').val();
data.hideRoles = $('#hideRoles').find('input:checked').val();
data.hideFlexTab = $('#hideFlexTab').find('input:checked').val();
data.hideAvatars = $('#hideAvatars').find('input:checked').val();
data.mergeChannels = $('#mergeChannels').find('input:checked').val();
data.sendOnEnter = $('#sendOnEnter').find('select').val();
data.unreadRoomsMode = $('input[name=unreadRoomsMode]:checked').val();
data.autoImageLoad = $('input[name=autoImageLoad]:checked').val();
data.emailNotificationMode = $('select[name=emailNotificationMode]').val();
data.highlights = _.compact(_.map($('[name=highlights]').val().split(','), function(e) {
return _.trim(e);
}));
data.desktopNotificationDuration = $('input[name=desktopNotificationDuration]').val();
data.unreadAlert = $('#unreadAlert').find('input:checked').val();
return Meteor.call('saveUserPreferences', data, function(error, results) {
if (results) {
toastr.success(t('Preferences_saved'));
instance.clearForm();
if (reload) {
setTimeout(function() {
return Meteor._reload.reload();
}, 1000);
}
}
if (error) {
return handleError(error);
}
});
};
});
Template.accountPreferences.onRendered(function() {
return Tracker.afterFlush(function() {
SideNav.setFlex('accountFlex');
return SideNav.openFlex();
});
});
Template.accountPreferences.events({
'click .submit button'(e, t) {
return t.save();
},
'change input[name=useEmojis]'(e, t) {
return t.useEmojis.set($(e.currentTarget).val() === '1');
},
'click .enable-notifications'() {
return KonchatNotification.getDesktopPermission();
},
'click .test-notifications'() {
return KonchatNotification.notify({
duration: $('input[name=desktopNotificationDuration]').val(),
payload: {
sender: {
username: 'rocket.cat'
}
},
title: TAPi18n.__('Desktop_Notification_Test'),
text: TAPi18n.__('This_is_a_desktop_notification')
});
},
'change .audio'(e) {
e.preventDefault();
const audio = $(e.currentTarget).val();
if (audio === 'none') {
return;
}
if (audio) {
const $audio = $(`audio#${ audio }`);
return $audio && $audio[0] && $audio.play();
}
}
});

@ -1,203 +0,0 @@
import toastr from 'toastr'
Template.accountProfile.helpers
allowDeleteOwnAccount: ->
return RocketChat.settings.get('Accounts_AllowDeleteOwnAccount')
realname: ->
return Meteor.user().name
username: ->
return Meteor.user().username
email: ->
return Meteor.user().emails?[0]?.address
emailVerified: ->
return Meteor.user().emails?[0]?.verified
allowUsernameChange: ->
return RocketChat.settings.get("Accounts_AllowUsernameChange") and RocketChat.settings.get("LDAP_Enable") isnt true
allowEmailChange: ->
return RocketChat.settings.get("Accounts_AllowEmailChange")
usernameChangeDisabled: ->
return t('Username_Change_Disabled')
allowPasswordChange: ->
return RocketChat.settings.get("Accounts_AllowPasswordChange")
passwordChangeDisabled: ->
return t('Password_Change_Disabled')
customFields: ->
return Meteor.user().customFields
Template.accountProfile.onCreated ->
settingsTemplate = this.parentTemplate(3)
settingsTemplate.child ?= []
settingsTemplate.child.push this
@clearForm = ->
@find('#password').value = ''
@changePassword = (newPassword, callback) ->
instance = @
if not newPassword
return callback()
else
if !RocketChat.settings.get("Accounts_AllowPasswordChange")
toastr.remove();
toastr.error t('Password_Change_Disabled')
instance.clearForm()
return
@save = (typedPassword) ->
instance = @
data = { typedPassword: typedPassword }
if _.trim($('#password').val()) and RocketChat.settings.get("Accounts_AllowPasswordChange")
data.newPassword = $('#password').val()
if _.trim $('#realname').val()
data.realname = _.trim $('#realname').val()
if _.trim($('#username').val()) isnt Meteor.user().username
if !RocketChat.settings.get("Accounts_AllowUsernameChange")
toastr.remove();
toastr.error t('Username_Change_Disabled')
instance.clearForm()
return
else
data.username = _.trim $('#username').val()
if _.trim($('#email').val()) isnt Meteor.user().emails?[0]?.address
if !RocketChat.settings.get("Accounts_AllowEmailChange")
toastr.remove();
toastr.error t('Email_Change_Disabled')
instance.clearForm()
return
else
data.email = _.trim $('#email').val()
customFields = {}
$('[data-customfield=true]').each () ->
customFields[this.name] = $(this).val() or ''
Meteor.call 'saveUserProfile', data, customFields, (error, results) ->
if results
toastr.remove();
toastr.success t('Profile_saved_successfully')
swal.close()
instance.clearForm()
if error
toastr.remove();
handleError(error)
Template.accountProfile.onRendered ->
Tracker.afterFlush ->
# this should throw an error-template
FlowRouter.go("home") if !RocketChat.settings.get("Accounts_AllowUserProfileChange")
SideNav.setFlex "accountFlex"
SideNav.openFlex()
Template.accountProfile.events
'click .submit button': (e, instance) ->
user = Meteor.user()
reqPass = ((_.trim($('#email').val()) isnt user?.emails?[0]?.address) or _.trim($('#password').val())) and s.trim(user?.services?.password?.bcrypt)
unless reqPass
return instance.save()
swal
title: t("Please_enter_your_password"),
text: t("For_your_security_you_must_enter_your_current_password_to_continue"),
type: "input",
inputType: "password",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Save'),
cancelButtonText: t('Cancel')
, (typedPassword) =>
if typedPassword
toastr.remove();
toastr.warning(t("Please_wait_while_your_profile_is_being_saved"));
instance.save(SHA256(typedPassword))
else
swal.showInputError(t("You_need_to_type_in_your_password_in_order_to_do_this"));
return false;
'click .logoutOthers button': (event, templateInstance) ->
Meteor.logoutOtherClients (error) ->
if error
toastr.remove();
handleError(error)
else
toastr.remove();
toastr.success t('Logged_out_of_other_clients_successfully')
'click .delete-account button': (e) ->
e.preventDefault();
if s.trim Meteor.user()?.services?.password?.bcrypt
swal
title: t("Are_you_sure_you_want_to_delete_your_account"),
text: t("If_you_are_sure_type_in_your_password"),
type: "input",
inputType: "password",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Delete')
cancelButtonText: t('Cancel')
, (typedPassword) =>
if typedPassword
toastr.remove();
toastr.warning(t("Please_wait_while_your_account_is_being_deleted"));
Meteor.call 'deleteUserOwnAccount', SHA256(typedPassword), (error, results) ->
if error
toastr.remove();
swal.showInputError(t("Your_password_is_wrong"));
else
swal.close();
else
swal.showInputError(t("You_need_to_type_in_your_password_in_order_to_do_this"));
return false;
else
swal
title: t("Are_you_sure_you_want_to_delete_your_account"),
text: t("If_you_are_sure_type_in_your_username"),
type: "input",
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Delete')
cancelButtonText: t('Cancel')
, (deleteConfirmation) =>
if deleteConfirmation is Meteor.user()?.username
toastr.remove();
toastr.warning(t("Please_wait_while_your_account_is_being_deleted"));
Meteor.call 'deleteUserOwnAccount', deleteConfirmation, (error, results) ->
if error
toastr.remove();
swal.showInputError(t("Your_password_is_wrong"));
else
swal.close();
else
swal.showInputError(t("You_need_to_type_in_your_username_in_order_to_do_this"));
return false;
'click #resend-verification-email': (e) ->
e.preventDefault()
e.currentTarget.innerHTML = e.currentTarget.innerHTML + ' ...'
e.currentTarget.disabled = true
Meteor.call 'sendConfirmationEmail', Meteor.user().emails?[0]?.address, (error, results) =>
if results
toastr.success t('Verification_email_sent')
else if error
handleError(error)
e.currentTarget.innerHTML = e.currentTarget.innerHTML.replace(' ...', '')
e.currentTarget.disabled = false

@ -0,0 +1,240 @@
import toastr from 'toastr';
Template.accountProfile.helpers({
allowDeleteOwnAccount() {
return RocketChat.settings.get('Accounts_AllowDeleteOwnAccount');
},
realname() {
return Meteor.user().name;
},
username() {
return Meteor.user().username;
},
email() {
const user = Meteor.user();
return user.emails && user.emails[0] && user.emails[0].address;
},
emailVerified() {
const user = Meteor.user();
return user.emails && user.emails[0] && user.emails[0].verified;
},
allowUsernameChange() {
return RocketChat.settings.get('Accounts_AllowUsernameChange') && RocketChat.settings.get('LDAP_Enable') !== true;
},
allowEmailChange() {
return RocketChat.settings.get('Accounts_AllowEmailChange');
},
usernameChangeDisabled() {
return t('Username_Change_Disabled');
},
allowPasswordChange() {
return RocketChat.settings.get('Accounts_AllowPasswordChange');
},
passwordChangeDisabled() {
return t('Password_Change_Disabled');
},
customFields() {
return Meteor.user().customFields;
}
});
Template.accountProfile.onCreated(function() {
const settingsTemplate = this.parentTemplate(3);
if (settingsTemplate.child == null) {
settingsTemplate.child = [];
}
settingsTemplate.child.push(this);
this.clearForm = function() {
return this.find('#password').value = '';
};
this.changePassword = function(newPassword, callback) {
const instance = this;
if (!newPassword) {
return callback();
} else if (!RocketChat.settings.get('Accounts_AllowPasswordChange')) {
toastr.remove();
toastr.error(t('Password_Change_Disabled'));
instance.clearForm();
}
};
return this.save = function(typedPassword) {
const instance = this;
const data = {
typedPassword
};
if (_.trim($('#password').val()) && RocketChat.settings.get('Accounts_AllowPasswordChange')) {
data.newPassword = $('#password').val();
}
if (_.trim($('#realname').val())) {
data.realname = _.trim($('#realname').val());
}
if (_.trim($('#username').val()) !== Meteor.user().username) {
if (!RocketChat.settings.get('Accounts_AllowUsernameChange')) {
toastr.remove();
toastr.error(t('Username_Change_Disabled'));
instance.clearForm();
return;
} else {
data.username = _.trim($('#username').val());
}
}
const user = Meteor.user();
if (_.trim($('#email').val()) !== (user.emails && user.emails[0] && user.emails[0].address)) {
if (!RocketChat.settings.get('Accounts_AllowEmailChange')) {
toastr.remove();
toastr.error(t('Email_Change_Disabled'));
instance.clearForm();
return;
} else {
data.email = _.trim($('#email').val());
}
}
const customFields = {};
$('[data-customfield=true]').each(function() {
return customFields[this.name] = $(this).val() || '';
});
return Meteor.call('saveUserProfile', data, customFields, function(error, results) {
if (results) {
toastr.remove();
toastr.success(t('Profile_saved_successfully'));
swal.close();
instance.clearForm();
}
if (error) {
toastr.remove();
return handleError(error);
}
});
};
});
Template.accountProfile.onRendered(function() {
return Tracker.afterFlush(function() {
if (!RocketChat.settings.get('Accounts_AllowUserProfileChange')) {
FlowRouter.go('home');
}
SideNav.setFlex('accountFlex');
return SideNav.openFlex();
});
});
Template.accountProfile.events({
'click .submit button'(e, instance) {
const user = Meteor.user();
const reqPass = ((_.trim($('#email').val()) !== (user && user.emails && user.emails[0] && user.emails[0].address)) || _.trim($('#password').val())) && (user && user.services && user.services.password && s.trim(user.services.password.bcrypt));
if (!reqPass) {
return instance.save();
}
return swal({
title: t('Please_enter_your_password'),
text: t('For_your_security_you_must_enter_your_current_password_to_continue'),
type: 'input',
inputType: 'password',
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Save'),
cancelButtonText: t('Cancel')
}, () => {
return function(typedPassword) {
if (typedPassword) {
toastr.remove();
toastr.warning(t('Please_wait_while_your_profile_is_being_saved'));
return instance.save(SHA256(typedPassword));
} else {
swal.showInputError(t('You_need_to_type_in_your_password_in_order_to_do_this'));
return false;
}
};
});
},
'click .logoutOthers button'() {
return Meteor.logoutOtherClients(function(error) {
if (error) {
toastr.remove();
return handleError(error);
} else {
toastr.remove();
return toastr.success(t('Logged_out_of_other_clients_successfully'));
}
});
},
'click .delete-account button'(e) {
e.preventDefault();
const user = Meteor.user();
if (s.trim(user && user.services && user.services.password && user.services.password.bcrypt)) {
return swal({
title: t('Are_you_sure_you_want_to_delete_your_account'),
text: t('If_you_are_sure_type_in_your_password'),
type: 'input',
inputType: 'password',
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Delete'),
cancelButtonText: t('Cancel')
}, () => {
return function(typedPassword) {
if (typedPassword) {
toastr.remove();
toastr.warning(t('Please_wait_while_your_account_is_being_deleted'));
return Meteor.call('deleteUserOwnAccount', SHA256(typedPassword), function(error) {
if (error) {
toastr.remove();
return swal.showInputError(t('Your_password_is_wrong'));
} else {
return swal.close();
}
});
} else {
swal.showInputError(t('You_need_to_type_in_your_password_in_order_to_do_this'));
return false;
}
};
});
} else {
return swal({
title: t('Are_you_sure_you_want_to_delete_your_account'),
text: t('If_you_are_sure_type_in_your_username'),
type: 'input',
showCancelButton: true,
closeOnConfirm: false,
confirmButtonText: t('Delete'),
cancelButtonText: t('Cancel')
}, () => {
return function(deleteConfirmation) {
const user = Meteor.user();
if (deleteConfirmation === (user && user.username)) {
toastr.remove();
toastr.warning(t('Please_wait_while_your_account_is_being_deleted'));
return Meteor.call('deleteUserOwnAccount', deleteConfirmation, function(error) {
if (error) {
toastr.remove();
return swal.showInputError(t('Your_password_is_wrong'));
} else {
return swal.close();
}
});
} else {
swal.showInputError(t('You_need_to_type_in_your_username_in_order_to_do_this'));
return false;
}
};
});
}
},
'click #resend-verification-email'(e) {
const user = Meteor.user();
e.preventDefault();
e.currentTarget.innerHTML = `${ e.currentTarget.innerHTML } ...`;
e.currentTarget.disabled = true;
return Meteor.call('sendConfirmationEmail', user.emails && user.emails[0] && user.emails[0].address(() => {
return function(error, results) {
if (results) {
toastr.success(t('Verification_email_sent'));
} else if (error) {
handleError(error);
}
e.currentTarget.innerHTML = e.currentTarget.innerHTML.replace(' ...', '');
return e.currentTarget.disabled = false;
};
}));
}
});

@ -1,14 +0,0 @@
Template.avatar.helpers
imageUrl: ->
username = this.username
if not username? and this.userId?
username = Meteor.users.findOne(this.userId)?.username
if not username?
return
Session.get "avatar_random_#{username}"
url = getAvatarUrlFromUsername(username)
return "background-image:url(#{url});"

@ -0,0 +1,15 @@
Template.avatar.helpers({
imageUrl() {
let username = this.username;
if ((username == null) && (this.userId != null)) {
const user = Meteor.users.findOne(this.userId);
username = user && user.username;
}
if (username == null) {
return;
}
Session.get(`avatar_random_${ username }`);
const url = getAvatarUrlFromUsername(username);
return `background-image:url(${ url });`;
}
});

@ -1,105 +0,0 @@
import toastr from 'toastr'
Template.avatarPrompt.onCreated ->
self = this
self.suggestions = new ReactiveVar
self.upload = new ReactiveVar
self.getSuggestions = ->
self.suggestions.set undefined
Meteor.call 'getAvatarSuggestion', (error, avatars) ->
self.suggestions.set
ready: true
avatars: avatars
self.getSuggestions()
Template.avatarPrompt.onRendered ->
Tracker.afterFlush ->
# this should throw an error-template
FlowRouter.go("home") if !RocketChat.settings.get("Accounts_AllowUserAvatarChange")
SideNav.setFlex "accountFlex"
SideNav.openFlex()
Template.avatarPrompt.helpers
suggestions: ->
return Template.instance().suggestions.get()
suggestAvatar: (service) ->
suggestions = Template.instance().suggestions.get()
return RocketChat.settings.get("Accounts_OAuth_#{_.capitalize service}") and not suggestions.avatars[service]
upload: ->
return Template.instance().upload.get()
username: ->
return Meteor.user()?.username
initialsUsername: ->
return '@'+Meteor.user()?.username
Template.avatarPrompt.events
'click .select-service': ->
if @service is 'initials'
Meteor.call 'resetAvatar', (err) ->
if err?.details?.timeToReset?
toastr.error t('error-too-many-requests', { seconds: parseInt(err.details.timeToReset / 1000) })
else
toastr.success t('Avatar_changed_successfully')
RocketChat.callbacks.run('userAvatarSet', 'initials')
else if @service is 'url'
if _.trim $('#avatarurl').val()
Meteor.call 'setAvatarFromService', $('#avatarurl').val(), '', @service, (err) ->
if err
if err.details?.timeToReset?
toastr.error t('error-too-many-requests', { seconds: parseInt(err.details.timeToReset / 1000) })
else
toastr.error t('Avatar_url_invalid_or_error')
else
toastr.success t('Avatar_changed_successfully')
RocketChat.callbacks.run('userAvatarSet', 'url')
else
toastr.error t('Please_enter_value_for_url')
else
tmpService = @service
Meteor.call 'setAvatarFromService', @blob, @contentType, @service, (err) ->
if err?.details?.timeToReset?
toastr.error t('error-too-many-requests', { seconds: parseInt(err.details.timeToReset / 1000) })
else
toastr.success t('Avatar_changed_successfully')
RocketChat.callbacks.run('userAvatarSet', tmpService)
'click .login-with-service': (event, template) ->
loginWithService = "loginWith#{_.capitalize(this)}"
serviceConfig = {}
Meteor[loginWithService] serviceConfig, (error) ->
if error?.error is 'github-no-public-email'
alert t("github_no_public_email")
return
console.log error
if error?
toastr.error error.message
return
template.getSuggestions()
'change .avatar-file-input': (event, template) ->
e = event.originalEvent or event
files = e.target.files
if not files or files.length is 0
files = e.dataTransfer?.files or []
for blob in files
if not /image\/.+/.test blob.type
return
reader = new FileReader()
reader.readAsDataURL(blob)
reader.onloadend = ->
template.upload.set
service: 'upload'
contentType: blob.type
blob: reader.result
RocketChat.callbacks.run('userAvatarSet', 'upload')

@ -0,0 +1,136 @@
import toastr from 'toastr';
Template.avatarPrompt.onCreated(function() {
const self = this;
self.suggestions = new ReactiveVar;
self.upload = new ReactiveVar;
self.getSuggestions = function() {
self.suggestions.set(undefined);
return Meteor.call('getAvatarSuggestion', function(error, avatars) {
return self.suggestions.set({
ready: true,
avatars
});
});
};
return self.getSuggestions();
});
Template.avatarPrompt.onRendered(function() {
return Tracker.afterFlush(function() {
if (!RocketChat.settings.get('Accounts_AllowUserAvatarChange')) {
FlowRouter.go('home');
}
SideNav.setFlex('accountFlex');
return SideNav.openFlex();
});
});
Template.avatarPrompt.helpers({
suggestions() {
return Template.instance().suggestions.get();
},
suggestAvatar(service) {
const suggestions = Template.instance().suggestions.get();
return RocketChat.settings.get(`Accounts_OAuth_${ _.capitalize(service) }`) && !suggestions.avatars[service];
},
upload() {
return Template.instance().upload.get();
},
username() {
const user = Meteor.user();
return user && user.username;
},
initialsUsername() {
const user = Meteor.user();
return `@${ user && user.username }`;
}
});
Template.avatarPrompt.events({
'click .select-service'() {
let tmpService;
if (this.service === 'initials') {
return Meteor.call('resetAvatar', function(err) {
if (err && err.details.timeToReset && err.details.timeToReset) {
return toastr.error(t('error-too-many-requests', {
seconds: parseInt(err.details.timeToReset / 1000)
}));
} else {
toastr.success(t('Avatar_changed_successfully'));
return RocketChat.callbacks.run('userAvatarSet', 'initials');
}
});
} else if (this.service === 'url') {
if (_.trim($('#avatarurl').val())) {
return Meteor.call('setAvatarFromService', $('#avatarurl').val(), '', this.service, function(err) {
if (err) {
if (err.details.timeToReset && err.details.timeToReset) {
return toastr.error(t('error-too-many-requests', {
seconds: parseInt(err.details.timeToReset / 1000)
}));
} else {
return toastr.error(t('Avatar_url_invalid_or_error'));
}
} else {
toastr.success(t('Avatar_changed_successfully'));
return RocketChat.callbacks.run('userAvatarSet', 'url');
}
});
} else {
return toastr.error(t('Please_enter_value_for_url'));
}
} else {
tmpService = this.service;
return Meteor.call('setAvatarFromService', this.blob, this.contentType, this.service, function(err) {
if (err && err.details.timeToReset && err.details.timeToReset) {
return toastr.error(t('error-too-many-requests', {
seconds: parseInt(err.details.timeToReset / 1000)
}));
} else {
toastr.success(t('Avatar_changed_successfully'));
return RocketChat.callbacks.run('userAvatarSet', tmpService);
}
});
}
},
'click .login-with-service'(event, template) {
const loginWithService = `loginWith${ _.capitalize(this) }`;
const serviceConfig = {};
return Meteor[loginWithService](serviceConfig, function(error) {
if ((error && error.error) === 'github-no-public-email') {
alert(t('github_no_public_email'));
return;
}
console.log(error);
if (error != null) {
toastr.error(error.message);
return;
}
return template.getSuggestions();
});
},
'change .avatar-file-input'(event, template) {
const e = event.originalEvent || event;
let files = e.target.files;
if (!files || files.length === 0) {
files = (e.dataTransfer && e.dataTransfer.files) || [];
}
console.log(files);
Object.keys(files).forEach((key) => {
const blob = files[key];
if (!/image\/.+/.test(blob.type)) {
return;
}
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
template.upload.set({
service: 'upload',
contentType: blob.type,
blob: reader.result
});
return RocketChat.callbacks.run('userAvatarSet', 'upload');
};
});
}
});

@ -14,7 +14,6 @@ Package.onUse(function(api) {
api.use([
'ecmascript',
'templating',
'coffeescript',
'underscore',
'rocketchat:lib',
'sha'
@ -27,12 +26,12 @@ Package.onUse(function(api) {
api.addFiles('client/avatar/avatar.html', 'client');
api.addFiles('client/avatar/prompt.html', 'client');
api.addFiles('client/account.coffee', 'client');
api.addFiles('client/accountFlex.coffee', 'client');
api.addFiles('client/accountPreferences.coffee', 'client');
api.addFiles('client/accountProfile.coffee', 'client');
api.addFiles('client/avatar/avatar.coffee', 'client');
api.addFiles('client/avatar/prompt.coffee', 'client');
api.addFiles('client/account.js', 'client');
api.addFiles('client/accountFlex.js', 'client');
api.addFiles('client/accountPreferences.js', 'client');
api.addFiles('client/accountProfile.js', 'client');
api.addFiles('client/avatar/avatar.js', 'client');
api.addFiles('client/avatar/prompt.js', 'client');
// api.addAssets('styles/side-nav.less', 'client');
});

Loading…
Cancel
Save