Skip to content

Commit

Permalink
Made it show an error-message, if old password is wrong when changing BC
Browse files Browse the repository at this point in the history
account password
  • Loading branch information
KlasJoensson committed Sep 5, 2012
1 parent b70b147 commit 4f15c8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Expand Up @@ -429,7 +429,7 @@ public void clearAccounts() {
* @param masterkey old password
* @param newkey new password
*/
public void changePassword(String masterkey, String newkey) {
public void changePassword(String masterkey, String newkey) throws IllegalArgumentException {

if ( encryptedPassword.matches( masterkey ) ) {

Expand Down
Expand Up @@ -11,6 +11,8 @@

package net.bioclipse.usermanager.dialogs;

import net.bioclipse.usermanager.UserContainer;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
Expand All @@ -23,6 +25,7 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;

/**
* A dialog used to change the password for an user
Expand All @@ -36,12 +39,16 @@ public class ChangePasswordDialog extends Dialog {
private Text oldPasswordText;
private String oldPassword;
private String newPassword;
private Label errorMessage;
private UserContainer sandbox;

/**
* Create the dialog
* @param parentShell
*/
public ChangePasswordDialog(Shell parentShell) {
public ChangePasswordDialog(Shell parentShell, UserContainer userContainer) {
super(parentShell);
this.sandbox = userContainer;
}

/**
Expand Down Expand Up @@ -80,7 +87,13 @@ protected Control createDialogArea(Composite parent) {
formData_3.right = new FormAttachment(100, -35);
formData_3.bottom = new FormAttachment(newPasswordLabel, 0, SWT.BOTTOM);
newPasswordText.setLayoutData(formData_3);
//

errorMessage = new Label(container, SWT.NONE);
final FormData formData_4 = new FormData();
formData_4.top = new FormAttachment(oldPasswordText, 3, SWT.BOTTOM);
formData_4.left = new FormAttachment(oldPasswordText, 0, SWT.LEFT);
errorMessage.setLayoutData( formData_4 );

return container;
}

Expand Down Expand Up @@ -109,9 +122,18 @@ protected void configureShell(Shell newShell) {
}
protected void buttonPressed(int buttonId) {
if (buttonId == IDialogConstants.OK_ID) {

this.oldPassword = oldPasswordText.getText();
this.newPassword = newPasswordText.getText();
try {
sandbox.changePassword( oldPassword, newPassword );
} catch (IllegalArgumentException e) {
errorMessage.setText( "Wrong password" );
errorMessage.setForeground( PlatformUI.getWorkbench()
.getDisplay()
.getSystemColor( SWT.COLOR_RED ) );
errorMessage.pack();
return;
}
}
super.buttonPressed(buttonId);
}
Expand Down
Expand Up @@ -338,11 +338,13 @@ public void widgetSelected(SelectionEvent e) {
new ChangePasswordDialog( PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getShell() );
if(dialog.open() == Window.OK) {
sandBoxUserContainer.changePassword( dialog.getOldPassword(),
dialog.getNewPassword() );
}
.getShell(), sandBoxUserContainer );
dialog.open();
// if(dialog.open() == Window.OK) {
// sandBoxUserContainer.changePassword( dialog.getOldPassword(),
// dialog.getNewPassword() );
//
// }
}
});
final FormData formData_8 = new FormData();
Expand Down

0 comments on commit 4f15c8c

Please sign in to comment.