123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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();
- }]);
|