// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
public class PasswordWizard extends Wizard implements IConversationEnabled{
private PasswordWizardPage passwordPage;
- private User user;
- private ConversationHolder conversation;
-
- public PasswordWizard(ConversationHolder conversation, User user){
+ private final User user;
+ private final ConversationHolder conversation;
+
+ /**
+ * @param user the user to change the password for
+ * @param conversation this optional parameter can be null. Only supply conversation if you
+ * need to run this wizard is a nested conversation
+ */
+ public PasswordWizard(User user, ConversationHolder conversation){
this.conversation = conversation;
this.user = user;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#addPages()
*/
@Override
public void addPages() {
CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
-
+
passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
addPage(passwordPage);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
@Override
public boolean performFinish() {
- String userName = user.getUsername();
- ConversationHolder internalConversation = CdmStore.getLoginManager().getConversationHolder();
- internalConversation.bind();
+
+ ConversationHolder internalConversation = CdmStore.getCurrentApplicationConfiguration().NewConversation();
+ internalConversation.bind();
+ internalConversation.startTransaction();
try{
- if(CdmStore.getLoginManager().isAdmin()){
- CdmStore.getService(IUserService.class).changePasswordForUser(userName, passwordPage.getNewPassword());
- }else{
+ if(passwordPage.isChangingOwnPassword()){
+ // change own password with validating of old one
CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
+ }else{
+ // change others passwords
+ CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
}
- internalConversation.commit();
+ internalConversation.commit(false);
+ internalConversation.unbind();
+ internalConversation.close();
return true;
}catch(Exception e){
StoreUtil.errorDialog("Error while changing password", getClass(), "There was a problem changing the password.", e);
return false;
}finally{
- conversation.bind();
+ if(conversation != null){
+ conversation.bind();
+ }
}
}
@Override
public void update(CdmDataChangeMap arg0) {
// TODO Auto-generated method stub
-
+
}
/* (non-Javadoc)