use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class GetGroupsCount method onFinished.
/**
* Called when loading successfully finishes.
*/
public void onFinished(JavaScriptObject jso) {
BasicOverlayType count = (BasicOverlayType) jso;
session.getUiElements().setLogText("Loading groups count finished: " + count.getInt());
this.groupsCountLabel.setText(String.valueOf(count.getInt()));
this.hyp.setText(String.valueOf(count.getInt()));
this.events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class TestJSONParserTabItem method draw.
public Widget draw() {
Button sendMessageButton = new Button("Parse response");
final FlexTable ft = new FlexTable();
ft.setCellSpacing(15);
int row = 0;
ft.setText(row, 0, "Server response:");
ft.setWidget(row, 1, returnedValue);
row++;
ft.setText(row, 0, "Callback name:");
ft.setHTML(row, 1, "callbackPost");
row++;
ft.setWidget(row, 0, sendMessageButton);
row++;
sendMessageButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
String resp = returnedValue.getText();
// trims the whitespace
resp = resp.trim();
// short comparing
if (("callbackPost(null);").equalsIgnoreCase(resp)) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
RegExp re = RegExp.compile("^" + "callbackPost" + "\\((.*)\\)|\\);$");
MatchResult result = re.exec(resp);
if (result != null) {
resp = result.getGroup(1);
}
UiElements.generateInfo("Unwrapped value", "Non-null unwrapped value is: " + resp);
// if response = null - return null
if (resp.equals("null")) {
UiElements.generateInfo("Parser result", "Parsed value is: NULL");
}
// normal object
JavaScriptObject jso = JsonUtils.parseJson(resp);
BasicOverlayType basic = jso.cast();
UiElements.generateInfo("Parser result", "Parsed result is: " + basic.getString());
}
});
this.contentWidget.setWidget(ft);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class AddLoginTabItem method draw.
public Widget draw() {
titleWidget.setText("Add login");
VerticalPanel vp = new VerticalPanel();
vp.setSize("100%", "100%");
final ExtendedTextBox userLogin = new ExtendedTextBox();
final ListBox namespace = new ListBox();
final CustomButton createLogin = TabMenu.getPredefinedButton(ButtonType.ADD, "Add login in selected namespace");
final Label notice = new Label("Your login will be automatically generated.");
notice.setVisible(false);
// offer only available namespaces.
ArrayList<String> logins = new ArrayList<String>();
for (Attribute a : usersLogins) {
logins.add(a.getFriendlyNameParameter());
}
for (String s : Utils.getSupportedPasswordNamespaces()) {
if (!logins.contains(s)) {
namespace.addItem(s.toUpperCase(), s);
}
}
final ExtendedTextBox.TextBoxValidator loginValidator = new ExtendedTextBox.TextBoxValidator() {
@Override
public boolean validateTextBox() {
if (userLogin.getTextBox().getValue().trim().isEmpty()) {
userLogin.setError("Login can't be empty!");
return false;
}
RegExp regExp = RegExp.compile(Utils.LOGIN_VALUE_MATCHER);
boolean match = regExp.test(userLogin.getTextBox().getValue().trim());
if (!match) {
userLogin.setError("Invalid format!");
return false;
}
if (userLogin.isProcessing() || userLogin.isHardError()) {
return false;
}
userLogin.setOk();
return true;
}
};
userLogin.setValidator(loginValidator);
final FlexTable layout = new FlexTable();
layout.addStyleName("inputFormFlexTable");
layout.setHTML(0, 0, "Namespace:");
layout.setHTML(1, 0, "Login:");
for (int i = 0; i < layout.getRowCount(); i++) {
layout.getFlexCellFormatter().addStyleName(i, 0, "itemName");
}
layout.setWidget(0, 1, namespace);
layout.setWidget(1, 1, userLogin);
layout.getFlexCellFormatter().setColSpan(2, 0, 2);
layout.setWidget(2, 0, notice);
layout.getFlexCellFormatter().addStyleName(2, 0, "inputFormInlineComment");
HTML help = new HTML("Login must<ul><li>start with lower-cased letter<li>be 2-15 characters long<li>consist only of<ul><li>lower-cased non-accented letters<li>digits<li>hyphens and underscores</ul></ul>");
help.setVisible(false);
layout.getFlexCellFormatter().setColSpan(3, 0, 2);
layout.setWidget(3, 0, help);
layout.getFlexCellFormatter().addStyleName(3, 0, "inputFormInlineComment");
TabMenu menu = new TabMenu();
menu.addWidget(createLogin);
final TabItem tab = this;
menu.addWidget(TabMenu.getPredefinedButton(ButtonType.CANCEL, "", new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
session.getTabManager().closeTab(tab, isRefreshParentOnClose());
}
}));
// user can't add new login
if (namespace.getItemCount() == 0) {
vp.add(new HTML("<p><strong>You already have login in all supported namespaces!</strong></p>"));
createLogin.setEnabled(false);
} else {
// user can add new login
vp.add(layout);
// check login availability
userLogin.getTextBox().addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent keyUpEvent) {
if (keyUpEvent.isDownArrow() || keyUpEvent.isUpArrow() || keyUpEvent.isLeftArrow() || keyUpEvent.isRightArrow()) {
// do not trigger when no text input
return;
}
final String value = userLogin.getTextBox().getValue().trim();
// trigger new validation on checked input or if previously was hard error
if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
BasicOverlayType bo = jso.cast();
userLogin.setProcessing(false);
if (!bo.getBoolean()) {
userLogin.setHardError("Login is already in use!");
} else {
userLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.removeHardError();
userLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
if ("InvalidLoginException".equalsIgnoreCase(error.getName())) {
userLogin.setProcessing(false);
String text = error.getErrorInfo();
text = text.split(":", 2)[1];
text = (text == null || text.isEmpty()) ? error.getErrorInfo() : text;
userLogin.setHardError(text);
} else {
// generic error
userLogin.setProcessing(false);
userLogin.setHardError("Unable to check if login is available!");
}
}
}
}).retrieveData();
}
}
});
namespace.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent changeEvent) {
if (namespace.getSelectedValue().equals("einfra")) {
help.setVisible(true);
} else {
help.setVisible(false);
}
if (namespace.getSelectedValue().equals("mu")) {
userLogin.getTextBox().setValue("");
userLogin.removeHardError();
userLogin.setOk();
userLogin.getTextBox().setEnabled(false);
notice.setVisible(true);
} else {
userLogin.getTextBox().setEnabled(true);
notice.setVisible(false);
final String value = userLogin.getTextBox().getValue().trim();
// trigger new validation on checked input or if previously was hard error
if ((!value.isEmpty() && RegExp.compile(Utils.LOGIN_VALUE_MATCHER).test(value)) || userLogin.isHardError()) {
new IsLoginAvailable(namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
BasicOverlayType bo = jso.cast();
userLogin.setProcessing(false);
if (!bo.getBoolean()) {
userLogin.setError("Login is already in use!");
} else {
userLogin.removeHardError();
loginValidator.validateTextBox();
}
}
}
@Override
public void onLoadingStart() {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.removeHardError();
userLogin.setProcessing(true);
}
}
@Override
public void onError(PerunError error) {
if (value.equals(userLogin.getTextBox().getValue().trim())) {
userLogin.setProcessing(false);
userLogin.setHardError("Error while loading.");
}
}
}).retrieveData();
}
}
}
});
createLogin.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (namespace.getSelectedValue().equals("mu")) {
session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
} else {
if (!loginValidator.validateTextBox())
return;
SetLogin request = new SetLogin(JsonCallbackEvents.disableButtonEvents(createLogin, new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.getTabManager().addTabToCurrentTab(new SelfPasswordTabItem(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim(), SelfPasswordTabItem.Actions.CREATE));
}
}));
request.setLogin(user, namespace.getValue(namespace.getSelectedIndex()), userLogin.getTextBox().getValue().trim());
}
}
});
}
if (namespace.getSelectedValue().equals("mu")) {
userLogin.getTextBox().setValue("");
userLogin.removeHardError();
userLogin.setOk();
userLogin.getTextBox().setEnabled(false);
notice.setVisible(true);
} else if (namespace.getSelectedValue().equals("einfra")) {
help.setVisible(true);
}
vp.add(menu);
vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);
this.contentWidget.setWidget(vp);
return getWidget();
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class GetMembersCount method onFinished.
/**
* Called when loading successfully finishes.
*/
public void onFinished(JavaScriptObject jso) {
BasicOverlayType count = (BasicOverlayType) jso;
session.getUiElements().setLogText("Loading members count finished: " + count.getInt());
this.membersCountLabel.setText(String.valueOf(count.getInt()));
this.hyp.setText(String.valueOf(count.getInt()));
this.events.onFinished(jso);
}
use of cz.metacentrum.perun.webgui.model.BasicOverlayType in project perun by CESNET.
the class PasswordResetGui method loadPerunPrincipal.
/**
* Performs a login into the RPC, loads user and his roles into session and enables GUI.
*/
private void loadPerunPrincipal() {
// show loading box
final PopupPanel loadingBox = session.getUiElements().perunLoadingBox();
loadingBox.show();
// events after getting PerunPrincipal from RPC
final JsonCallbackEvents events = new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
// store perun principal into session for future use
PerunPrincipal pp = (PerunPrincipal) jso;
session.setPerunPrincipal(pp);
// check if user exists
if (session.getUser() != null && !pp.getRoles().hasAnyRole() && !session.getRpcUrl().startsWith("/non/rpc")) {
// if not and no role, redraw page body
RootLayoutPanel body = RootLayoutPanel.get();
loadingBox.hide();
body.clear();
body.add(new NotUserOfPerunWidget());
return;
}
if (session.getUser() != null && !pp.getRoles().hasAnyRole()) {
// store users roles and editable entities into session
session.setRoles(pp.getRoles());
// display logged user
session.getUiElements().setLoggedUserInfo(pp);
}
GetGuiConfiguration getConf = new GetGuiConfiguration(new JsonCallbackEvents() {
@Override
public void onFinished(JavaScriptObject jso) {
session.setConfiguration((BasicOverlayType) jso.cast());
// hides the loading box
loadingBox.hide();
if (session.getRpcUrl().startsWith("/non/rpc")) {
// CHALLENGE WITH CAPTCHA
FlexTable ft = new FlexTable();
ft.setSize("100%", "500px");
// captcha with public key
String key = Utils.getReCaptchaPublicKey();
if (key == null) {
PerunError error = new JSONObject().getJavaScriptObject().cast();
error.setErrorId("0");
error.setName("Missing public key");
error.setErrorInfo("Public key for Re-Captcha service is missing. Please add public key to GUIs configuration file.");
error.setRequestURL("");
UiElements.generateError(error, "Missing public key", "Public key for Re-Captcha service is missing.<br />Accessing password reset without authorization is not possible.");
loadingBox.hide();
return;
}
final RecaptchaWidget captcha = new RecaptchaWidget(key, LocaleInfo.getCurrentLocale().getLocaleName(), "clean");
final CustomButton cb = new CustomButton();
cb.setIcon(SmallIcons.INSTANCE.arrowRightIcon());
cb.setText(ApplicationMessages.INSTANCE.captchaSendButton());
cb.setImageAlign(true);
final TextBox response = new TextBox();
captcha.setOwnTextBox(response);
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
response.setFocus(true);
}
});
response.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
cb.click();
}
}
});
cb.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent clickEvent) {
VerifyCaptcha req = new VerifyCaptcha(captcha.getChallenge(), captcha.getResponse(), JsonCallbackEvents.disableButtonEvents(cb, new JsonCallbackEvents() {
public void onFinished(JavaScriptObject jso) {
BasicOverlayType bt = jso.cast();
if (bt.getBoolean()) {
// OK captcha answer - load GUI
// add menu item and load content
contentPanel.setWidget(new PasswordResetFormPage().getContent());
//Anchor a = leftMenu.addMenuContents("Password reset", SmallIcons.INSTANCE.keyIcon(), new PasswordResetFormPage().getContent());
//a.fireEvent(new ClickEvent(){});
} else {
// wrong captcha answer
UiElements.generateAlert(ApplicationMessages.INSTANCE.captchaErrorHeader(), ApplicationMessages.INSTANCE.captchaErrorMessage());
}
}
}));
req.retrieveData();
}
});
// set layout
int row = 0;
ft.getFlexCellFormatter().setAlignment(row, 0, HasHorizontalAlignment.ALIGN_CENTER, HasVerticalAlignment.ALIGN_MIDDLE);
ft.setHTML(row, 0, "<h2>In order to continue to the password reset page, please, use CAPTCHA below.</h2>");
ft.setWidget(row + 1, 0, captcha);
ft.getFlexCellFormatter().setHorizontalAlignment(row + 1, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(row + 1, 0, HasVerticalAlignment.ALIGN_BOTTOM);
FlexTable sendFt = new FlexTable();
sendFt.setStyleName("inputFormFlexTable");
sendFt.setWidget(0, 0, response);
sendFt.setWidget(0, 1, cb);
ft.setWidget(row + 2, 0, sendFt);
ft.getFlexCellFormatter().setHorizontalAlignment(row + 2, 0, HasHorizontalAlignment.ALIGN_CENTER);
ft.getFlexCellFormatter().setVerticalAlignment(row + 2, 0, HasVerticalAlignment.ALIGN_TOP);
ft.setHeight("100%");
ft.getFlexCellFormatter().setHeight(row, 0, "50%");
ft.getFlexCellFormatter().setHeight(row + 2, 0, "50%");
// finish loading GUI
loadingBox.hide();
contentPanel.setWidget(ft);
} else {
// add menu item and load content
contentPanel.setWidget(new PasswordResetFormPage().getContent());
//Anchor a = leftMenu.addMenuContents("Password reset", SmallIcons.INSTANCE.keyIcon(), new PasswordResetFormPage().getContent());
//a.fireEvent(new ClickEvent(){});
}
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
leftMenu.addItem("Password reset", SmallIcons.INSTANCE.keyIcon(), null);
}
});
getConf.retrieveData();
}
@Override
public void onError(PerunError error) {
// hides the loading box
loadingBox.hide();
// shows error box
PopupPanel loadingFailedBox;
if (error == null) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("Request timeout exceeded.");
} else {
if (error.getName().contains("UserNotExistsException")) {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox("You are not registered to any Virtual Organization.</br></br>" + error.getErrorInfo());
} else {
loadingFailedBox = session.getUiElements().perunLoadingFailedBox(error.getErrorInfo());
}
}
loadingFailedBox.show();
leftMenu.addItem("Password reset", SmallIcons.INSTANCE.keyIcon(), null);
}
};
GetPerunPrincipal loggedUserRequest = new GetPerunPrincipal(events);
loggedUserRequest.retrieveData();
}
Aggregations