[kune-commits] r1547 - in trunk/src: main/java/cc/kune/core/client/rpcservices main/java/cc/kune/core/server/manager main/java/cc/kune/core/server/manager/impl main/java/cc/kune/core/server/rpc test/java/cc/kune/core/server/integration/site
Vicente J. Ruiz Jurado
vjrj_ at ourproject.org
Sun Oct 9 01:47:26 CEST 2011
Author: vjrj_
Date: 2011-10-09 01:47:25 +0200 (Sun, 09 Oct 2011)
New Revision: 1547
Modified:
trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java
trunk/src/main/java/cc/kune/core/server/manager/UserManager.java
trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java
trunk/src/test/java/cc/kune/core/server/integration/site/UserServiceTest.java
Log:
NEW - # 138: Add change password functionality to the User Interface
http://kune.ourproject.org/issues/ticket/138
Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -34,6 +34,8 @@
@RemoteServiceRelativePath("UserService")
public interface UserService extends RemoteService {
+ void changePasswd(String userHash, String oldPassword, String newPassword);
+
void createUser(UserDTO user, boolean wantPersonalHomepage) throws DefaultException;
String getUserAvatarBaser64(String userHash, StateToken userToken) throws DefaultException;
Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/UserServiceAsync.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -31,6 +31,8 @@
public interface UserServiceAsync {
+ void changePasswd(String userHash, String oldPassword, String newPassword, AsyncCallback<Void> callback);
+
void createUser(UserDTO user, boolean wantPersonalHomepage, AsyncCallback<Void> asyncCallback);
void getUserAvatarBaser64(String userHash, StateToken userToken, AsyncCallback<String> asyncCallback);
Modified: trunk/src/main/java/cc/kune/core/server/manager/UserManager.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/UserManager.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/main/java/cc/kune/core/server/manager/UserManager.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -30,6 +30,8 @@
import cc.kune.domain.utils.UserBuddiesData;
public interface UserManager {
+ User changePasswd(Long userId, String oldPassword, String newPassword);
+
/**
* CreateUser new method with language country and timezone params
*
Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -35,10 +35,17 @@
import org.apache.lucene.search.Query;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.packet.RosterPacket.ItemType;
+import org.waveprotocol.box.server.account.AccountData;
import org.waveprotocol.box.server.authentication.PasswordDigest;
import org.waveprotocol.box.server.persistence.AccountStore;
+import org.waveprotocol.box.server.persistence.PersistenceException;
+import org.waveprotocol.box.server.robots.agent.RobotAgentUtil;
+import org.waveprotocol.wave.model.wave.ParticipantId;
import org.waveprotocol.wave.model.waveref.WaveRef;
+import cc.kune.common.client.utils.TextUtils;
+import cc.kune.core.client.errors.AccessViolationException;
+import cc.kune.core.client.errors.DefaultException;
import cc.kune.core.client.errors.EmailAddressInUseException;
import cc.kune.core.client.errors.GroupLongNameInUseException;
import cc.kune.core.client.errors.GroupShortNameInUseException;
@@ -114,6 +121,32 @@
this.mailService = mailService;
}
+ @Override
+ public User changePasswd(final Long userId, final String oldPassword, final String newPassword) {
+ final User user = find(userId);
+ final ParticipantId participantId = participantUtils.of(user.getShortName());
+ // Check oldPasswd
+ try {
+ final AccountData account = waveAccountStore.getAccount(participantId);
+ if (TextUtils.notEmpty(oldPassword) && account != null
+ && !account.asHuman().getPasswordDigest().verify(oldPassword.toCharArray())) {
+ throw new AccessViolationException("You cannot change passwd");
+ }
+ // Wave change passwd
+ RobotAgentUtil.changeUserPassword(newPassword, participantId, waveAccountStore);
+ } catch (final IllegalArgumentException e) {
+ throw new DefaultException("Error changing user passwd", e);
+ } catch (final PersistenceException e) {
+ throw new DefaultException("Error changing user passwd", e);
+ }
+ // Kune db change passwd
+ final PasswordDigest newPasswordDigest = new PasswordDigest(newPassword.toCharArray());
+ user.setPassword(newPassword);
+ user.setSalt(newPasswordDigest.getSalt());
+ user.setDiggest(newPasswordDigest.getDigest());
+ return persist(user);
+ }
+
private void checkIfEmailAreInUse(final String email) {
if (userFinder.countByEmail(email) != 0) {
throw new EmailAddressInUseException();
@@ -355,7 +388,6 @@
user.setEmail(email);
}
user.setLanguage(findLanguage(lang.getCode()));
- // user.setLanguage(findLanguage(userDTO.getLanguage().getCode()));
persist(user);
groupManager.persist(userGroup);
return user;
Modified: trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -88,6 +88,14 @@
}
@Override
+ @Authenticated
+ @Transactional
+ public void changePasswd(final String userHash, final String oldPassword, final String newPassword) {
+ final Long userId = userSessionManager.getUser().getId();
+ userManager.changePasswd(userId, oldPassword, newPassword);
+ }
+
+ @Override
@Transactional(rollbackOn = DefaultException.class)
public void createUser(final UserDTO userDTO, final boolean wantPersonalHomepage)
throws DefaultException {
@@ -137,7 +145,7 @@
// sessionService.getNewSession();
final User user = userManager.login(nickOrEmail, passwd);
return loginUser(user, waveToken);
- }
+ };
private UserInfoDTO loginUser(final User user, final String waveToken) throws DefaultException {
if (user != null) {
@@ -146,7 +154,7 @@
} else {
throw new UserAuthException();
}
- };
+ }
@Override
@Authenticated
Modified: trunk/src/test/java/cc/kune/core/server/integration/site/UserServiceTest.java
===================================================================
--- trunk/src/test/java/cc/kune/core/server/integration/site/UserServiceTest.java 2011-10-06 13:32:53 UTC (rev 1546)
+++ trunk/src/test/java/cc/kune/core/server/integration/site/UserServiceTest.java 2011-10-08 23:47:25 UTC (rev 1547)
@@ -172,7 +172,27 @@
}
}
+ @Test(expected = AccessViolationException.class)
+ public void testSiteChangeIncorrectPasswdMustFail() throws Exception {
+ assertNull(session.getUser().getId());
+ doLogin(properties.getAdminShortName(), properties.getAdminPassword());
+ assertNotNull(session.getUser().getId());
+ userService.changePasswd(session.getHash(), "otherpasswd", "kkkkkk");
+ }
+
@Test
+ public void testSiteChangePasswd() throws Exception {
+ assertNull(session.getUser().getId());
+ doLogin(properties.getAdminShortName(), properties.getAdminPassword());
+ assertNotNull(session.getUser().getId());
+ userService.changePasswd(session.getHash(), properties.getAdminPassword(), "kkkkkk");
+ doLogout();
+ doLogin(properties.getAdminShortName(), "kkkkkk");
+ userService.changePasswd(session.getHash(), "kkkkkk", properties.getAdminPassword());
+ doLogout();
+ }
+
+ @Test
public void testSiteEmailLogin() throws Exception {
assertNull(session.getUser().getId());
userService.login(properties.getAdminEmail(), properties.getAdminPassword(), token);
@@ -235,8 +255,8 @@
timezone, null, true, SubscriptionMode.manual, "blue");
userService.createUser(user, false);
doLogin("test", "123456");
- final UserDTO userChanged = new UserDTO(shortName, longName, "123456", email, lang, country,
- timezone, null, true, SubscriptionMode.manual, "blue");
+ final UserDTO userChanged = new UserDTO("test", longName, "123456", email, lang, country, timezone,
+ null, true, SubscriptionMode.manual, "blue");
userChanged.setId(session.getUser().getId());
userService.updateUser(getHash(), userChanged, simpleLang);
}
More information about the kune-commits
mailing list