mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-10 15:11:22 +00:00
GUAC-1053: Move password changing into preferences.
This commit is contained in:
@@ -45,30 +45,12 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
||||
templateUrl: 'app/navigation/templates/guacUserMenu.html',
|
||||
controller: ['$scope', '$injector', '$element', function guacUserMenuController($scope, $injector, $element) {
|
||||
|
||||
// Get required types
|
||||
var PermissionSet = $injector.get('PermissionSet');
|
||||
|
||||
// Get required services
|
||||
var $document = $injector.get('$document');
|
||||
var $location = $injector.get('$location');
|
||||
var authenticationService = $injector.get('authenticationService');
|
||||
var guacNotification = $injector.get('guacNotification');
|
||||
var permissionService = $injector.get("permissionService");
|
||||
var userService = $injector.get('userService');
|
||||
var userPageService = $injector.get('userPageService');
|
||||
|
||||
/**
|
||||
* An action to be provided along with the object sent to
|
||||
* showStatus which closes the currently-shown status dialog.
|
||||
*/
|
||||
var ACKNOWLEDGE_ACTION = {
|
||||
name : 'USER_MENU.ACTION_ACKNOWLEDGE',
|
||||
// Handle action
|
||||
callback : function acknowledgeCallback() {
|
||||
guacNotification.showStatus(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The outermost element of the user menu directive.
|
||||
*
|
||||
@@ -83,28 +65,6 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
||||
*/
|
||||
var document = $document[0];
|
||||
|
||||
/**
|
||||
* Whether the password edit dialog should be shown.
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
$scope.showPasswordDialog = false;
|
||||
|
||||
/**
|
||||
* The new password for the user.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
$scope.newPassword = null;
|
||||
|
||||
/**
|
||||
* The password match for the user. The update password action will
|
||||
* fail if $scope.newPassword !== $scope.passwordMatch.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
$scope.newPasswordMatch = null;
|
||||
|
||||
/**
|
||||
* Whether the contents of the user menu are currently shown.
|
||||
*
|
||||
@@ -139,81 +99,6 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
||||
$scope.menuShown = !$scope.menuShown;
|
||||
};
|
||||
|
||||
/**
|
||||
* Show the password update dialog.
|
||||
*/
|
||||
$scope.showPasswordUpdate = function showPasswordUpdate() {
|
||||
|
||||
// Show the dialog
|
||||
$scope.showPasswordDialog = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Close the password update dialog.
|
||||
*/
|
||||
$scope.closePasswordUpdate = function closePasswordUpdate() {
|
||||
|
||||
// Clear the password fields and close the dialog
|
||||
$scope.oldPassword = null;
|
||||
$scope.newPassword = null;
|
||||
$scope.newPasswordMatch = null;
|
||||
$scope.showPasswordDialog = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the current user's password to the password currently set within
|
||||
* the password change dialog.
|
||||
*/
|
||||
$scope.updatePassword = function updatePassword() {
|
||||
|
||||
// Verify passwords match
|
||||
if ($scope.newPasswordMatch !== $scope.newPassword) {
|
||||
guacNotification.showStatus({
|
||||
className : 'error',
|
||||
title : 'USER_MENU.DIALOG_HEADER_ERROR',
|
||||
text : 'USER_MENU.ERROR_PASSWORD_MISMATCH',
|
||||
actions : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify that the new password is not blank
|
||||
if (!$scope.newPassword) {
|
||||
guacNotification.showStatus({
|
||||
className : 'error',
|
||||
title : 'USER_MENU.DIALOG_HEADER_ERROR',
|
||||
text : 'USER_MENU.ERROR_PASSWORD_BLANK',
|
||||
actions : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the user with the new password
|
||||
userService.updateUserPassword($scope.username, $scope.oldPassword, $scope.newPassword)
|
||||
.success(function passwordUpdated() {
|
||||
|
||||
// Close the password update dialog
|
||||
$scope.closePasswordUpdate();
|
||||
|
||||
// Indicate that the password has been changed
|
||||
guacNotification.showStatus({
|
||||
text : 'USER_MENU.PASSWORD_CHANGED',
|
||||
actions : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
})
|
||||
|
||||
// Notify of any errors
|
||||
.error(function passwordUpdateFailed(error) {
|
||||
guacNotification.showStatus({
|
||||
className : 'error',
|
||||
title : 'USER_MENU.DIALOG_HEADER_ERROR',
|
||||
'text' : error.message,
|
||||
actions : [ ACKNOWLEDGE_ACTION ]
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Logs out the current user, redirecting them to back to the login
|
||||
* screen after logout completes.
|
||||
@@ -234,34 +119,11 @@ angular.module('navigation').directive('guacUserMenu', [function guacUserMenu()
|
||||
callback : $scope.logout
|
||||
};
|
||||
|
||||
/**
|
||||
* Action which shows the password update dialog.
|
||||
*/
|
||||
var CHANGE_PASSWORD_ACTION = {
|
||||
name : 'USER_MENU.ACTION_CHANGE_PASSWORD',
|
||||
className : 'change-password',
|
||||
callback : $scope.showPasswordUpdate
|
||||
};
|
||||
|
||||
/**
|
||||
* All available actions for the current user.
|
||||
*/
|
||||
$scope.actions = [ LOGOUT_ACTION ];
|
||||
|
||||
// Retrieve current permissions
|
||||
permissionService.getPermissions(authenticationService.getCurrentUserID())
|
||||
.success(function permissionsRetrieved(permissions) {
|
||||
|
||||
// Add action for changing password if permission is granted
|
||||
if (PermissionSet.hasUserPermission(permissions,
|
||||
PermissionSet.ObjectPermissionType.UPDATE,
|
||||
authenticationService.getCurrentUserID()))
|
||||
$scope.actions.unshift(CHANGE_PASSWORD_ACTION);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Close menu when use clicks anywhere else
|
||||
document.body.addEventListener('click', function clickOutsideMenu() {
|
||||
$scope.$apply(function closeMenu() {
|
||||
|
Reference in New Issue
Block a user