diff --git a/client/views/account/accountProfile.coffee b/client/views/account/accountProfile.coffee index 575e6ab04de..9bd7703bb67 100644 --- a/client/views/account/accountProfile.coffee +++ b/client/views/account/accountProfile.coffee @@ -19,36 +19,53 @@ Template.accountProfile.onCreated -> @clearForm = -> @find('#language').value = localStorage.getItem('userLanguage') + @find('#oldPassword').value = '' @find('#password').value = '' + @changePassword = (oldPassword, newPassword, callback) -> + if not oldPassword and not newPassword + return callback() + + else if !!oldPassword ^ !!newPassword + toastr.warning t('Old_and_new_password_required') + + else if newPassword and oldPassword + Accounts.changePassword oldPassword, newPassword, (error) -> + if error + toastr.error t('Incorrect_Password') + else + return callback() + @save = -> instance = @ - data = {} - reload = false - selectedLanguage = $('#language').val() - - if localStorage.getItem('userLanguage') isnt selectedLanguage - localStorage.setItem 'userLanguage', selectedLanguage - data.language = selectedLanguage - reload = true - - if _.trim $('#password').val() - data.password = _.trim $('#password').val() - - if _.trim $('#username').val() - data.username = _.trim $('#username').val() - - Meteor.call 'saveUserProfile', data, (error, results) -> - if results - toastr.success t('Profile_saved_successfully') - instance.clearForm() - if reload - setTimeout -> - Meteor._reload.reload() - , 1000 - - if error - toastr.error error.reason + + oldPassword = _.trim($('#oldPassword').val()) + newPassword = _.trim($('#password').val()) + + instance.changePassword oldPassword, newPassword, -> + data = {} + reload = false + selectedLanguage = $('#language').val() + + if localStorage.getItem('userLanguage') isnt selectedLanguage + localStorage.setItem 'userLanguage', selectedLanguage + data.language = selectedLanguage + reload = true + + if _.trim $('#username').val() + data.username = _.trim $('#username').val() + + Meteor.call 'saveUserProfile', data, (error, results) -> + if results + toastr.success t('Profile_saved_successfully') + instance.clearForm() + if reload + setTimeout -> + Meteor._reload.reload() + , 1000 + + if error + toastr.error error.reason Template.accountProfile.onRendered -> Tracker.afterFlush -> diff --git a/client/views/account/accountProfile.html b/client/views/account/accountProfile.html index d2ea2b9b0f9..9af06a11572 100644 --- a/client/views/account/accountProfile.html +++ b/client/views/account/accountProfile.html @@ -15,6 +15,12 @@ +
+ +
+ +
+
diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 48d4c1951a0..7cec2369f56 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -119,6 +119,7 @@ "Hide_room" : "Hide room", "History" : "History", "hours" : "hours", + "Incorrect_Password" : "Incorrect Password", "inline_code" : "inline_code", "Invalid_confirm_pass" : "The password confirmation does not match password", "Invalid_email" : "The e-mail entered is invalid", @@ -213,6 +214,8 @@ "Not_found_or_not_allowed" : "Not Found or Not Allowed", "Nothing_found" : "Nothing found", "Notify_all_in_this_room" : "Notify all in this room", + "Old_Password" : "Old Password", + "Old_and_new_password_required" : "You need to provide both old and new password for changing your password.", "Only_you_can_see_this_message" : "Only you can see this message", "Online" : "Online", "Oops!" : "Oops", diff --git a/server/methods/saveUserProfile.coffee b/server/methods/saveUserProfile.coffee index 40131de389e..cfd36bdbefc 100644 --- a/server/methods/saveUserProfile.coffee +++ b/server/methods/saveUserProfile.coffee @@ -4,8 +4,8 @@ Meteor.methods if settings.language? RocketChat.models.Users.setLanguage Meteor.userId(), settings.language - if settings.password? - Accounts.setPassword Meteor.userId(), settings.password, { logout: false } + # if settings.password? + # Accounts.setPassword Meteor.userId(), settings.password, { logout: false } if settings.username? Meteor.call 'setUsername', settings.username diff --git a/server/methods/setPassword.coffee b/server/methods/setPassword.coffee deleted file mode 100644 index 6f6c2a65e84..00000000000 --- a/server/methods/setPassword.coffee +++ /dev/null @@ -1,5 +0,0 @@ -Meteor.methods - setPassword: (password) -> - if Meteor.userId() - Accounts.setPassword Meteor.userId(), password, { logout: false } - return true \ No newline at end of file