// Reset authentication session attribute
request.getSession().removeAttribute(Pac4jAuthenticationUtils.AUTH_TOKEN_ATTRIBUTE);
getSession().success(getString("register.success"));
throw new RestartResponseException(HomePage.class);
} else {
LOGGER.warn("Username '" + user.getUserName() + "' already used");
getSession().error(getString("register.userName.notUnique"));
}
}
} catch (RestartResponseException e) {
throw e;
} catch (Exception e) {
LOGGER.error("Error occured while creating account.", e);
getSession().error(getString("register.error"));
}
}
};
// Email field
EmailTextField emailInput = new EmailTextField("emailInput", BindingModel.of(userModel, Binding.user().email()));
emailInput.setLabel(new ResourceModel("register.email"));
emailInput.setRequired(true);
form.add(emailInput);
// Name fields
TextField<String> fullNameInput = new TextField<String>("fullNameInput", BindingModel.of(userModel, Binding.user().fullName()));
fullNameInput.setLabel(new ResourceModel("register.fullName"));
form.add(fullNameInput);
// Password fields
WebMarkupContainer passwordContainer = new WebMarkupContainer("passwordContainer") {
private static final long serialVersionUID = 2727669661139358058L;
@SuppressWarnings("unchecked")
@Override
protected void onConfigure() {
super.onConfigure();
boolean isRemoteRegistration = isRemoteRegistration();
setVisible(!isRemoteRegistration);
for (int i = 0; i < size(); ++i) {
((FormComponent<String>) get(i)).setRequired(!isRemoteRegistration);
}
}
};
form.add(passwordContainer);
PasswordTextField passwordInput = new PasswordTextField("passwordInput", this.passwordModel); // FIXME: Génère un warning au submit
passwordInput.setLabel(new ResourceModel("register.password"));
passwordInput.add(new PasswordPatternValidator());
passwordContainer.add(passwordInput);
PasswordTextField confirmPasswordInput = new PasswordTextField("confirmPasswordInput", this.confirmPasswordModel);
confirmPasswordInput.setLabel(new ResourceModel("register.confirmPassword"));
passwordContainer.add(confirmPasswordInput);
// Remote identifier field
TextField<String> remoteIdentifierInput = new TextField<String>("remoteIdentifierInput",
BindingModel.of(userModel, Binding.user().remoteIdentifier())) {
private static final long serialVersionUID = 1L;
@Override
protected void onConfigure() {
super.onConfigure();
boolean isRemoteRegistration = isRemoteRegistration();
setVisible(isRemoteRegistration);
setRequired(isRemoteRegistration);
}
};
remoteIdentifierInput.setLabel(new ResourceModel("register.remote.identifier"));
remoteIdentifierInput.setEnabled(false);
form.add(remoteIdentifierInput);
Link<Void> clearRemoteIdentifierLink = new Link<Void>("clearRemoteIdentifierLink") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
// Reset authentication session attribute
HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest();
request.getSession().removeAttribute(Pac4jAuthenticationUtils.AUTH_TOKEN_ATTRIBUTE);
RegisterFormPanel.this.userModel.setObject(new User());
RegisterFormPanel.this.userModel.getObject().setActive(false);
throw new RestartResponseException(RegisterPage.class);
}
};
form.add(clearRemoteIdentifierLink);
if (!isRemoteRegistration()) {