From f46efb55ffa6ded70f9e6ad9ffec81c56590f398 Mon Sep 17 00:00:00 2001 From: vrockai Date: Tue, 3 Dec 2013 10:07:16 +0100 Subject: [PATCH] KEYCLOAK-155 added totp to credentials page --- .../META-INF/resources/admin/js/app.js | 10 +- .../resources/admin/js/controllers/users.js | 95 ++++++++++++++----- .../admin/partials/user-credentials.html | 17 +++- .../resources/admin/partials/user-detail.html | 4 - 4 files changed, 91 insertions(+), 35 deletions(-) diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js index 90bc5ff6f5b..f618052f1d2 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/app.js @@ -535,6 +535,7 @@ module.directive('onoffswitch', function() { replace: true, scope: { ngModel: '=', + ngDisabled: '=', ngBind: '=', name: '=', id: '=', @@ -544,9 +545,11 @@ module.directive('onoffswitch', function() { compile: function(element, attrs) { if (!attrs.onText) { attrs.onText = "ON"; } if (!attrs.offText) { attrs.offText = "OFF"; } + if (!attrs.ngDisabled) { attrs.ngDisabled = false; } - var html = "
" + - "" + + var html = "
" + + "" + "" + - "
"; + "
"; element.replaceWith($(html)); } } }); - module.directive('kcInput', function() { var d = { scope : true, diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js index 0ae5b7950d6..de73f6333a7 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js +++ b/admin-ui/src/main/resources/META-INF/resources/admin/js/controllers/users.js @@ -231,20 +231,27 @@ module.controller('UserCredentialsCtrl', function($scope, realm, user, User, Use $scope.realm = realm; $scope.user = angular.copy(user); + $scope.isTotp = false; + if(!!user.totp){ + $scope.isTotp = user.totp; + } + $scope.resetPassword = function() { - if ($scope.password != $scope.confirmPassword) { - Notifications.error("Password and confirmation does not match."); - $scope.password = ""; - $scope.confirmPassword = ""; - return; - } + if ($scope.pwdChange) { + if ($scope.password != $scope.confirmPassword) { + Notifications.error("Password and confirmation does not match."); + $scope.password = ""; + $scope.confirmPassword = ""; + return; + } - if (!$scope.user.hasOwnProperty('requiredActions')){ - $scope.user.requiredActions = []; - } - if ($scope.user.requiredActions.indexOf("UPDATE_PASSWORD") < 0){ - $scope.user.requiredActions.push("UPDATE_PASSWORD"); + if (!$scope.user.hasOwnProperty('requiredActions')){ + $scope.user.requiredActions = []; + } + if ($scope.user.requiredActions.indexOf("UPDATE_PASSWORD") < 0){ + $scope.user.requiredActions.push("UPDATE_PASSWORD"); + } } var credentials = [ { type : "password", value : $scope.password } ]; @@ -254,21 +261,65 @@ module.controller('UserCredentialsCtrl', function($scope, realm, user, User, Use userId: $scope.user.username }, $scope.user, function () { - UserCredentials.update({ - realm: realm.id, - userId: $scope.user.username - }, credentials, function () { - Notifications.success("The user password has been reset. The user is required to change his password on" + - " the next login."); - }, function () { - Notifications.error("Error while resetting user password. Be aware that the update password required action" + - " was already set."); - }); + $scope.isTotp = $scope.user.totp; + + if ($scope.pwdChange){ + UserCredentials.update({ + realm: realm.id, + userId: $scope.user.username + }, credentials, function () { + Notifications.success("The password has been reset. The user is required to change his password on" + + " the next login."); + $scope.password = ""; + $scope.confirmPassword = ""; + $scope.pwdChange = false; + $scope.isTotp = user.totp; + $scope.userChange = false; + }, function () { + Notifications.error("Error while resetting user password. Be aware that the update password required action" + + " was already set."); + }); + } else { + Notifications.success("User settings was updated."); + $scope.isTotp = user.totp; + $scope.userChange = false; + } }, function () { - Notifications.error("Error while adding update password required action. Password was not reset."); + Notifications.error("Error while updating user settings."); }); }; + + $scope.$watch('user', function() { + if (!angular.equals($scope.user, user)) { + $scope.userChange = true; + } else { + $scope.userChange = false; + } + }, true); + + $scope.$watch('password', function() { + if (!!$scope.password){ + $scope.pwdChange = true; + } else { + $scope.pwdChange = false; + } + }, true); + + $scope.reset = function() { + $scope.password = ""; + $scope.confirmPassword = ""; + + $scope.user = angular.copy(user); + + $scope.isTotp = false; + if(!!user.totp){ + $scope.isTotp = user.totp; + } + + $scope.pwdChange = false; + $scope.userChange = false; + }; }); module.controller('RoleMappingCtrl', function($scope, realm, User, users, role, RoleMapping, Notifications) { diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-credentials.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-credentials.html index a7329454f6a..8f3de02d44a 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-credentials.html +++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-credentials.html @@ -14,10 +14,11 @@
  • {{realm.realm}}
  • Users
  • -

    {{user.username}}'s Reset Password

    +

    {{user.username}}'s Credentials

    + Reset Password
    @@ -28,14 +29,20 @@
    - +
    +
    + + +
    - + + + +
    diff --git a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-detail.html b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-detail.html index 13b60ce427f..0735afac27b 100755 --- a/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-detail.html +++ b/admin-ui/src/main/resources/META-INF/resources/admin/partials/user-detail.html @@ -70,10 +70,6 @@ -
    - - -