KEYCLOAK-155 reset user password page (user credentials)

This commit is contained in:
vrockai 2013-11-28 17:36:43 +01:00
parent 85eeb415e1
commit 945eaa2ddb
6 changed files with 118 additions and 2 deletions

View file

@ -113,6 +113,18 @@ module.config([ '$routeProvider', function($routeProvider) {
},
controller : 'UserDetailCtrl'
})
.when('/realms/:realm/users/:user/user-credentials', {
templateUrl : 'partials/user-credentials.html',
resolve : {
realm : function(RealmLoader) {
return RealmLoader();
},
user : function(UserLoader) {
return UserLoader();
}
},
controller : 'UserCredentialsCtrl'
})
.when('/realms/:realm/users/:user/role-mappings', {
templateUrl : 'partials/role-mappings.html',
resolve : {

View file

@ -225,6 +225,52 @@ module.controller('UserDetailCtrl', function($scope, realm, user, User, $locatio
};
});
module.controller('UserCredentialsCtrl', function($scope, realm, user, User, UserCredentials, Notifications) {
console.log('UserCredentialsCtrl');
$scope.realm = realm;
$scope.user = angular.copy(user);
$scope.resetPassword = function() {
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");
}
var credentials = [ { type : "password", value : $scope.password } ];
User.update({
realm: realm.id,
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.");
});
}, function () {
Notifications.error("Error while adding update password required action. Password was not reset.");
});
};
});
module.controller('RoleMappingCtrl', function($scope, realm, User, users, role, RoleMapping, Notifications) {
$scope.realm = realm;
$scope.realmId = realm.realm || realm.id;

View file

@ -134,6 +134,18 @@ module.factory('User', function($resource) {
});
});
module.factory('UserCredentials', function($resource) {
return $resource('/auth-server/rest/saas/admin/realms/:realm/users/:userId/credentials', {
realm : '@realm',
userId : '@userId'
}, {
update : {
method : 'PUT',
isArray : true
}
});
});
module.factory('RealmRoleMapping', function($resource) {
return $resource('/auth-server/rest/saas/admin/realms/:realm/users/:userId/role-mappings/realm', {
realm : '@realm',

View file

@ -5,7 +5,7 @@
<div class="top-nav">
<ul class="rcue-tabs" >
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}">Attributes</a></li>
<li><a href="#">Credentials</a></li>
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}/user-credentials">Credentials</a></li>
<li class="active"><a href="#/realms/{{realm.id}}/users/{{user.username}}/role-mappings">Role Mappings</a></li>
</ul>
</div>

View file

@ -0,0 +1,46 @@
<div id="wrapper" class="container">
<div class="row">
<div class="bs-sidebar col-md-3 clearfix" data-ng-include data-src="'partials/realm-menu.html'"></div>
<div id="content-area" class="col-md-9" role="main">
<div class="top-nav">
<ul class="rcue-tabs">
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}">Attributes</a></li>
<li class="active"><a href="#/realms/{{realm.id}}/users/{{user.username}}/user-credentials">Credentials</a></li>
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}/role-mappings">Role Mappings</a></li>
</ul>
</div>
<div id="content">
<ol class="breadcrumb">
<li><a href="#/realms/{{realm.id}}">{{realm.realm}}</a></li>
<li class="active">Users</li>
</ol>
<h2><span>{{user.username}}'s</span> Reset Password</h2>
<form name="userForm" novalidate>
<fieldset class="border-top">
<div class="form-group">
<label for="password">New Password</label>
<div class="controls">
<input type="password" id="password" name="password" data-ng-model="password" autofocus
required>
</div>
</div>
<div class="form-group">
<label class="two-lines" for="password">New Password Confirmation</label>
<div class="controls">
<input type="password" id="confirmPassword" name="confirmPassword" data-ng-model="confirmPassword"
required>
</div>
</div>
</fieldset>
<div class="form-actions">
<button type="submit" class="primary" data-ng-click="resetPassword()"
ng-show="password != null">Reset Password</button>
</div>
</form>
</div>
</div>
<div id="container-right-bg"></div>
</div>
</div>

View file

@ -10,7 +10,7 @@
<div class="top-nav" data-ng-show="!create">
<ul class="rcue-tabs" >
<li class="active"><a href="#/realms/{{realm.id}}/users/{{user.username}}">Attributes</a></li>
<li><a href="#">Credentials</a></li>
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}/user-credentials">Credentials</a></li>
<li><a href="#/realms/{{realm.id}}/users/{{user.username}}/role-mappings">Role Mappings</a></li>
</ul>
</div>