[kune-commits] r1665 - in trunk/src/main/java/cc/kune/core: client client/auth client/rpcservices client/sitebar/auth client/state server/rpc
Vicente J. Ruiz Jurado
vjrj_ at ourproject.org
Tue Jan 17 13:34:02 CET 2012
Author: vjrj_
Date: 2012-01-17 13:34:00 +0100 (Tue, 17 Jan 2012)
New Revision: 1665
Added:
trunk/src/main/java/cc/kune/core/client/sitebar/auth/PasswordResetPanel.java
Modified:
trunk/src/main/java/cc/kune/core/client/CoreParts.java
trunk/src/main/java/cc/kune/core/client/auth/SignInPanel.java
trunk/src/main/java/cc/kune/core/client/auth/SignInPresenter.java
trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
trunk/src/main/java/cc/kune/core/client/sitebar/auth/AskForPasswordResetPanel.java
trunk/src/main/java/cc/kune/core/client/state/SiteTokens.java
trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java
Log:
CLOSED - # 99: Add a recovery password functionality
http://kune.ourproject.org/issues/ticket/99
Modified: trunk/src/main/java/cc/kune/core/client/CoreParts.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/CoreParts.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/CoreParts.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -28,6 +28,7 @@
import cc.kune.core.client.sitebar.AboutKuneDialog;
import cc.kune.core.client.sitebar.SiteUserOptionsPresenter;
import cc.kune.core.client.sitebar.auth.AskForPasswordResetPanel;
+import cc.kune.core.client.sitebar.auth.PasswordResetPanel;
import cc.kune.core.client.sitebar.auth.VerifyEmailClientManager;
import cc.kune.core.client.sitebar.spaces.Space;
import cc.kune.core.client.sitebar.spaces.SpaceSelectEvent;
@@ -63,7 +64,7 @@
final Provider<SubtitlesManager> subProvider, final EventBus eventBus,
final Provider<VerifyEmailClientManager> verifyManager,
final Provider<UserOptions> userOptionsDialog, final Provider<GroupOptions> groupOptionsDialog,
- final Provider<AskForPasswordResetPanel> askForPass) {
+ final Provider<PasswordResetPanel> passReset, final Provider<AskForPasswordResetPanel> askForPass) {
session.onAppStart(true, new AppStartHandler() {
@Override
public void onAppStart(final AppStartEvent event) {
@@ -140,6 +141,24 @@
}
}
});
+ tokenListener.put(SiteTokens.ASK_RESET_PASSWD, new HistoryTokenAuthNotNeededCallback() {
+ @Override
+ public void onHistoryToken(final String token) {
+ if (!session.isLogged()) {
+ askForPass.get().show();
+ }
+ }
+ });
+ tokenListener.put(SiteTokens.RESET_PASSWD, new HistoryTokenAuthNotNeededCallback() {
+ @Override
+ public void onHistoryToken(final String token) {
+ if (!session.isLogged()) {
+ passReset.get().setPasswordHash(token);
+ passReset.get().show();
+ }
+ }
+ });
verifyManager.get();
+
}
}
Modified: trunk/src/main/java/cc/kune/core/client/auth/SignInPanel.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/auth/SignInPanel.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/auth/SignInPanel.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -40,8 +40,10 @@
public static final String CANCEL_BUTTON_ID = "k-signinp-cb";
public static final String CREATE_ONE = "k-signinp-create";
public static final String ERROR_MSG = "k-sigp-errmsg";
+ public static final String FORGOT_PASSWD = "k-signinp-forgot";
public static final String SIGN_IN_BUTTON_ID = "k-signinp-sib";
public static final String SIGNIN_DIALOG = "k-signinp-dialog";
+ private Label forgotPasswordLabel;
private Label registerLabel;
private final SignInForm signInForm;
@@ -54,24 +56,31 @@
signInForm = new SignInForm(i18n);
signInForm.setWidth(330);
- signInForm.add(createNoAccountRegister());
+ signInForm.add(createRegisterAndForgotPasswd());
messageErrorBar = new MessageToolbar(images, errorLabelId);
signInForm.add(messageErrorBar);
super.getInnerPanel().add(signInForm.getFormPanel());
}
- private VerticalPanel createNoAccountRegister() {
+ private void createLink(final Label label, final String id) {
+ label.ensureDebugId(id);
+ label.addStyleName("k-link");
+ label.addStyleName("k-cursor");
+ }
+
+ private VerticalPanel createRegisterAndForgotPasswd() {
final VerticalPanel noAccRegisterPanel = new VerticalPanel();
final HorizontalPanel hpanel = new HorizontalPanel();
final Label dontHaveAccount = new Label(i18n.t("Don't have an account?"));
registerLabel = new Label(i18n.t("Create one."));
- registerLabel.ensureDebugId(CREATE_ONE);
+ createLink(registerLabel, CREATE_ONE);
registerLabel.addStyleName("kune-Margin-Medium-l");
- registerLabel.addStyleName("k-link");
- registerLabel.addStyleName("k-cursor");
+ forgotPasswordLabel = new Label(i18n.t("Lost your password?"));
+ createLink(forgotPasswordLabel, FORGOT_PASSWD);
hpanel.add(dontHaveAccount);
hpanel.add(registerLabel);
noAccRegisterPanel.add(hpanel);
+ noAccRegisterPanel.add(forgotPasswordLabel);
return noAccRegisterPanel;
}
@@ -91,6 +100,11 @@
}
@Override
+ public HasClickHandlers getForgotPasswd() {
+ return forgotPasswordLabel;
+ }
+
+ @Override
public String getLoginPassword() {
return signInForm.getLoginPassword();
}
Modified: trunk/src/main/java/cc/kune/core/client/auth/SignInPresenter.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/auth/SignInPresenter.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/auth/SignInPresenter.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -33,6 +33,7 @@
import cc.kune.core.client.i18n.I18nUITranslationService;
import cc.kune.core.client.resources.CoreMessages;
import cc.kune.core.client.rpcservices.UserServiceAsync;
+import cc.kune.core.client.sitebar.auth.AskForPasswordResetPanel;
import cc.kune.core.client.state.Session;
import cc.kune.core.client.state.SiteTokens;
import cc.kune.core.client.state.StateManager;
@@ -68,6 +69,8 @@
HasClickHandlers getAccountRegister();
+ HasClickHandlers getForgotPasswd();
+
String getLoginPassword();
String getNickOrEmail();
@@ -83,7 +86,7 @@
void validate();
}
-
+ private final Provider<AskForPasswordResetPanel> askPasswdReset;
private final EventBus eventBus;
private final Provider<Register> registerProvider;
private final TimerWrapper timer;
@@ -95,13 +98,15 @@
final Session session, final StateManager stateManager, final I18nUITranslationService i18n,
final UserServiceAsync userService, final Provider<Register> registerProvider,
final CookiesManager cookiesManager, final UserPassAutocompleteManager autocomplete,
- final TimerWrapper timeWrapper, final WaveClientSimpleAuthenticator waveClientAuthenticator) {
+ final TimerWrapper timeWrapper, final WaveClientSimpleAuthenticator waveClientAuthenticator,
+ final Provider<AskForPasswordResetPanel> askPasswdReset) {
super(eventBus, view, proxy, session, stateManager, i18n, cookiesManager, autocomplete);
this.eventBus = eventBus;
this.userService = userService;
this.registerProvider = registerProvider;
this.timer = timeWrapper;
this.waveClientAuthenticator = waveClientAuthenticator;
+ this.askPasswdReset = askPasswdReset;
}
@Override
@@ -185,6 +190,12 @@
onAccountRegister();
}
});
+ getView().getForgotPasswd().addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ askPasswdReset.get().show();
+ }
+ });
}
public void onFormSignIn() {
Modified: trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/rpcservices/UserService.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -20,6 +20,7 @@
package cc.kune.core.client.rpcservices;
import cc.kune.core.client.errors.DefaultException;
+import cc.kune.core.client.errors.EmailHashInvalidException;
import cc.kune.core.client.errors.EmailNotFoundException;
import cc.kune.core.shared.domain.UserSNetVisibility;
import cc.kune.core.shared.domain.utils.StateToken;
@@ -55,7 +56,7 @@
UserInfoDTO reloadUserInfo(String userHash) throws DefaultException;
- void resetPassword(String passwdHash, String newpasswd);
+ void resetPassword(String passwdHash, String newpasswd) throws EmailHashInvalidException;
void setBuddiesVisibility(String userHash, StateToken groupToken, UserSNetVisibility visibility);
Modified: trunk/src/main/java/cc/kune/core/client/sitebar/auth/AskForPasswordResetPanel.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/sitebar/auth/AskForPasswordResetPanel.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/sitebar/auth/AskForPasswordResetPanel.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -12,14 +12,16 @@
import cc.kune.core.client.events.StackErrorEvent;
import cc.kune.core.client.rpcservices.UserServiceAsync;
import cc.kune.core.client.state.Session;
+import cc.kune.core.client.state.SiteTokens;
+import cc.kune.core.client.state.StateManager;
import cc.kune.core.client.ui.DefaultForm;
-import com.extjs.gxt.ui.client.widget.form.LabelField;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Label;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -33,18 +35,21 @@
public static final String ERRMSG = "k-ask-for-pwd-error";
public static final String RESET_BUTTON_ID = "k-ask-for-pwd-reset";
private final TextField<String> resetEmail;
+ private final StateManager stateManager;
@Inject
public AskForPasswordResetPanel(final I18nTranslationService i18n, final Session session,
final MaskWidgetView mask, final NotifyLevelImages images, final EventBus eventbus,
- final UserFieldFactory userFieldFactory, final Provider<UserServiceAsync> userService) {
+ final UserFieldFactory userFieldFactory, final Provider<UserServiceAsync> userService,
+ final StateManager stateManager) {
super(ASK_PASSWD_RESET_DIALOG, mask, i18n, i18n.t("Reset your password"), true, true, true, "",
i18n.t("Reset your password"), RESET_BUTTON_ID, i18n.tWithNT("Cancel", "used in button"),
CANCEL_BUTTON_ID, images, ERRMSG, 1);
+ this.stateManager = stateManager;
final DefaultForm form = new DefaultForm();
- final LabelField desc = new LabelField(
+ final Label desc = new Label(
i18n.t("Please enter your email address. You will receive a link to create a new password via email."));
- form.add(desc);
+ desc.setWidth("300px");
resetEmail = userFieldFactory.createUserEmail(EMAIL_RESET_ID);
resetEmail.setFieldLabel(i18n.t("email"));
resetEmail.setTabIndex(1);
@@ -77,14 +82,15 @@
}
}
});
- super.getInnerPanel().add(form.getFormPanel());
super.getSecondBtn().addClickHandler(new ClickHandler() {
-
@Override
public void onClick(final ClickEvent event) {
hide();
}
});
+ super.getInnerPanel().add(desc);
+ super.getInnerPanel().add(form.getFormPanel());
+
}
@Override
@@ -92,6 +98,7 @@
super.hide();
super.messageErrorBar.hideErrorMessage();
resetEmail.clear();
+ stateManager.gotoHistoryToken(SiteTokens.HOME);
}
@Override
Copied: trunk/src/main/java/cc/kune/core/client/sitebar/auth/PasswordResetPanel.java (from rev 1664, trunk/src/main/java/cc/kune/core/client/sitebar/auth/AskForPasswordResetPanel.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/client/sitebar/auth/PasswordResetPanel.java (rev 0)
+++ trunk/src/main/java/cc/kune/core/client/sitebar/auth/PasswordResetPanel.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -0,0 +1,134 @@
+package cc.kune.core.client.sitebar.auth;
+
+import cc.kune.common.client.notify.NotifyLevel;
+import cc.kune.common.client.notify.NotifyLevelImages;
+import cc.kune.common.client.notify.NotifyUser;
+import cc.kune.common.client.ui.MaskWidgetView;
+import cc.kune.common.client.ui.dialogs.MessageToolbar;
+import cc.kune.common.shared.i18n.I18nTranslationService;
+import cc.kune.core.client.auth.SignInAbstractPanel;
+import cc.kune.core.client.auth.UserFieldFactory;
+import cc.kune.core.client.errors.EmailHashInvalidException;
+import cc.kune.core.client.events.StackErrorEvent;
+import cc.kune.core.client.rpcservices.UserServiceAsync;
+import cc.kune.core.client.state.Session;
+import cc.kune.core.client.state.SiteTokens;
+import cc.kune.core.client.state.StateManager;
+import cc.kune.core.client.state.TokenUtils;
+import cc.kune.core.client.ui.DefaultForm;
+
+import com.extjs.gxt.ui.client.widget.form.TextField;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.shared.EventBus;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Label;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+ at Singleton
+public class PasswordResetPanel extends SignInAbstractPanel {
+
+ public static final String CANCEL_BUTTON_ID = "k-pwd-reset-cancel";
+ public static final String ERRMSG = "k-pwd-reset-error";
+ public static final String PASSWD_RESET_DIALOG = "k-pwd-reset-diag";
+ public static final String PASSWD_RESET_ID = "k-pwd-reset-email";
+ public static final String PASSWD2_RESET_DIALOG = "k-pwd-reset-diag";
+ public static final String RESET_BUTTON_ID = "k-pwd-reset-reset";
+ private final TextField<String> confirmPasswdField;
+ private final TextField<String> newPasswdField;
+ private String passwordHash;
+ private final StateManager stateManager;
+
+ @Inject
+ public PasswordResetPanel(final I18nTranslationService i18n, final Session session,
+ final MaskWidgetView mask, final NotifyLevelImages images, final EventBus eventbus,
+ final UserFieldFactory userFieldFactory, final Provider<UserServiceAsync> userService,
+ final StateManager stateManager) {
+ super(PASSWD_RESET_DIALOG, mask, i18n, i18n.t("Reset your password"), true, true, true, "",
+ i18n.t("Reset your password"), RESET_BUTTON_ID, i18n.tWithNT("Cancel", "used in button"),
+ CANCEL_BUTTON_ID, images, ERRMSG, 1);
+ this.stateManager = stateManager;
+ final DefaultForm form = new DefaultForm();
+ final Label desc = new Label(i18n.t("Enter your new password below."));
+ desc.setWidth("300px");
+ newPasswdField = userFieldFactory.createUserPasswd(PASSWD_RESET_ID, i18n.t("New password"));
+ newPasswdField.setTabIndex(1);
+ confirmPasswdField = userFieldFactory.createUserPasswd(PASSWD_RESET_ID, i18n.t("Confirm"));
+ confirmPasswdField.setTabIndex(1);
+
+ messageErrorBar = new MessageToolbar(images, errorLabelId);
+ form.add(newPasswdField);
+ form.add(confirmPasswdField);
+ form.add(messageErrorBar);
+ super.getFirstBtn().addClickHandler(new ClickHandler() {
+ @Override
+ public void onClick(final ClickEvent event) {
+ final String newPass = newPasswdField.getValue();
+ final String confirmPass = confirmPasswdField.getValue();
+ if (form.isValid()) {
+ if (!newPass.equals(confirmPass)) {
+ messageErrorBar.setErrorMessage(i18n.t("Passwords are different"), NotifyLevel.error);
+ messageErrorBar.setVisible(true);
+ } else {
+ userService.get().resetPassword(getPasswordHash(), newPasswdField.getValue(),
+ new AsyncCallback<Void>() {
+ @Override
+ public void onFailure(final Throwable caught) {
+ if (caught instanceof EmailHashInvalidException) {
+ PasswordResetPanel.this.setErrorMessage(i18n.t("Invalid confirmation code"),
+ NotifyLevel.error);
+ } else {
+ PasswordResetPanel.this.setErrorMessage(
+ i18n.t("Other error trying to reset your password"), NotifyLevel.error);
+ }
+ StackErrorEvent.fire(eventbus, caught);
+ PasswordResetPanel.this.messageErrorBar.setVisible(true);
+ }
+
+ @Override
+ public void onSuccess(final Void result) {
+ NotifyUser.info(i18n.t("Your password has been reset. Sign in"));
+ hide();
+ stateManager.gotoHistoryToken(TokenUtils.addRedirect(SiteTokens.HOME,
+ SiteTokens.SIGN_IN));
+ }
+ });
+ }
+ }
+ }
+ });
+ super.getSecondBtn().addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(final ClickEvent event) {
+ hide();
+ }
+ });
+ super.getInnerPanel().add(desc);
+ super.getInnerPanel().add(form.getFormPanel());
+ }
+
+ public String getPasswordHash() {
+ return passwordHash;
+ }
+
+ @Override
+ public void hide() {
+ super.hide();
+ super.messageErrorBar.hideErrorMessage();
+ newPasswdField.clear();
+ confirmPasswdField.clear();
+ stateManager.gotoHistoryToken(SiteTokens.HOME);
+ }
+
+ public void setPasswordHash(final String passwordHash) {
+ this.passwordHash = passwordHash;
+ }
+
+ @Override
+ public void show() {
+ super.show();
+ }
+}
Modified: trunk/src/main/java/cc/kune/core/client/state/SiteTokens.java
===================================================================
--- trunk/src/main/java/cc/kune/core/client/state/SiteTokens.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/client/state/SiteTokens.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -29,6 +29,7 @@
*/
public final class SiteTokens {
public static final String ABOUT_KUNE = "about";
+ public final static String ASK_RESET_PASSWD = "askresetpasswd";
public final static String GROUP_HOME = "";
public final static String GROUP_PREFS = "gprefs";
public final static String HOME = "";
Modified: trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java 2012-01-17 01:24:06 UTC (rev 1664)
+++ trunk/src/main/java/cc/kune/core/server/rpc/UserRPC.java 2012-01-17 12:34:00 UTC (rev 1665)
@@ -210,7 +210,8 @@
@Override
@Transactional
- public void resetPassword(final String passwdHash, final String newpasswd) {
+ public void resetPassword(final String passwdHash, final String newpasswd)
+ throws EmailHashInvalidException {
try {
final User user = userFinder.findByHash(passwdHash);
userManager.changePasswd(user.getId(), null, newpasswd, false);
More information about the kune-commits
mailing list