diff --git a/controllers/changepassword.go b/controllers/changepassword.go new file mode 100644 index 0000000000..0ecddb29c1 --- /dev/null +++ b/controllers/changepassword.go @@ -0,0 +1,11 @@ +package controllers + +// ChangePasswordController handles request to /change_password +type ChangePasswordController struct { + BaseController +} + +// Get renders the change password page +func (asc *ChangePasswordController) Get() { + asc.Forward("page_title_change_password", "change-password.htm") +} diff --git a/static/resources/js/harbor.module.js b/static/resources/js/harbor.module.js index d92272c75d..8fe5eda2a4 100644 --- a/static/resources/js/harbor.module.js +++ b/static/resources/js/harbor.module.js @@ -13,6 +13,7 @@ 'harbor.layout.sign.up', 'harbor.layout.add.new', 'harbor.layout.account.setting', + 'harbor.layout.change.password', 'harbor.layout.forgot.password', 'harbor.layout.reset.password', 'harbor.layout.index', @@ -48,4 +49,4 @@ 'harbor.inline.help', 'harbor.dismissable.alerts' ]); -})(); \ No newline at end of file +})(); diff --git a/static/resources/js/layout/account-setting/account-setting.controller.js b/static/resources/js/layout/account-setting/account-setting.controller.js index 6a8a0a46f3..fbbcd53bea 100644 --- a/static/resources/js/layout/account-setting/account-setting.controller.js +++ b/static/resources/js/layout/account-setting/account-setting.controller.js @@ -17,7 +17,6 @@ vm.errorMessage = ''; vm.reset = reset; - vm.toggleChangePassword = toggleChangePassword; vm.confirm = confirm; vm.updateUser = updateUser; vm.cancel = cancel; @@ -52,14 +51,6 @@ vm.errorMessage = ''; } - function toggleChangePassword() { - if(vm.isOpen) { - vm.isOpen = false; - }else{ - vm.isOpen = true; - } - } - function confirm() { $window.location.href = '/dashboard'; } @@ -67,37 +58,14 @@ function updateUser(user) { vm.confirmOnly = true; vm.action = vm.confirm; - if(vm.isOpen){ - if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) { - ChangePasswordService(userId, user.oldPassword, user.password) - .success(changePasswordSuccess) - .error(changePasswordFailed); - } - }else{ - if(user && angular.isDefined(user.username) && angular.isDefined(user.password) && - angular.isDefined(user.realname)) { - UpdateUserService(userId, user) - .success(updateUserSuccess) - .error(updateUserFailed); - currentUser.set(user); - } + if(user && angular.isDefined(user.username) && angular.isDefined(user.realname)) { + UpdateUserService(userId, user) + .success(updateUserSuccess) + .error(updateUserFailed); + currentUser.set(user); } } - - function changePasswordSuccess(data, status) { - vm.modalTitle = $filter('tr')('change_password', []); - vm.modalMessage = $filter('tr')('successful_changed_password', []); - $scope.$broadcast('showDialog', true); - } - - function changePasswordFailed(data, status) { - console.log('Failed to changed password:' + data); - if(data == 'old_password_is_not_correct') { - vm.hasError = true; - vm.errorMessage = 'old_password_is_incorrect'; - } - } - + function updateUserSuccess(data, status) { vm.modalTitle = $filter('tr')('change_profile', []); vm.modalMessage = $filter('tr')('successful_changed_profile', []); @@ -123,4 +91,4 @@ } -})(); \ No newline at end of file +})(); diff --git a/static/resources/js/layout/change-password/change-password.controller.js b/static/resources/js/layout/change-password/change-password.controller.js new file mode 100644 index 0000000000..b4d07c5d82 --- /dev/null +++ b/static/resources/js/layout/change-password/change-password.controller.js @@ -0,0 +1,96 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.layout.change.password') + .controller('ChangePasswordController', ChangePasswordController); + + ChangePasswordController.$inject = ['ChangePasswordService', 'UpdateUserService', '$filter', 'trFilter', '$scope', '$window', 'currentUser']; + + function ChangePasswordController(ChangePasswordService, UpdateUserService, $filter, trFilter, $scope, $window, currentUser) { + + var vm = this; + vm.isOpen = false; + + vm.hasError = false; + vm.errorMessage = ''; + + vm.reset = reset; + + vm.confirm = confirm; + vm.updatePassword = updatePassword; + vm.cancel = cancel; + + $scope.user = currentUser.get(); + var userId = $scope.user.user_id; + + //Error message dialog handler for account setting. + $scope.$on('modalTitle', function(e, val) { + vm.modalTitle = val; + }); + + $scope.$on('modalMessage', function(e, val) { + vm.modalMessage = val; + }); + + $scope.$on('raiseError', function(e, val) { + if(val) { + vm.action = function() { + $scope.$broadcast('showDialog', false); + }; + vm.contentType = 'text/plain'; + vm.confirmOnly = true; + $scope.$broadcast('showDialog', true); + } + }); + + function reset() { + $scope.form.$setUntouched(); + $scope.form.$setPristine(); + vm.hasError = false; + vm.errorMessage = ''; + } + + function confirm() { + $window.location.href = '/dashboard'; + } + + function updatePassword(user) { + if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) { + vm.action = vm.confirm; + ChangePasswordService(userId, user.oldPassword, user.password) + .success(changePasswordSuccess) + .error(changePasswordFailed); + } + + } + + function changePasswordSuccess(data, status) { + vm.modalTitle = $filter('tr')('change_password', []); + vm.modalMessage = $filter('tr')('successful_changed_password', []); + $scope.$broadcast('showDialog', true); + } + + function changePasswordFailed(data, status) { + + var message; + $scope.$emit('modalTitle', $filter('tr')('error')); + console.log('Failed to change password:' + data); + if(data == 'old_password_is_not_correct') { + message = $filter('tr')('old_password_is_incorrect'); + }else{ + message = $filter('tr')('failed_to_change_password'); + } + + $scope.$emit('modalMessage', message); + $scope.$emit('raiseError', true); + } + + function cancel(form) { + $window.location.href = '/dashboard'; + } + + } + +})(); diff --git a/static/resources/js/layout/change-password/change-password.module.js b/static/resources/js/layout/change-password/change-password.module.js new file mode 100644 index 0000000000..c0655b3248 --- /dev/null +++ b/static/resources/js/layout/change-password/change-password.module.js @@ -0,0 +1,9 @@ +(function() { + + 'use strict'; + + angular + .module('harbor.layout.change.password', [ + 'harbor.services.user']); + +})(); \ No newline at end of file diff --git a/static/resources/js/services/i18n/locale_messages_en-US.js b/static/resources/js/services/i18n/locale_messages_en-US.js index f72d492230..820ff46d26 100644 --- a/static/resources/js/services/i18n/locale_messages_en-US.js +++ b/static/resources/js/services/i18n/locale_messages_en-US.js @@ -47,6 +47,7 @@ var locale_messages = { 'forgot_password_description': 'Please input the Email used when you signed up, a reset password Email will be sent to you.', 'reset_password': 'Reset Password', 'successful_reset_password': 'Password has been reset successfully.', + 'failed_to_change_password': 'Failed to change password.', 'summary': 'Summary', 'projects': 'Projects', 'public_projects': 'Public Projects', @@ -252,4 +253,4 @@ var locale_messages = { 'inline_help_publicity': 'Setting the project as public.', 'alert_job_contains_error': 'Found errors in the current replication jobs, please look into it.', 'caution': 'Caution' -}; \ No newline at end of file +}; diff --git a/static/resources/js/services/i18n/locale_messages_zh-CN.js b/static/resources/js/services/i18n/locale_messages_zh-CN.js index 895d9596e9..0dca7e3488 100644 --- a/static/resources/js/services/i18n/locale_messages_zh-CN.js +++ b/static/resources/js/services/i18n/locale_messages_zh-CN.js @@ -47,6 +47,7 @@ var locale_messages = { 'forgot_password_description': '重置邮件将发送到此邮箱。', 'reset_password': '重置密码', 'successful_reset_password': '重置密码成功。', + 'failed_to_change_password': '修改密码失败。', 'summary': '摘要', 'projects': '项目', 'public_projects': '公开项目', @@ -251,4 +252,4 @@ var locale_messages = { 'inline_help_publicity': '设置该项目为公开。', 'alert_job_contains_error': '当前复制任务中包含错误,请检查。', 'caution': '注意' -}; \ No newline at end of file +}; diff --git a/ui/router.go b/ui/router.go index 4fe8a41848..b35d53229c 100644 --- a/ui/router.go +++ b/ui/router.go @@ -37,6 +37,7 @@ func initRouters() { beego.Router("/sign_up", &controllers.SignUpController{}) beego.Router("/add_new", &controllers.AddNewController{}) beego.Router("/account_setting", &controllers.AccountSettingController{}) + beego.Router("/change_password", &controllers.ChangePasswordController{}) beego.Router("/admin_option", &controllers.AdminOptionController{}) beego.Router("/forgot_password", &controllers.ForgotPasswordController{}) beego.Router("/reset_password", &controllers.ResetPasswordController{}) diff --git a/views/account-settings.htm b/views/account-settings.htm index bf5d38c549..1f16c147ec 100644 --- a/views/account-settings.htm +++ b/views/account-settings.htm @@ -15,8 +15,8 @@