List of usage examples for com.google.gwt.user.client Cookies setCookie
public static void setCookie(String name, String value, Date expires)
From source file:com.tensegrity.wpalo.client.ui.mvc.viewbrowser.ShowTipsAtStartupDialog.java
License:Open Source License
private final void doShowDialog(String msg, final Date date, final String user) { setData("messageBox", true); setHeading(constants.didYouKnow());/*from ww w .j a v a 2 s . com*/ setResizable(false); setConstrain(true); setMinimizable(false); setMaximizable(false); setMinWidth(100); setClosable(false); setModal(false); setButtonAlign(HorizontalAlignment.CENTER); setMinHeight(80); setPlain(true); setFooter(true); setButtons(MessageBox.YESNOCANCEL); setHideOnButtonClick(false); setCloseAction(CloseAction.CLOSE); addListener(Events.Close, new Listener<BaseEvent>() { public void handleEvent(BaseEvent be) { boolean showTips = true; if (doNotShowAgain != null) { showTips = !doNotShowAgain.getValue(); } String cookieData = showTips + "," + tipNumber; Cookies.setCookie(ViewBrowser.SHOW_TIPS_COOKIE + user, cookieData, date); } }); if (getButtons() != null) { if (getButtons().contains(Dialog.NO)) { setFocusWidget(getButtonBar().getButtonById(Dialog.NO)); } } ButtonBar bb = getButtonBar(); for (int i = 0; i < bb.getItemCount(); i++) { if (bb.getItem(i).getItemId().equalsIgnoreCase(Dialog.CANCEL)) { bb.getItem(i).setText(constants.showNextTip()); } else if (bb.getItem(i).getItemId().equalsIgnoreCase(Dialog.YES)) { bb.getItem(i).setText(constants.showPreviousTip()); } else if (bb.getItem(i).getItemId().equalsIgnoreCase(Dialog.NO)) { bb.getItem(i).setText(constants.ok()); } } doNotShowAgain = new CheckBox(); doNotShowAgain.setBoxLabel(constants.doNotShowTipsAtStartup()); String[] msgs = msg.split("\\|"); String header = "<b>" + constants.didYouKnow() + "</b>"; String message = msg; if (msgs != null && msgs.length == 2) { header = msgs[0]; message = msgs[1]; } HorizontalPanel hp = new HorizontalPanel(); hp.setVerticalAlign(VerticalAlignment.MIDDLE); hp.setStyleName("margin10"); LabelField l1 = new LabelField(); l1.addStyleName("icon-lightbulb"); hp.add(l1); headerLabel = new LabelField(header); hp.add(headerLabel); messageLabel = new LabelField(message); messageLabel.setStyleName("margin10"); add(hp); add(messageLabel); doNotShowAgain.setStyleName("margin10"); add(doNotShowAgain); setHeight(370); setWidth(420); show(); }
From source file:com.tensegrity.wpalo.client.ui.mvc.viewbrowser.ViewBrowser.java
License:Open Source License
private final void checkShowTipCookie(XUser user) { String cookieData = Cookies.getCookie(SHOW_TIPS_COOKIE + user.getLogin()); Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l); if (cookieData == null) { cookieData = "true,1"; }/*from w w w . j a v a 2 s .c om*/ // Update cookie data expiration date: Cookies.setCookie(SHOW_TIPS_COOKIE + user.getLogin(), cookieData, date); String[] values = cookieData.split(","); if (values == null || values.length != 2) { values = new String[2]; values[0] = "true"; values[1] = "1"; } boolean doShow = true; int tipNumber = 1; try { doShow = Boolean.parseBoolean(values[0]); tipNumber = Integer.parseInt(values[1]); } catch (Throwable t) { doShow = true; tipNumber = 1; } if (doShow) { new ShowTipsAtStartupDialog(tipNumber, date, user.getLogin()); } else { cookieData = doShow + "," + tipNumber; Cookies.setCookie(SHOW_TIPS_COOKIE + user.getLogin(), cookieData, date); } }
From source file:com.tensegrity.wpalo.client.WPalo.java
License:Open Source License
private final String setLocale() { String val = Window.Location.getParameter("locale"); if (val == null) { val = Cookies.getCookie("locale"); if (val != null) { String url = Window.Location.getHref(); int index; if ((index = url.indexOf("locale=")) != -1) { int i2 = url.indexOf("&", index); if (i2 == -1) { url = url.substring(0, index) + "locale=" + val; } else { url = url.substring(0, index) + "locale=" + val + url.substring(i2); }//from w ww. j ava 2 s .co m } else { if (url.indexOf("?") != -1) { url += "&locale=" + val; } else { url += "?locale=" + val; } } // Window.Location.assign(url); return url; } } if (val == null || val.isEmpty()) { return null; } if (val.equals(Cookies.getCookie("locale"))) { return null; } Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l); Cookies.setCookie("locale", val, date); return null; }
From source file:com.tensegrity.wpalo.client.WPalo.java
License:Open Source License
private final String setTheme(String url) { String val = Window.Location.getParameter("theme"); if (val == null) { val = Cookies.getCookie("theme"); if (val != null) { if (url == null) { url = Window.Location.getHref(); }/*from w ww .j a v a 2 s. co m*/ int index; if ((index = url.indexOf("theme=")) != -1) { int i2 = url.indexOf("&", index); if (i2 == -1) { url = url.substring(0, index) + "theme=" + val; } else { url = url.substring(0, index) + "theme=" + val + url.substring(i2); } } else { if (url.indexOf("?") != -1) { url += "&theme=" + val; } else { url += "?theme=" + val; } } // Window.Location.assign(url); return url; } } if (val == null || val.isEmpty()) { return url; } if (val.equals(Cookies.getCookie("theme"))) { return url; } Date date = new Date(System.currentTimeMillis() + 1000l * 60l * 60l * 24l * 30l); Cookies.setCookie("theme", val, date); return url; }
From source file:com.xclinical.mdr.client.util.LoginUtils.java
License:Apache License
/** * Stores the specified credentials.// ww w .j a va 2 s. c om * * @param credentials are the credentials to save. */ public static void storeCredentials(String cookie) { Date expiration = new Date(new Date().getTime() + OFFSET); Cookies.setCookie(NAME, cookie, expiration); }
From source file:cz.filmtit.client.Gui.java
License:Open Source License
/** * Set the active sessionID, or set null to unset the sessionID. * Made persistent via cookies.// w ww.j a v a2s . co m */ public static void setSessionID(String newSessionID) { if (newSessionID == null) { Cookies.removeCookie(SESSIONID); } else { Cookies.setCookie(SESSIONID, newSessionID, getDateIn1Year()); } sessionID = newSessionID; }
From source file:cz.filmtit.client.PageHandler.java
License:Open Source License
/** * load a documentId which is not set through a GET parameter; saves it into * a Cookie// w w w . j a v a2s. co m * * @param id */ public void setDocumentId(long id) { this.documentId = id; Cookies.setCookie(DOCUMENTID, Long.toString(id), Gui.getDateIn1Year()); }
From source file:edu.ucla.loni.pipeline.client.Login.LONI_Pipeline_ST_Login_Display.java
License:Open Source License
public void buildMainPage(final UserDTO user, final SessionId sessionId) { mainLayout.setHeight100();/*w ww .j av a 2s . c om*/ mainLayout.setWidth100(); mainLayout.setLayoutAlign(Alignment.CENTER); mainLayout.setAlign(Alignment.CENTER); mainLayout.setAlign(VerticalAlignment.CENTER); mainLayout.setBackgroundColor("#EFF4FA"); VLayout loginLayout = new VLayout(); loginLayout.setLayoutAlign(Alignment.CENTER); loginLayout.setAlign(Alignment.CENTER); loginLayout.setAlign(VerticalAlignment.CENTER); loginLayout.setHeight("250px"); loginLayout.setWidth("280px"); loginLayout.setBorder("3px dashed #B0B0B0"); loginLayout.setBackgroundColor("#FFFFFF"); loginLayout.setMembersMargin(10); VLayout padding; padding = new VLayout(); padding.setMembersMargin(0); padding.setSize("100%", "40px"); loginLayout.addMember(padding); Img logo = new Img(GWT.getModuleBaseURL() + "../images/logo1.png"); logo.setLayoutAlign(Alignment.CENTER); logo.setAlign(Alignment.CENTER); logo.setValign(VerticalAlignment.CENTER); logo.setHeight("200px"); logo.setWidth("234px"); loginLayout.addMember(logo); padding = new VLayout(); padding.setMembersMargin(0); padding.setSize("100%", "20px"); loginLayout.addMember(padding); Label labelSignIn = new Label("Sign in to your account"); labelSignIn.setAlign(Alignment.CENTER); labelSignIn.setHeight("20px"); labelSignIn.setWidth100(); loginLayout.addMember(labelSignIn); FlexTable flexTable = new FlexTable(); loginLayout.addMember(flexTable); flexTable.setWidth("345px"); flexTable.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); flexTable.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER); final Label labelUsername = new Label("Username:"); labelUsername.setAlign(Alignment.CENTER); labelUsername.setHeight("20px"); flexTable.setWidget(0, 0, labelUsername); textboxUsername = new TextBox(); textboxUsername.setValue("loni"); flexTable.setWidget(0, 1, textboxUsername); final Label labelPassword = new Label("Password:"); labelPassword.setAlign(Alignment.CENTER); labelPassword.setHeight("20px"); flexTable.setWidget(1, 0, labelPassword); textboxPassword = new PasswordTextBox(); textboxPassword.setValue("123"); flexTable.setWidget(1, 1, textboxPassword); // final Label labelErrorMessage = new Label("test"); // labelSignIn.setAlign(Alignment.CENTER); // labelSignIn.setHeight("20px"); // labelSignIn.setWidth100(); // loginLayout.addMember(labelErrorMessage); VLayout buttonLayout = new VLayout(); buttonLayout.setLayoutAlign(Alignment.CENTER); buttonLayout.setHeight("30px"); buttonLayout.setWidth("70px"); Button buttonSignIn = new Button("Sign in"); buttonLayout.addMember(buttonSignIn); loginLayout.addMember(buttonLayout); mainLayout.addMember(loginLayout); mainLayout.draw(); buttonSignIn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { System.out.println("onClick()"); user.setUsername(textboxUsername.getText()); user.setPassword(textboxPassword.getText()); System.out.println("Username = " + user.getUsername()); System.out.println("Password = " + user.getPassword()); if (user.getUsername().equals("loni") == false) { Window.alert("Wrong username"); // labelErrorMessage.setTitle("hello"); return; } if (user.getPassword().equals("123") == false) { Window.alert("Wrong password"); // labelErrorMessage.setTitle("hello"); return; } LoginServiceAsync loginServiceAsync = GWT.create(LoginService.class); System.out.println("After creation"); AsyncCallback<String> asyncCallback = new AsyncCallback<String>() { @Override public void onSuccess(String result) { System.out.println("onClick(): onSuccess"); if (result != null) { System.out.println("Set Cookie: result = " + result); Cookies.setCookie("session", result, new Date(System.currentTimeMillis() + TWO_MIN)); sessionId.setSessionId(result); System.out.println("Login Successful"); System.out.println("Login session => " + result); } else { System.out.println("Login Invalid !"); } } @Override public void onFailure(Throwable caught) { System.out.println("onClick(): onFailure"); System.out.println(caught); } }; loginServiceAsync.login(user, asyncCallback); mainLayout.clear(); wbst = new LONI_Pipeline_ST_Tabset_Display("Guest"); wbst.buildMainPage(user, sessionId); } }); }
From source file:edu.ucsb.eucalyptus.admin.client.EucalyptusWebInterface.java
License:Open Source License
public void displayLoginPage(String greeting) { History.newItem("login"); label_box.setText(greeting);/*from w w w .j av a2s . c o m*/ label_box.setStyleName("euca-greeting-normal"); final TextBox login_box = new TextBox(); login_box.setFocus(true); // this box gets focus first final PasswordTextBox pass_box = new PasswordTextBox(); ClickListener LoginButtonListener = new ClickListener() { public void onClick(Widget sender) { /* perform checks */ if (login_box.getText().length() < 1) { displayLoginErrorPage("Username is empty!"); return; } if (pass_box.getText().length() < 1) { displayLoginErrorPage("Password is empty!"); return; } label_box.setText("Contacting the server..."); label_box.setStyleName("euca-greeting-pending"); EucalyptusWebBackend.App.getInstance().getNewSessionID(login_box.getText(), GWTUtils.md5(pass_box.getText()), new AsyncCallback() { public void onSuccess(Object result) { sessionId = (String) result; long expiresMs = System.currentTimeMillis() + (7 * 24 * 60 * 60 * 1000); /* week */ Date expires = new Date(expiresMs); if (check_box.isChecked()) { Cookies.setCookie(cookie_name, sessionId, expires); } else { /* this cookie should expire at the end of the session */ /* TODO: does this work right in all browsers? */ Cookies.setCookie(cookie_name, sessionId, new Date(0)); } attemptLogin(); } public void onFailure(Throwable caught) { displayLoginErrorPage((String) caught.getMessage()); } }); } }; ClickListener RecoverButtonListener = new ClickListener() { public void onClick(Widget sender) { displayInitiatePasswordRecoveryPage(); } }; Button submit_button = new Button(MSG.signInButton(), LoginButtonListener); Hyperlink signup_button = new Hyperlink(MSG.applyButton(), "apply"); signup_button.addClickListener(AddUserButtonListener); Hyperlink recover_button = new Hyperlink(MSG.recoverButton(), "recover"); recover_button.addClickListener(RecoverButtonListener); remember_label.setStyleName("euca-remember-text"); /* enable login by pressing Enter */ EucalyptusKeyboardListener sl = new EucalyptusKeyboardListener(submit_button); submit_button.addKeyboardListener(sl); login_box.addKeyboardListener(sl); pass_box.addKeyboardListener(sl); Grid g = new Grid(4, 2); g.setCellSpacing(4); g.setWidget(0, 0, new Label(MSG.usernameField() + ":")); g.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_RIGHT); g.setWidget(1, 0, new Label(MSG.passwordField() + ":")); g.getCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT); g.setWidget(0, 1, login_box); g.setWidget(1, 1, pass_box); g.setWidget(2, 0, check_box); g.getCellFormatter().setHorizontalAlignment(2, 0, HasHorizontalAlignment.ALIGN_RIGHT); g.setWidget(2, 1, remember_label); g.setWidget(3, 1, submit_button); VerticalPanel panel = new VerticalPanel(); panel.add(g); panel.setStyleName("euca-login-panel"); panel.setCellHorizontalAlignment(g, HasHorizontalAlignment.ALIGN_CENTER); panel.setCellVerticalAlignment(g, HasVerticalAlignment.ALIGN_MIDDLE); HorizontalPanel hpanel = new HorizontalPanel(); hpanel.setSpacing(2); if (enable_signups) { hpanel.add(signup_button); hpanel.add(new HTML(" " + MSG.forAccount() + " | ")); } hpanel.add(recover_button); hpanel.add(new HTML(" " + MSG.thePassword())); VerticalPanel vpanel = new VerticalPanel(); vpanel.setSpacing(15); vpanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); if (logo != null) { vpanel.add(logo); } if (version != null) { Label version_label = new Label("Version " + version); version_label.setStyleName("euca-small-text"); vpanel.add(version_label); } vpanel.add(label_box); vpanel.add(panel); if (server_ready.booleanValue()) { vpanel.add(hpanel); } VerticalPanel wrapper = new VerticalPanel(); wrapper.add(vpanel); wrapper.setSize("100%", "100%"); wrapper.setCellHorizontalAlignment(vpanel, VerticalPanel.ALIGN_CENTER); wrapper.setCellVerticalAlignment(vpanel, VerticalPanel.ALIGN_MIDDLE); RootPanel.get().clear(); RootPanel.get().add(wrapper); }
From source file:eml.studio.client.IndexPage.java
License:Open Source License
/** * Enter login action //from w ww . j a va 2 s . c om */ public void enterLogin() { Account account = new Account(); if (loginPanel.getAutoLogin()) { account.setEmail(loginPanel.getEmail()); account.setSerial(Cookies.getCookie("bdaserial")); accountSrv.autoLogin(account, new AsyncCallback<Account>() { @Override public void onFailure(Throwable caught) { loginPanel.errorLabel.setText(Constants.logUIMsg.loginErrorMsg()); } @Override public void onSuccess(Account account) { if (account != null) { loginPanel.hide(); String refer = Window.Location.getParameter("url"); if (refer == null) AppController.redirect("EMLStudio.html"); else Window.Location.replace(refer); } else { loginPanel.errorLabel.setText(Constants.logUIMsg.loginWrongMsg()); } } }); } else { account.setEmail(loginPanel.getEmail()); account.setPassword(loginPanel.getPassword()); accountSrv.login(account, new AsyncCallback<Account>() { @Override public void onFailure(Throwable caught) { loginPanel.errorLabel.setText(Constants.logUIMsg.loginErrorMsg()); } @Override public void onSuccess(Account account) { if (account != null) { Cookies.setCookie("bdaemail", account.getEmail(), Util.getCookieExpireDate()); if (loginPanel.getRemmenber()) { Cookies.setCookie("bdaserial", account.getSerial(), Util.getCookieExpireDate()); } loginPanel.hide(); String refer = Window.Location.getParameter("url"); if (refer == null) AppController.redirect("EMLStudio.html"); else Window.Location.replace(refer); } else { loginPanel.errorLabel.setText(Constants.logUIMsg.loginWrongMsg()); } } }); } }