List of usage examples for org.apache.wicket.request.http WebRequest getPostParameters
public IRequestParameters getPostParameters()
From source file:org.bosik.diacomp.web.frontend.wicket.pages.register.RegisterPage.java
License:Open Source License
@Override protected void onInitialize() { super.onInitialize(); feedbackPanel = new FeedbackPanel("feedbackPanel"); feedbackPanel.setOutputMarkupId(true); add(feedbackPanel);/*from w w w . j a va 2s.c o m*/ final WebMarkupContainer progressContainer = new WebMarkupContainer("progressContainer"); progressContainer.setOutputMarkupId(true); add(progressContainer); progressBehavior = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) { private static final long serialVersionUID = 1L; @Override protected void onPostProcessTarget(AjaxRequestTarget target) { if (progress.isRunning()) { progressSpinner.setVisible(true); } else { progressSpinner.setVisible(false); progressBehavior.stop(null); buttonRegister.setEnabled(true); target.add(buttonRegister); if (progress.isSuccess()) { Page succeedPage = new RegistrationSentPage(Model.of(progress.getMessage())); setResponsePage(succeedPage); } else { feedbackPanel.error(progress.getMessage()); target.add(feedbackPanel); } } } }; progressBehavior.stop(null); progressContainer.add(progressBehavior); progressSpinner = new WebMarkupContainer("progressSpinner"); progressSpinner.setOutputMarkupId(true); progressSpinner.setVisible(false); progressContainer.add(progressSpinner); Form<Void> form = new Form<>("regForm"); form.setOutputMarkupId(true); add(form); final TextField<String> fieldEmail = new TextField<>("rhCyIStebK", Model.of("")); fieldEmail.add(EmailAddressValidator.getInstance()); form.add(fieldEmail); final HiddenField<String> fieldFakeEmail = new HiddenField<>("email", Model.of("")); form.add(fieldFakeEmail); final PasswordTextField fieldPassword = new PasswordTextField("P2BohS6rUR", Model.of("")); fieldPassword.setRequired(false); // to handle it manually form.add(fieldPassword); form.add(new BookmarkablePageLink<Void>("linkEula", EulaPage.class)); form.add(new BookmarkablePageLink<Void>("linkPrivacy", PrivacyPolicyPage.class)); buttonRegister = new AjaxFallbackButton("buttonRegister", form) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { final String antiBot = fieldFakeEmail.getModelObject(); if (antiBot != null && !antiBot.isEmpty()) { form.clearInput(); return; } final WebRequest request = (WebRequest) RequestCycle.get().getRequest(); final String challenge = request.getPostParameters().getParameterValue("g-recaptcha-response") .toString(); final String secret = Config.get(Config.KEY_CAPTCHA_SECRET); final String MSG_ERROR_CAPTCHA = getString("error.captcha"); final String MSG_ERROR_EMAIL = getString("error.wrongEmail"); final String MSG_ERROR_DUPLICATION = getString("error.emailInUse"); final String MSG_ERROR_PASSWORD_IS_EMPTY = getString("error.password.empty"); final String MSG_ERROR_PASSWORD_TOO_SHORT = getString("error.password.tooShort"); final String MSG_ERROR_PASSWORD_TOO_LONG = getString("error.password.tooLong"); final String MSG_ERROR_USERNAME_IS_EMPTY = getString("error.userName.empty"); final String MSG_ERROR_USERNAME_TOO_SHORT = getString("error.userName.tooShort"); final String MSG_ERROR_USERNAME_TOO_LONG = getString("error.userName.tooLong"); final String MSG_ERROR_COMMON = getString("error.common"); final String appUrlRaw = Config.get(Config.KEY_APP_URL); final String appUrl = appUrlRaw.endsWith("/") ? appUrlRaw : appUrlRaw + "/"; final String bodyPattern = getString("email.body"); final String title = getString("email.title"); final String sender = getString("email.sender"); progressBehavior.restart(target); buttonRegister.setEnabled(false); progressSpinner.setVisible(true); Session.get().getFeedbackMessages().clear(); target.add(buttonRegister, progressSpinner, feedbackPanel); new Thread() { @Override public void run() { try { progress = new ProgressBundle(); progress.setRunning(true); if (!Utils.validateCaptcha(secret, challenge)) { progress.fail(MSG_ERROR_CAPTCHA); return; } String email = fieldEmail.getModelObject(); String password = fieldPassword.getModelObject(); if (!StringUtils.isEmpty(email)) { email = email.toLowerCase(); } String activationKey = authService.register(email, password); String activationLink = String.format("%sregister/activate?key=%s", appUrl, activationKey); String body = String.format(bodyPattern, activationLink, activationLink); Utils.sendEmail(email, title, body, sender); progress.success(email); } catch (UserNameIsEmptyException e) { progress.fail(MSG_ERROR_USERNAME_IS_EMPTY); } catch (UserNameTooShortException e) { progress.fail(MSG_ERROR_USERNAME_TOO_SHORT); } catch (UserNameTooLongException e) { progress.fail(MSG_ERROR_USERNAME_TOO_LONG); } catch (PasswordIsEmptyException e) { progress.fail(MSG_ERROR_PASSWORD_IS_EMPTY); } catch (PasswordTooShortException e) { progress.fail(MSG_ERROR_PASSWORD_TOO_SHORT); } catch (PasswordTooLongException e) { progress.fail(MSG_ERROR_PASSWORD_TOO_LONG); } catch (MessagingException e) { progress.fail(MSG_ERROR_EMAIL); } catch (DuplicateException e) { progress.fail(MSG_ERROR_DUPLICATION); } catch (Exception e) { e.printStackTrace(); progress.fail(MSG_ERROR_COMMON); } } }.start(); } }; buttonRegister.setOutputMarkupId(true); form.add(buttonRegister); }
From source file:org.bosik.diacomp.web.frontend.wicket.pages.restore.RestorePage.java
License:Open Source License
@Override protected void onInitialize() { super.onInitialize(); final StringValue parKey = getPageParameters().get("email"); final String defaultEmail = parKey.toString(""); feedbackPanel = new FeedbackPanel("feedbackPanel"); feedbackPanel.setOutputMarkupId(true); add(feedbackPanel);//from www . j a v a 2 s . com final WebMarkupContainer progressContainer = new WebMarkupContainer("progressContainer"); progressContainer.setOutputMarkupId(true); add(progressContainer); progressBehavior = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) { private static final long serialVersionUID = 1L; @Override protected void onPostProcessTarget(AjaxRequestTarget target) { if (progress.isRunning()) { progressSpinner.setVisible(true); } else { progressSpinner.setVisible(false); progressBehavior.stop(null); buttonRestore.setEnabled(true); target.add(buttonRestore); if (progress.isSuccess()) { Page succeedPage = new RestoreSentPage(Model.of(progress.getMessage())); setResponsePage(succeedPage); } else { feedbackPanel.error(progress.getMessage()); target.add(feedbackPanel); } } } }; progressBehavior.stop(null); progressContainer.add(progressBehavior); progressSpinner = new WebMarkupContainer("progressSpinner"); progressSpinner.setOutputMarkupId(true); progressSpinner.setVisible(false); progressContainer.add(progressSpinner); Form<Void> form = new Form<>("restoreForm"); form.setOutputMarkupId(true); add(form); final TextField<String> fieldEmail = new TextField<>("siDyIVtwLp", Model.of(defaultEmail)); form.add(fieldEmail); buttonRestore = new AjaxFallbackButton("buttonRestore", form) { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { final WebRequest request = (WebRequest) RequestCycle.get().getRequest(); final String challenge = request.getPostParameters().getParameterValue("g-recaptcha-response") .toString(); final String secret = Config.get(Config.KEY_CAPTCHA_SECRET); final String MSG_ERROR_CAPTCHA = getString("error.captcha"); final String MSG_ERROR_EMAIL = getString("error.wrongEmail"); final String MSG_ERROR_UNKNOWN_EMAIL = getString("error.unknownEmail"); final String MSG_ERROR_USERNAME_IS_EMPTY = getString("error.userName.empty"); final String MSG_ERROR_COMMON = getString("error.common"); final String appUrlRaw = Config.get(Config.KEY_APP_URL); final String appUrl = appUrlRaw.endsWith("/") ? appUrlRaw : appUrlRaw + "/"; final String bodyPattern = getString("email.body"); final String title = getString("email.title"); final String sender = getString("email.sender"); progressBehavior.restart(target); buttonRestore.setEnabled(false); progressSpinner.setVisible(true); Session.get().getFeedbackMessages().clear(); target.add(buttonRestore, progressSpinner, feedbackPanel); new Thread() { @Override public void run() { try { progress = new ProgressBundle(); progress.setRunning(true); if (!Utils.validateCaptcha(secret, challenge)) { progress.fail(MSG_ERROR_CAPTCHA); return; } String email = fieldEmail.getModelObject(); Validator.validateUserName(email); email = email.toLowerCase(); String restoreKey = authService.buildRestoreKey(email); if (restoreKey != null) { String restoreLink = String.format("%srestore/change?key=%s", appUrl, restoreKey); String body = String.format(bodyPattern, restoreLink, restoreLink); Utils.sendEmail(email, title, body, sender); progress.success(email); } else { progress.fail(MSG_ERROR_UNKNOWN_EMAIL); } } catch (UserNameIsEmptyException e) { progress.fail(MSG_ERROR_USERNAME_IS_EMPTY); } catch (ValidationException e) { progress.fail(MSG_ERROR_UNKNOWN_EMAIL); } catch (MessagingException e) { progress.fail(MSG_ERROR_EMAIL); } catch (Exception e) { e.printStackTrace(); progress.fail(MSG_ERROR_COMMON); } finally { progress.setRunning(false); } } }.start(); } }; buttonRestore.setOutputMarkupId(true); form.add(buttonRestore); }