use of cz.metacentrum.perun.webgui.json.usersManager.ChangeNonAuthzPassword in project perun by CESNET.
the class PasswordResetFormPage method drawNonAuthzPasswordReset.
public Widget drawNonAuthzPasswordReset(VerticalPanel vp) {
final String i = Location.getParameter("i");
final String m = Location.getParameter("m");
final ExtendedPasswordBox passBox = new ExtendedPasswordBox();
final ExtendedPasswordBox secondPassBox = new ExtendedPasswordBox();
final ExtendedTextBox.TextBoxValidator validator;
final ExtendedTextBox.TextBoxValidator validator2;
final CustomButton resetPass = new CustomButton("Reset password", "Reset password", SmallIcons.INSTANCE.keyIcon());
validator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (passBox.getTextBox().getValue().trim().isEmpty()) {
passBox.setError("Password can't be empty !");
return false;
} else if (!passBox.getTextBox().getValue().trim().equals(secondPassBox.getTextBox().getValue().trim())) {
passBox.setError("Password in both textboxes must be the same !");
return false;
} else {
passBox.setOk();
secondPassBox.setOk();
return true;
}
}
};
validator2 = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (secondPassBox.getTextBox().getValue().trim().isEmpty()) {
secondPassBox.setError("Password can't be empty !");
return false;
} else if (!secondPassBox.getTextBox().getValue().trim().equals(passBox.getTextBox().getValue().trim())) {
secondPassBox.setError("Password in both textboxes must be the same !");
return false;
} else {
secondPassBox.setOk();
passBox.setOk();
return true;
}
}
};
passBox.setValidator(validator);
secondPassBox.setValidator(validator2);
FlexTable ft = new FlexTable();
ft.setSize("300px", "100px");
ft.addStyleName("inputFormFlexTable");
ft.getElement().setAttribute("style", "margin: auto;");
ft.getFlexCellFormatter().setColSpan(0, 0, 2);
ft.setHTML(0, 0, "Password reset");
ft.getFlexCellFormatter().setStyleName(0, 0, "now-managing");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.setHTML(1, 0, "New password:");
ft.getFlexCellFormatter().setStyleName(1, 0, "itemName");
ft.setWidget(1, 1, passBox);
ft.setHTML(2, 0, "Retype new password:");
ft.getFlexCellFormatter().setStyleName(2, 0, "itemName");
ft.setWidget(2, 1, secondPassBox);
resetPass.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ChangeNonAuthzPassword changepw = new ChangeNonAuthzPassword(JsonCallbackEvents.disableButtonEvents(resetPass, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
bodyContents.clear();
FlexTable ft = new FlexTable();
ft.setSize("100%", "300px");
ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.acceptIcon()) + "<h2>Password successfully changed!</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setHTML(1, 0, "<h2>New password will work on all resources in approx. 15 minutes after reset.</h2>");
ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_MIDDLE);
bodyContents.setWidget(ft);
}
}));
if (validator.validateTextBox() && validator2.validateTextBox()) {
changepw.changeNonAuthzPassword(i, m, passBox.getTextBox().getText().trim());
}
}
});
vp.add(ft);
TabMenu menu = new TabMenu();
menu.addWidget(resetPass);
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
return bodyContents;
}
Aggregations