This is an automated email from the git hooks/post-receive script. New commit to branch feature/1_socialauth in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 3b0912205a842e282c2be9b4d36ea1e89720a5f1 Author: Kevin Morin <morin@codelutin.com> Date: Thu Aug 31 16:08:45 2017 +0200 refs #1 permettre l'ajout d'un mot de passe à des comptes créés à partir de service tiers --- .../java/org/chorem/pollen/services/bean/PollenUserBean.java | 12 +++++++++++- .../chorem/pollen/services/service/PollenUserService.java | 8 +++++--- .../service/security/PollenAuthenticationException.java | 4 ++++ .../pollen/services/service/security/SecurityService.java | 10 +++++++++- pollen-ui-riot-js/src/main/web/i18n.json | 2 ++ pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html | 11 ++++++++--- pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html | 2 +- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java index 9bb64057..42d33279 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/bean/PollenUserBean.java @@ -46,6 +46,8 @@ public class PollenUserBean extends PollenBean<PollenUser> { protected boolean emailIsValidate; + protected boolean withPassword; + public PollenUserBean() { super(PollenUser.class); } @@ -62,7 +64,7 @@ public class PollenUserBean extends PollenBean<PollenUser> { setEmail(entity.getEmail()); setPassword(entity.getPassword()); setEmailIsValidate(entity.getEmailActivationToken() == null); - + setWithPassword(entity.getPassword() != null); } @Override @@ -136,4 +138,12 @@ public class PollenUserBean extends PollenBean<PollenUser> { public void setBanned(boolean banned) { this.banned = banned; } + + public boolean isWithPassword() { + return withPassword; + } + + public void setWithPassword(boolean withPassword) { + this.withPassword = withPassword; + } } 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 b3cf72ef..5db9468d 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 @@ -82,8 +82,11 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer checkIsConnected(); checkNotNull(userId); - PollenUser pollenUser = getUser0(userId); - + PollenUser pollenUser = getConnectedUser(); + if (!userId.equals(pollenUser.getTopiaId())) { + checkIsAdmin(); + pollenUser = getUser0(userId); + } return toBean(PollenUserBean.class, pollenUser, pollenUserFunction); } @@ -146,7 +149,6 @@ public class PollenUserService extends PollenServiceSupport implements PollenSer String newPassword) throws InvalidFormException { checkNotNull(userId); - checkNotNull(oldPassword); checkNotNull(newPassword); PollenUser user = getUser0(userId); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenAuthenticationException.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenAuthenticationException.java index f2635c8a..85ac88cd 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenAuthenticationException.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/PollenAuthenticationException.java @@ -31,6 +31,10 @@ public class PollenAuthenticationException extends Exception { private static final long serialVersionUID = 1L; + public PollenAuthenticationException() { + super(); + } + public PollenAuthenticationException(Exception e) { super(e); } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java index 1ccb28bb..f351b350 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SecurityService.java @@ -25,6 +25,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.shiro.authc.AuthenticationException; @@ -125,6 +126,10 @@ public class SecurityService extends PollenServiceSupport { public PollenEntityRef<PollenUser> login(String login, String password, Boolean rememberMe) throws PollenAuthenticationException, PollenEmailNotValidatedException, PollenUserBannedException { + if (StringUtils.isBlank(password)) { + throw new PollenAuthenticationException(); + } + Subject subject = getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(login, password); if (rememberMe != null) { @@ -335,7 +340,10 @@ public class SecurityService extends PollenServiceSupport { public void checkUserPassword(PollenUser user, String password) throws PollenInvalidPasswordException { - String encodedPassword = serviceContext.encodePassword(user.getSalt(), password); + String encodedPassword = null; + if (password != null) { + encodedPassword = serviceContext.encodePassword(user.getSalt(), password); + } boolean valid = Objects.equals(encodedPassword, user.getPassword()); if (user.isBanned() || !valid) { throw new PollenInvalidPasswordException(); diff --git a/pollen-ui-riot-js/src/main/web/i18n.json b/pollen-ui-riot-js/src/main/web/i18n.json index 4dea55f4..93c25c00 100644 --- a/pollen-ui-riot-js/src/main/web/i18n.json +++ b/pollen-ui-riot-js/src/main/web/i18n.json @@ -394,6 +394,7 @@ "userProfile_repeatPassword_placeholder": "Répétez votre mot de passe", "userProfile_repeatPassword_error": "Les deux mots de passe ne sont pas identiques.", "userProfile_savePassword": "Enregistrer", + "userProfile_updatedPassword": "Votre mot de passe a été mis à jour", "choice_description_placeholder": "Vous pouvez saisir une description pour ce choix", "date-picker_today": "Aujourd'hui", "date-picker_dateplaceholder": "Date", @@ -937,6 +938,7 @@ "userProfile_repeatPassword_placeholder": "Confirm your new password", "userProfile_repeatPassword_error": "The two passwords are not identical.", "userProfile_savePassword": "Save", + "userProfile_updatedPassword": "Your password has been updated", "choice_description_placeholder": "You can enter a description for this choice", "date-picker_today": "Today", "date-picker_dateplaceholder": "Date", diff --git a/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html b/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html index c06bed10..f7e2eda0 100644 --- a/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/UserProfile.tag.html @@ -64,7 +64,7 @@ require("./components/HumanInput.tag.html"); <form ref="password-form" class="password-form"> <HumanInput onsubmit={submitPassword}/> <h3 class="c-heading"><i class="fa fa-key"/> {__.passwordChange}</h3> - <div class="o-form-element"> + <div class="o-form-element" if="{user.withPassword}"> <label class="c-label" for="oldPassword">{__.oldPassword}</label> <input class="c-field {c-field--error : errors.oldPassword}" type="password" @@ -131,6 +131,7 @@ require("./components/HumanInput.tag.html"); this.user = session.getUser() || {}; let userService = require("../js/UserService"); let authService = require("../js/AuthService"); + let Message = require("../js/Message"); this.onUserChange = (user) => { this.user = user || {}; @@ -170,13 +171,17 @@ require("./components/HumanInput.tag.html"); this.checkPassword(); if (this.errors.repeatPassword === undefined) { - let oldPassword = this.refs.oldPassword.value; + let oldPassword = this.user.withPassword ? this.refs.oldPassword.value : null; let newPassword = this.refs.newPassword.value; userService.changePassword(this.user.id, oldPassword, newPassword).then(() => { - this.refs.oldPassword.value = ""; + if (this.user.withPassword) { + this.refs.oldPassword.value = ""; + } this.refs.newPassword.value = ""; this.refs.repeatPassword.value = ""; + this.user.withPassword = true; this.update(); + this.bus.trigger("message", new Message(this._l("updatedPassword"), "success")); }) .catch((errors) => { this.errors = errors; diff --git a/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html b/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html index 6f403e32..8fb9e3e7 100644 --- a/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html +++ b/pollen-ui-riot-js/src/main/web/tag/poll/Polls.tag.html @@ -96,7 +96,7 @@ require("../components/Search.tag.html"); return pollService.assignPoll(finds[1], finds[2]).then((result) => { if (result) { this.refresh(); - this.bus.trigger("message", new Message(this._l("assignSuccessMessage", result.title), "succes")); + this.bus.trigger("message", new Message(this._l("assignSuccessMessage", result.title), "success")); } else { this.bus.trigger("message", new Message(this.__.alreadyAssignMessage, "warning")); } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.