angular.module('luticate') .controller('HomeController', ['$scope', 'luticateAuthCache', 'luticateDialogErrorHelper', 'luticateAuthUsers', '$state', function($scope, luticateAuthCache, luticateDialogErrorHelper, luticateAuthUsers, $state) { $scope.user = luticateAuthCache.getUser(); $scope.userPassword = { old: "", value: "", confirm: "" }; $scope.passwordValidation = { length: '$value.length >= 5 || $value.length == 0' }; $scope.password2Validation = { same_passwords: 'userPassword.value==$value' }; $scope.submit = function() { var promiseEditUser = { id: "promiseEditUser", loaderGroups: ["form"] }; if (luticateAuthCache.hasEffectivePermission("LU_USER_EDIT_ME")) { luticateAuthUsers.editMe({ email: $scope.user.Email, firstname: $scope.user.Firstname, lastname: $scope.user.Lastname }, promiseEditUser) .then(function(data) { $scope.load(); $scope.mayEditPassword(); }, luticateDialogErrorHelper.errorDialog); } else { $scope.mayEditPassword(); } }; $scope.mayEditPassword = function() { var promiseSetPassword = { id: "promiseSetPassword", loaderGroups: ["form"] }; if ($scope.userPassword.value != "" && luticateAuthCache.hasEffectivePermission("LU_USER_SET_PASSWORD_ME")) { luticateAuthUsers.setPasswordMe({ oldPassword: $scope.userPassword.old, password: $scope.userPassword.value }, promiseSetPassword) .then(function(data) { luticateAuthCache.removeUser(); $state.go('login'); }, luticateDialogErrorHelper.errorDialog); } }; $scope.load = function() { var promiseLoadMe = { id: "promiseLoadMe", groups: ["form"] }; luticateAuthUsers.getMe(promiseLoadMe) .then(function(user) { $scope.user = user; }, luticateDialogErrorHelper.errorDialog); }; $scope.load(); }]);