2016-05-09 12:53:40 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.layout.account.setting')
|
|
|
|
.controller('AccountSettingController', AccountSettingController);
|
|
|
|
|
2016-05-11 09:57:52 +02:00
|
|
|
AccountSettingController.$inject = ['ChangePasswordService', '$scope', '$window', 'currentUser'];
|
2016-05-09 12:53:40 +02:00
|
|
|
|
2016-05-11 09:57:52 +02:00
|
|
|
function AccountSettingController(ChangePasswordService, $scope, $window, currentUser) {
|
2016-05-09 12:53:40 +02:00
|
|
|
var vm = this;
|
|
|
|
vm.isOpen = false;
|
|
|
|
vm.user = {};
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
|
|
|
|
vm.reset = reset;
|
|
|
|
vm.toggleChangePassword = toggleChangePassword;
|
2016-05-09 19:48:05 +02:00
|
|
|
vm.changeProfile = changeProfile;
|
|
|
|
vm.changePassword= changePassword;
|
|
|
|
vm.cancel = cancel;
|
|
|
|
|
2016-06-16 08:10:35 +02:00
|
|
|
|
|
|
|
vm.user = currentUser.get();
|
2016-05-14 07:34:54 +02:00
|
|
|
|
|
|
|
function reset() {
|
|
|
|
vm.hasError = false;
|
|
|
|
vm.errorMessage = '';
|
|
|
|
}
|
2016-05-11 09:57:52 +02:00
|
|
|
|
2016-05-09 12:53:40 +02:00
|
|
|
function toggleChangePassword() {
|
|
|
|
if(vm.isOpen) {
|
|
|
|
vm.isOpen = false;
|
|
|
|
}else{
|
|
|
|
vm.isOpen = true;
|
2016-05-14 07:34:54 +02:00
|
|
|
}
|
2016-05-09 12:53:40 +02:00
|
|
|
}
|
2016-05-10 12:43:52 +02:00
|
|
|
|
2016-05-09 12:53:40 +02:00
|
|
|
function getCurrentUserFailed(data) {
|
|
|
|
console.log('Failed get current user:' + data);
|
|
|
|
}
|
|
|
|
|
2016-05-09 19:48:05 +02:00
|
|
|
function changeProfile(user) {
|
|
|
|
console.log(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
function changePassword(user) {
|
2016-05-14 07:34:54 +02:00
|
|
|
if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) {
|
2016-06-16 08:10:35 +02:00
|
|
|
ChangePasswordService(vm.user.user_id, user.oldPassword, user.password)
|
2016-05-14 07:34:54 +02:00
|
|
|
.success(changePasswordSuccess)
|
|
|
|
.error(changePasswordFailed);
|
|
|
|
}
|
2016-05-09 12:53:40 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 19:48:05 +02:00
|
|
|
function changePasswordSuccess(data, status) {
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/project';
|
2016-05-09 19:48:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function changePasswordFailed(data, status) {
|
|
|
|
console.log('Failed changed password:' + data);
|
2016-06-16 08:10:35 +02:00
|
|
|
if(data == 'old_password_is_not_correct') {
|
2016-05-14 07:34:54 +02:00
|
|
|
vm.hasError = true;
|
|
|
|
vm.errorMessage = 'old_password_is_incorrect';
|
2016-05-09 19:48:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 07:34:54 +02:00
|
|
|
function cancel(form) {
|
|
|
|
if(form) {
|
|
|
|
form.$setPristine();
|
|
|
|
}
|
2016-06-16 08:10:35 +02:00
|
|
|
$window.location.href = '/project';
|
2016-05-09 19:48:05 +02:00
|
|
|
}
|
2016-05-09 12:53:40 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})();
|