예제 #1
0
  public RegisterHtmlForm(String id, RegisterForm registerForm) {
    super(id, new CompoundPropertyModel<RegisterForm>(registerForm));

    TextField<String> email =
        new RequiredTextField<String>(
            "register.email", new PropertyModel<String>(registerForm, "email"));
    add(email);
    email.add(EmailAddressValidator.getInstance());
    email.add(StringValidator.maximumLength(SimiConstants.VALID_EMAIL_MAX_LENGTH));

    PasswordTextField password =
        new PasswordTextField(
            "register.password", new PropertyModel<String>(registerForm, "password"));
    add(password);
    password.setRequired(true);
    password.add(
        StringValidator.lengthBetween(
            SimiConstants.VALID_PASSWORD_MIX_LENGTH, SimiConstants.VALID_PASSWORD_MAX_LENGTH));

    PasswordTextField repassword =
        new PasswordTextField(
            "register.repassword", new PropertyModel<String>(registerForm, "repassword"));
    add(repassword);
    repassword.setRequired(true);
    repassword.setResetPassword(false);
    repassword.add(
        StringValidator.lengthBetween(
            SimiConstants.VALID_PASSWORD_MIX_LENGTH, SimiConstants.VALID_PASSWORD_MAX_LENGTH));

    add(new EqualPasswordInputValidator(password, repassword));

    add(new FeedbackPanel(id + ".feedback", new ContainerFeedbackMessageFilter(this)));
  }
예제 #2
0
  public ChangePasswordPanel() {
    txtOldPassword =
        new PasswordTextField("oldPassword", new PropertyModel<String>(this, "oldPassword"));
    txtOldPassword.setRequired(true);
    txtOldPassword.setLabel(Model.of("Parola veche"));
    addWithFeedback(txtOldPassword);

    txtNewPassword =
        new PasswordTextField("newPassword", new PropertyModel<String>(this, "newPassword"));
    txtNewPassword.setRequired(true);
    txtNewPassword.setLabel(Model.of("Parola noua"));
    txtNewPassword.add(StringValidator.minimumLength(6));
    addWithFeedback(txtNewPassword);

    txtRetypedPassword =
        new PasswordTextField(
            "retypedPassword", new PropertyModel<String>(this, "retypedPassword"));
    txtRetypedPassword.setRequired(true);
    txtRetypedPassword.setLabel(Model.of("Parola reintrodusa"));
    addWithFeedback(txtRetypedPassword);
  }
  public PasswordPage() {

    Usuario usuario =
        this.daoService.getUsuario(SecurityUtils.getSubject().getPrincipal().toString());

    final Form<Usuario> form =
        new Form<Usuario>("form", new CompoundPropertyModel<Usuario>(usuario));
    this.add(form);

    final FeedbackPanel feedBackPanel = new FeedbackPanel("feedBackPanel");
    feedBackPanel.setOutputMarkupId(true);
    form.add(feedBackPanel);

    Label nombreUsuario = new Label("nombreUsuario", usuario.getNombre());
    form.add(nombreUsuario);

    final PasswordTextField passActual =
        new PasswordTextField("contraseniaActual", new Model<String>(new String()));
    passActual.setLabel(Model.of("Password actual"));
    passActual.add(new StringValidator(0, 30));
    passActual.setRequired(true);
    passActual.add(
        new IValidator<String>() {

          @Override
          public void validate(IValidatable<String> validatable) {

            Boolean correcto =
                daoService.validarPassword(form.getModelObject(), validatable.getValue());

            if (!correcto) {
              error(validatable, "La password ingresada en 'Password actual' no es correcta.");
            }
          }

          private void error(IValidatable<String> validatable, String errorKey) {
            ValidationError error = new ValidationError();
            error.addKey(getClass().getSimpleName() + "." + errorKey);
            error.setMessage(errorKey);
            validatable.error(error);
          }
        });

    form.add(passActual);

    final PasswordTextField password = new PasswordTextField("password");
    password.setLabel(Model.of("Nueva Password"));
    password.add(new StringValidator(0, 30));
    password.setRequired(true);
    form.add(password);

    final PasswordTextField passConfirmacion =
        new PasswordTextField("contraseniaConfirmacion", new Model<String>(new String()));
    passConfirmacion.setLabel(Model.of("Confirmaci\363n"));
    passConfirmacion.setRequired(true);
    passConfirmacion.add(new StringValidator(0, 30));
    passConfirmacion.add(
        new IValidator<String>() {

          @Override
          public void validate(IValidatable<String> validatable) {

            if (!validatable.getValue().equals(password.getValue())) {
              error(
                  validatable,
                  "Las passwords ingresadas en 'Nueva Password' y 'Confimaci\363n' deben ser iguales.");
            }
          }

          private void error(IValidatable<String> validatable, String errorKey) {
            ValidationError error = new ValidationError();
            error.addKey(getClass().getSimpleName() + "." + errorKey);
            error.setMessage(errorKey);
            validatable.error(error);
          }
        });

    form.add(passConfirmacion);

    final SelectModalWindow selectModalWindow =
        new SelectModalWindow("modalWindow") {

          public void onCancel(AjaxRequestTarget target) {
            close(target);
          }
        };

    form.add(selectModalWindow);

    AjaxButton submit =
        new AjaxButton("submit", form) {

          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

            Usuario usuario = (Usuario) form.getModelObject();

            String nuevaPassword = usuario.getPassword();

            Boolean estaHabilitado =
                PasswordPage.this.daoService.getPermisoCambiarPassword(usuario.getNombreLogin());

            if (estaHabilitado) {
              PasswordPage.this.daoService.setPassword(usuario.getNombreLogin(), nuevaPassword);
              selectModalWindow.show(target);

            } else {
              this.error("No tiene permiso para cambiar su password");
            }

            target.add(feedBackPanel);
          }

          @Override
          protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.add(feedBackPanel);
          }
        };

    form.add(submit);
  }
  @Override
  protected void onInitialize() {
    super.onInitialize();
    add(new FeedbackPanel("feedback"));

    final Administrator newAdmin = new Administrator();
    newAdmin.setAccessLevel("passenger");

    Form<TripList> form = new Form<>("administrator-registration-form");
    add(form);
    TextField<String> loginField =
        new TextField<String>("login", new PropertyModel<String>(newAdmin, "login"));
    loginField.setRequired(true);
    loginField.add(StringValidator.maximumLength(50));
    form.add(loginField);

    // можно добавить второе поле для проверки корректности ввода
    PasswordTextField passwordField =
        new PasswordTextField("password", new PropertyModel<String>(newAdmin, "password"));
    passwordField.setRequired(true);
    passwordField.add(StringValidator.maximumLength(50));
    form.add(passwordField);

    TextField<String> firstNameField =
        new TextField<String>("first-name", new PropertyModel<String>(newAdmin, "firstName"));
    firstNameField.setRequired(true);
    firstNameField.add(StringValidator.maximumLength(50));
    form.add(firstNameField);

    TextField<String> lastNameField =
        new TextField<String>("last-name", new PropertyModel<String>(newAdmin, "lastName"));
    lastNameField.setRequired(true);
    lastNameField.add(StringValidator.maximumLength(50));
    form.add(lastNameField);

    TextField<String> emailField =
        new TextField<String>("email", new PropertyModel<String>(newAdmin, "email"));
    emailField.setRequired(true);
    emailField.add(StringValidator.maximumLength(50));
    form.add(emailField);

    form.add(
        new SubmitLink("submit-button") {
          @Override
          public void onSubmit() {

            // TODO - correct
            //				if (aService.getByLogin(newAdmin.getLogin()) != null) {
            //					warn("such login already exists");
            //				}
            //				if (aService.getByLogin(newAdmin.getLogin()) != null) {
            //					warn("user with such email already exists");
            //				}
            //
            //				if (aService.getByLogin(newAdmin.getLogin()) == null
            //						&& aService.getByLogin(newAdmin.getLogin()) == null) {
            aService.register(newAdmin);
            setResponsePage(new HomePage());
            // }
          }
        });
  }
예제 #5
0
  private void initLayout(final boolean oldPasswordVisible) {
    model = (LoadableModel<MyPasswordsDto>) getModel();

    Label oldPasswordLabel =
        new Label(
            ID_OLD_PASSWORD_LABEL, createStringResource("PageSelfCredentials.oldPasswordLabel"));
    add(oldPasswordLabel);
    oldPasswordLabel.add(
        new VisibleEnableBehaviour() {

          private static final long serialVersionUID = 1L;

          @Override
          public boolean isVisible() {
            return oldPasswordVisible;
          }
        });

    Label passwordLabel =
        new Label(ID_PASSWORD_LABEL, createStringResource("PageSelfCredentials.passwordLabel1"));
    add(passwordLabel);

    PasswordTextField oldPasswordField =
        new PasswordTextField(
            ID_OLD_PASSWORD_FIELD, new PropertyModel<String>(model, MyPasswordsDto.F_OLD_PASSWORD));
    oldPasswordField.setRequired(false);
    oldPasswordField.setResetPassword(false);
    add(oldPasswordField);
    oldPasswordField.add(
        new VisibleEnableBehaviour() {

          private static final long serialVersionUID = 1L;

          public boolean isVisible() {
            return oldPasswordVisible;
          };
        });

    PasswordPanel passwordPanel =
        new PasswordPanel(
            ID_PASSWORD_PANEL,
            new PropertyModel<ProtectedStringType>(model, MyPasswordsDto.F_PASSWORD));
    passwordPanel.getBaseFormComponent().add(new AttributeModifier("autofocus", ""));
    add(passwordPanel);

    WebMarkupContainer accountContainer = new WebMarkupContainer(ID_ACCOUNTS_CONTAINER);

    List<IColumn<PasswordAccountDto, String>> columns = initColumns();
    ListDataProvider<PasswordAccountDto> provider =
        new ListDataProvider<PasswordAccountDto>(
            this, new PropertyModel<List<PasswordAccountDto>>(model, MyPasswordsDto.F_ACCOUNTS));
    TablePanel accounts = new TablePanel(ID_ACCOUNTS_TABLE, provider, columns);
    accounts.setItemsPerPage(30);
    accounts.setShowPaging(false);
    if (model.getObject().getPropagation() != null
        && model
            .getObject()
            .getPropagation()
            .equals(CredentialsPropagationUserControlType.MAPPING)) {
      accountContainer.setVisible(false);
    }
    accountContainer.add(accounts);

    AjaxLink help =
        new AjaxLink(ID_BUTTON_HELP) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            showHelpPerformed(target);
          }
        };
    accountContainer.add(help);

    add(accountContainer);
  }