/** * Gets the concrete value only if the submission was a success. * If the form is invalid because of validation errors this method will throw an exception. * If you want to retrieve the value even when the form is invalid use {@link #value()} instead. * * @throws IllegalStateException if there are errors binding the form, including the errors as JSON in the message * @return the concrete value. */ public T get() { return this.get(this.lang); }
/** * Gets the concrete value only if the submission was a success. * If the form is invalid because of validation errors this method will throw an exception. * If you want to retrieve the value even when the form is invalid use {@link #value()} instead. * * @throws IllegalStateException if there are errors binding the form, including the errors as JSON in the message * @return the concrete value. */ public T get() { return this.get(this.lang); }
/** * Gets the concrete value only if the submission was a success. * If the form is invalid because of validation errors this method will throw an exception. * If you want to retrieve the value even when the form is invalid use {@link #value()} instead. * * @throws IllegalStateException if there are errors binding the form, including the errors as JSON in the message * @return the concrete value. */ public T get() { return this.get(this.lang); }
protected static boolean isPasswordConfirmationCorrect(Form<SignupData> signUpForm) { String password = signUpForm.get().getPassword(); String passwordConfirmation = signUpForm.get().getPasswordConfirmation(); if (!password.equals(passwordConfirmation)) { signUpForm.reject(SignupData.PASSWORD_CONFIRMATION_FIELD, PASSWORDS_MISMATCH); return false; } return true; }
public boolean isUserEditFormValid(Form<?> userEditForm) { // TODO: Check password confirmation. @SuppressWarnings("unchecked") Form<UserEditData> typedForm = (Form<UserEditData>) userEditForm; return !isPasswordSpecified(typedForm.get().getPassword()) || isPasswordConfirmationCorrect(typedForm.get()); }
private static boolean isPasswordConfirmationCorrect(Form<PasswordResetData> form) { if (form.get().passwordsMatch()) { return true; } else { form.reject(PasswordResetData.PASSWORD_CONFIRMATION_FIELD, SignupService.PASSWORDS_MISMATCH); return false; } }
public PlessUser createUser(Form<?> signupForm) { SignupData signupData = (SignupData) signupForm.get(); return userRepository().createUser(signupData.email, signupData.username, signupData.password); }
@Override public Result apply(final Form<HerculesProjectForm> form) { final JiraProject project = projectRetriever.getProject(userId, tenant, form.get().projectId); return badRequest(views.html.admin.editproject.render(form, project, getPatternOptions())); } },
private boolean isValidProjectConfig(final AcHost tenant, final Form<HerculesProjectForm> form) { final HerculesProjectForm projectForm = form.get(); if (projectForm.patternSourceIds.size() == 0) { form.reject("patternSourceIds", "Please select at least one valid pattern source."); } final Iterable<Long> allSourceIds = transform(HerculesPatternSource.findAll(tenant.getKey()), input -> input.id); for (Long patternSourceId : projectForm.patternSourceIds) { if (!Iterables.contains(allSourceIds, patternSourceId)) { form.reject("patternSourceIds", "Pattern Source with id '" + patternSourceId + "' is not a valid pattern source. Only select from the valid sources above."); } } return !form.hasErrors(); }
default CompletionStage<Result> handleValidForm(final Form<? extends F> form, final T context) { final CompletionStage<Result> resultStage = doAction(form.get(), context) .thenComposeAsync(result -> handleSuccessfulAction(form.get(), context, result), HttpExecution.defaultContext()); return recoverWith(resultStage, throwable -> handleFailedAction(form, context, throwable), HttpExecution.defaultContext()); }
protected static boolean isEmailFree(Form<SignupData> signUpForm) { String email = signUpForm.get().getEmail(); if (userRepository().findUserByEmail(email) != null) { signUpForm.reject(SignupData.EMAIL_FIELD, "A user with the given email is already signed up."); return false; } return true; }
protected static boolean isUsernameFree(Form<SignupData> signUpForm) { String username = signUpForm.get().getUsername(); if (username != null && userRepository().findUserByUsername(username) != null) { signUpForm.reject(SignupData.USERNAME_FIELD, "A user with the given username is already signed up."); return false; } return true; }
private static boolean tryResetPassword(Form<PasswordResetData> form) { PasswordResetData passwordResetData = form.get(); boolean passwordResetSucceeded = tryResetPassword(passwordResetData.getEmail(), passwordResetData.getResetPasswordToken(), passwordResetData.getPassword()); if (passwordResetSucceeded) { return true; } else { form.reject(PasswordResetData.PASSWORD_CONFIRMATION_FIELD, PASSWORD_RESET_ERROR); return false; } }
@SunriseRoute("processChangeLanguageForm") public CompletionStage<Result> changeLanguage() { final Form<LanguageFormData> languageForm = formFactory.form(LanguageFormData.class).bindFromRequest(); final String languageTag = languageForm.hasErrors() ? defaultLanguage() : languageForm.get().getLanguage(); logger.debug("Changed language: " + languageTag); return redirectToLanguage(languageTag); }
@SunriseRoute("processChangeCountryForm") public CompletionStage<Result> changeCountry(final String languageTag) { final Form<CountryFormData> boundForm = formFactory.form(CountryFormData.class).bindFromRequest(); final String country = boundForm.hasErrors() ? defaultCountry() : boundForm.get().getCountry(); session(SESSION_COUNTRY, country); logger.debug("Changed country: " + country); return redirectToHome(); }
public PlessUser updateUser(Form<?> accountEditForm, PlessUser userToUpdate) { UserEditData userEditData = (UserEditData) accountEditForm.get(); updateEmail(userToUpdate, userEditData.getEmail()); updateUsername(userToUpdate, userEditData.getUsername()); updatePassword(userToUpdate, userEditData.getPassword()); return userToUpdate; }
@Override public Option<Form<HerculesPropertiesForm>> validateAndSave(final String userId, final AcHost tenant, final Form<HerculesPropertiesForm> form) { final HerculesPropertiesForm properties = form.get(); if (!isPositiveNumber(properties.attachmentMaxSize)) { form.reject("attachmentMaxSize", "Please enter maximum attachment size in number of MBs."); } if (!isPositiveNumber(properties.archiveMaxEntryCount)) { form.reject("archiveMaxEntryCount", "Please enter a number greater than or equal to 0."); } if (form.hasErrors()) { return Option.some(form); } JPA.withTransaction(() -> { final HerculesConfiguration config = HerculesConfiguration.get(tenant.getKey()); config.attachmentMaxSize = Integer.parseInt(properties.attachmentMaxSize) * HerculesPropertiesForm.ONE_MB; config.archiveMaxEntryCount = Integer.parseInt(properties.archiveMaxEntryCount); JPA.em().merge(config); }); cache.refresh(tenant.getKey()); return Option.none(); }
public static Result logIn() { Form<PasswordLoginData> form = Form.form(PasswordLoginData.class).bindFromRequest(); if (form.hasErrors()) { return badRequest(form.errorsAsJson()); } else { PasswordLoginData passwordLoginData = form.get(); return logIn(passwordLoginData.getEmail(), passwordLoginData.getPassword()); } }
@Override public Either<Form<HerculesProjectForm>, Project> validateAndEdit(final String userId, final AcHost tenant, final Form<HerculesProjectForm> form) { final HerculesProjectForm projectForm = form.get(); try { return JPA.withTransaction(() -> { if (!isValidProjectConfig(tenant, form)) { return Either.<Form<HerculesProjectForm>, Project>left(form); } final List<HerculesPatternSource> patternSource = getHerculesPatternSourcesForIds(projectForm, tenant); return Either.<Form<HerculesProjectForm>, Project>right(Project.toProject(HerculesProject.edit(tenant.getKey(), projectForm, patternSource))); }); } catch (Throwable t) { form.reject("Unknown error saving project " + t.getMessage()); return Either.left(form); } }
public Result processForm() { return onSetupEnabled(() -> { final Form<SphereCredentials> form = formFactory.form(SphereCredentials.class).bindFromRequest(); final Result result; if (form.hasErrors()) { result = badRequest(setup.render(form, setupReverseRouter.processSetupFormCall())); } else { final SphereCredentials credentials = form.get(); final String content = String.format("ctp.projectKey=%s\n" + "ctp.clientId=%s\n" + "ctp.clientSecret=%s\n", credentials.getProjectKey(), credentials.getClientId(), credentials.getClientSecret()); final Path path = writeSettingsFile(PATH, content); result = ok(success.render(path.toString())); } return result; }); }