This is an automated email from the git hooks/post-receive script. New commit to branch feature/adminUser in repository pollen. See http://git.chorem.org/pollen.git commit f4e8036d2ab21ead54de567f40b566a2a2128f82 Author: Adrien Garandel <a.garandel@dralagen.fr> Date: Wed Jul 23 12:27:35 2014 +0200 add good error when you want to change password --- .../org/chorem/pollen/rest/api/v1/PollenUserApi.java | 2 +- .../pollen/services/service/PollenUserService.java | 18 +++++++++++++++--- .../src/main/webapp/js/controllers/userCtrl.js | 2 ++ .../src/main/webapp/partials/user-edit.html | 12 ++++++------ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java index b02027a..55893b8 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/PollenUserApi.java @@ -101,7 +101,7 @@ public class PollenUserApi extends WebMotionController { public void changePassword(PollenUserService pollenUserService, PollenEntityId<PollenUser> userId, String oldPassword, - String newPassword) throws PollenInvalidPasswordException { + String newPassword) throws InvalidFormException { pollenUserService.changePassword(userId.getEntityId(), oldPassword, newPassword); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java index d577551..f49f1c9 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenUserService.java @@ -167,7 +167,7 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer public void changePassword(String userId, String oldPassword, - String newPassword) throws PollenInvalidPasswordException { + String newPassword) throws InvalidFormException { checkNotNull(userId); checkNotNull(oldPassword); @@ -175,8 +175,20 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer PollenUser user = getUser0(userId); - // check old password - getSecurityService().checkUserPassword(user, oldPassword); + ErrorMap errorMap = new ErrorMap(); + + boolean passwordNotBlank = checkNotBlank(errorMap, "newPassword", newPassword, l(getLocale(), "pollen.error.user.passwordEmpty")); + + if (passwordNotBlank) { + // check old password + try { + getSecurityService().checkUserPassword(user, oldPassword); + } catch (PollenInvalidPasswordException e) { + check(errorMap, "password", false, l(getLocale(), "pollen.error.user.passwordInvalid")); + } + } + + errorMap.failIfNotEmpty(); // set new password getSecurityService().setUserPassword(user, newPassword); diff --git a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js index b2c3add..68f8e03 100644 --- a/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js +++ b/pollen-ui-angular/src/main/webapp/js/controllers/userCtrl.js @@ -94,6 +94,8 @@ angular.module('userControllers', []) } $scope.data.user.password = ''; + $scope.data.user.newPassword = ''; + $scope.data.user.newPassword2 = ''; $scope.editUser = function () { User.update($scope.data.user, function (data) { diff --git a/pollen-ui-angular/src/main/webapp/partials/user-edit.html b/pollen-ui-angular/src/main/webapp/partials/user-edit.html index 1d75891..15fdd66 100644 --- a/pollen-ui-angular/src/main/webapp/partials/user-edit.html +++ b/pollen-ui-angular/src/main/webapp/partials/user-edit.html @@ -20,8 +20,8 @@ --> <h2> {{ 'title.user.edit' | translate }} </h2> -<form class="horizontal-form" ng-submit="editUser()"> - <div class="control-group"> +<form class="horizontal-form"> + <div class="control-group row"> <label for="formName" class="col-sm-5 text-right control-label"> {{ 'user.name' | translate }} </label> @@ -32,7 +32,7 @@ </div> </div> - <div class="control-group"> + <div class="control-group row"> <label for="formEmail" class="col-sm-5 text-right control-label"> {{ 'user.mail' | translate }} @@ -46,7 +46,7 @@ </div> </div> - <div class="control-group"> + <div class="control-group row"> <label for="formPassword" class="col-sm-5 text-right control-label"> {{ 'user.passwordCurrent' | translate }} </label> @@ -67,13 +67,13 @@ <div class="col-sm-1"></div> </div> -<form class="horizontal-form" ng-submit="editPassword()"> +<form class="horizontal-form"> <div class="control-group"> <label for="formCurrentPassword" class="col-sm-5 text-right control-label"> {{ 'user.passwordCurrent' | translate }} </label> <div class="col-sm-6"> - <input type="password" id="formCurrentPassword" class="form-control" ng-model="data.user.password" /> + <input type="password" id="formCurrentPassword" class="form-control" ng-model="data.user.password" auto-save="editPassword()" /> </div> <div class="col-sm-1"> <info-error error="restError.password[0]" data="data.user.password"></info-error> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.