use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project peppol-practical by phax.
the class PageSecurePeppolSendAS4 method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final IIdentifierFactory aIF = Phase4PeppolSender.IF;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.params().hasStringValue(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM)) {
final String sSenderID = aWPEC.params().getAsStringTrimmed(FIELD_SENDER_ID);
final IParticipantIdentifier aSenderID = aIF.parseParticipantIdentifier(sSenderID);
final String sReceiverID = aWPEC.params().getAsStringTrimmed(FIELD_RECEIVER_ID);
final IParticipantIdentifier aReceiverID = aIF.parseParticipantIdentifier(sReceiverID);
final String sDocTypeID = aWPEC.params().getAsStringTrimmed(FIELD_DOCTYPE_ID);
final IDocumentTypeIdentifier aDocTypeID = aIF.parseDocumentTypeIdentifier(sDocTypeID);
final String sProcessID = aWPEC.params().getAsStringTrimmed(FIELD_PROCESS_ID);
final IProcessIdentifier aProcessID = aIF.parseProcessIdentifier(sProcessID);
final String sPayload = aWPEC.params().getAsStringTrimmed(FIELD_PAYLOAD);
final Document aPayloadDoc = DOMReader.readXMLDOM(sPayload);
if (StringHelper.hasNoText(sSenderID))
aFormErrors.addFieldError(FIELD_SENDER_ID, "A sending participant ID must be provided.");
else if (aSenderID == null)
aFormErrors.addFieldError(FIELD_SENDER_ID, "The sending participant ID could not be parsed.");
if (StringHelper.hasNoText(sReceiverID))
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "A receiving participant ID must be provided.");
else if (aReceiverID == null)
aFormErrors.addFieldError(FIELD_RECEIVER_ID, "The receiving participant ID could not be parsed.");
if (StringHelper.hasNoText(sDocTypeID))
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "A document type ID must be provided.");
else if (aDocTypeID == null)
aFormErrors.addFieldError(FIELD_DOCTYPE_ID, "The document type ID could not be parsed.");
if (StringHelper.hasNoText(sProcessID))
aFormErrors.addFieldError(FIELD_PROCESS_ID, "A process ID must be provided.");
else if (aProcessID == null)
aFormErrors.addFieldError(FIELD_PROCESS_ID, "The process ID could not be parsed.");
if (StringHelper.hasNoText(sPayload))
aFormErrors.addFieldError(FIELD_PAYLOAD, "A payload must be provided.");
else if (aPayloadDoc == null)
aFormErrors.addFieldError(FIELD_PAYLOAD, "The payload is not wellformed XML.");
if (aFormErrors.isEmpty()) {
final HCDiv aNL = new HCDiv().addStyle(CCSSProperties.MAX_WIDTH.newValue("80vw"));
final String sAS4PayloadDoc = XMLWriter.getNodeAsString(aPayloadDoc);
final byte[] aAS4PayloadBytes = XMLWriter.getNodeAsBytes(aPayloadDoc);
aNL.addChild(h3("Sending document"));
// Show payload
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sAS4PayloadDoc));
final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {
public void onAS4Message(final AbstractAS4Message<?> aMsg) {
final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
}
};
try {
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST);
// What to remember
final Wrapper<String> aEndpointURL = new Wrapper<>();
final Wrapper<X509Certificate> aEndpointCert = new Wrapper<>();
final Wrapper<EPeppolCertificateCheckResult> aEndpointCertCheck = new Wrapper<>();
final Wrapper<Phase4Exception> aSendEx = new Wrapper<>();
final Wrapper<byte[]> aResponseBytes = new Wrapper<>();
final Wrapper<Ebms3SignalMessage> aResponseMsg = new Wrapper<>();
LOGGER.info("Sending Peppol AS4 message from '" + aSenderID.getURIEncoded() + "' to '" + aReceiverID.getURIEncoded() + "' using document type '" + aDocTypeID.getURIEncoded() + "' and process ID '" + aProcessID.getURIEncoded() + "'");
// Try to send message
final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().cryptoFactory(AS4_CF).documentTypeID(aDocTypeID).processID(aProcessID).senderParticipantID(aSenderID).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aAS4PayloadBytes).smpClient(aSMPClient).endpointURLConsumer(aEndpointURL::set).certificateConsumer((cert, dt, res) -> {
aEndpointCert.set(cert);
aEndpointCertCheck.set(res);
}).validationConfiguration(null).buildMessageCallback(aBuildMessageCallback).outgoingDumper(new AS4OutgoingDumperFileBased()).incomingDumper(new AS4IncomingDumperFileBased()).rawResponseConsumer(r -> aResponseBytes.set(r.getResponse())).signalMsgConsumer(aResponseMsg::set).sendMessageAndCheckForReceipt(aSendEx::set);
LOGGER.info("Sending Peppol AS4 message resulted in " + eResult);
if (aEndpointURL.isSet())
aNL.addChild(div("Sending to this endpoint URL: ").addChild(code(aEndpointURL.get())));
if (aEndpointCert.isSet())
aNL.addChild(div("The message is encrypted for the following receiver: ").addChild(code(aEndpointCert.get().getSubjectX500Principal().getName())));
if (aEndpointCertCheck.isSet())
aNL.addChild(div("The certificate verification resulted in: ").addChild(code(aEndpointCertCheck.get().name())));
if (eResult.isSuccess())
aNL.addChild(success("Successfully send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())));
else
aNL.addChild(error().addChild(div("Failed to send AS4 message to Peppol receiver ").addChild(code(aReceiverID.getURIEncoded())).addChild(" with result ").addChild(code(eResult.name()))).addChild(AppCommonUI.getTechnicalDetailsUI(aSendEx.get(), true)));
boolean bShowRaw = true;
if (aResponseMsg.isSet()) {
// Don't do XSD validation here because there is no defined
// "SignalMessage" element
final String sSignalMessage = new GenericJAXBMarshaller<>(Ebms3SignalMessage.class, GenericJAXBMarshaller.createSimpleJAXBElement(new QName(com.helger.phase4.ebms3header.ObjectFactory._Messaging_QNAME.getNamespaceURI(), "SignalMessage"), Ebms3SignalMessage.class)).setFormattedOutput(true).getAsString(aResponseMsg.get());
if (StringHelper.hasText(sSignalMessage)) {
// Show payload
aNL.addChild(div("Response ebMS Signal Message"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(sSignalMessage));
bShowRaw = false;
}
}
if (aResponseBytes.isSet()) {
if (bShowRaw) {
aNL.addChild(div("Response message - NOT a valid response"));
aNL.addChild(new BootstrapPrismJS(EPrismLanguage.MARKUP).addPlugin(new PrismPluginLineNumbers()).addChild(new String(aResponseBytes.get(), StandardCharsets.UTF_8)));
}
// Else already shown above
} else {
if (eResult.isSuccess())
aNL.addChild(error("Received no response content :("));
}
} catch (final SMPDNSResolutionException ex) {
aNL.addChild(error(div("Error creating the SMP client.")).addChild(AppCommonUI.getTechnicalDetailsUI(ex, false)));
}
if (true)
aNodeList.addChild(aNL);
else
aWPEC.postRedirectGetInternal(aNL);
}
}
aNodeList.addChild(h3("Send new Peppol AS4 message (Test network only)"));
final BootstrapForm aForm = aNodeList.addAndReturnChild(new BootstrapForm(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Sending participant ID").setCtrl(new HCEdit(new RequestField(FIELD_SENDER_ID, DEFAULT_SENDER_ID))).setHelpText(span("The sending Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_SENDER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Receiving participant ID").setCtrl(new HCEdit(new RequestField(FIELD_RECEIVER_ID, DEFAULT_RECEIVER_ID))).setHelpText(span("The receiving Peppol participant identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_RECEIVER_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Document type ID").setCtrl(new HCEdit(new RequestField(FIELD_DOCTYPE_ID, DEFAULT_DOCTYPE_ID))).setHelpText(span("The Peppol document type identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_DOCTYPE_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Process ID").setCtrl(new HCEdit(new RequestField(FIELD_PROCESS_ID, DEFAULT_PROCESS_ID))).setHelpText(span("The Peppol process identifier. Must include the ").addChild(code(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME)).addChild(" prefix.")).setErrorList(aFormErrors.getListOfField(FIELD_PROCESS_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("XML Payload to be send").setCtrl(new HCTextArea(new RequestField(FIELD_PAYLOAD, DEFAULT_PAYLOAD.get())).setRows(8)).setHelpText("This MUST be wellformed XML - e.g. a UBL Invoice or a CII Invoice. NO Schematron validation is performed. The SBDH is added automatically.").setErrorList(aFormErrors.getListOfField(FIELD_PAYLOAD)));
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send Peppol AS4 message"));
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project peppol-practical by phax.
the class PageSecureSMLConfiguration method showInputForm.
@Override
protected void showInputForm(@Nonnull final WebPageExecutionContext aWPEC, @Nullable final ISMLConfiguration aSelectedObject, @Nonnull final BootstrapForm aForm, final boolean bFormSubmitted, @Nonnull final EWebPageFormAction eFormAction, @Nonnull final FormErrorList aFormErrors) {
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final boolean bEdit = eFormAction.isEdit();
aForm.addChild(getUIHandler().createActionHeader(bEdit ? "Edit SML configuration '" + aSelectedObject.getDisplayName() + "'" : "Create new SML configuration"));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("ID").setCtrl(new HCEdit(new RequestField(FIELD_ID, aSelectedObject != null ? aSelectedObject.getID() : null)).setReadOnly(bEdit)).setHelpText("The internal ID of the SML configuration. This value cannot be edited.").setErrorList(aFormErrors.getListOfField(FIELD_ID)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Name").setCtrl(new HCEdit(new RequestField(FIELD_DISPLAY_NAME, aSelectedObject != null ? aSelectedObject.getDisplayName() : null))).setHelpText("The name of the SML configuration. This is for informational purposes only and has no effect on the functionality.").setErrorList(aFormErrors.getListOfField(FIELD_DISPLAY_NAME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("DNS Zone").setCtrl(new HCEdit(new RequestField(FIELD_DNS_ZONE, aSelectedObject != null ? aSelectedObject.getDNSZone() : null))).setHelpText(new HCTextNode("The name of the DNS Zone that this SML is working upon (e.g. "), new HCCode().addChild("sml.peppolcentral.org"), new HCTextNode("). The value will automatically converted to all-lowercase!")).setErrorList(aFormErrors.getListOfField(FIELD_DNS_ZONE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Management Service URL").setCtrl(new HCEdit(new RequestField(FIELD_MANAGEMENT_ADDRESS_URL, aSelectedObject != null ? aSelectedObject.getManagementServiceURL() : null))).setHelpText("The service URL where the SML management application is running on including the host name. It may not contain the '" + CSMLDefault.MANAGEMENT_SERVICE_METADATA + "' or '" + CSMLDefault.MANAGEMENT_SERVICE_PARTICIPANTIDENTIFIER + "' path elements!").setErrorList(aFormErrors.getListOfField(FIELD_MANAGEMENT_ADDRESS_URL)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Client Certificate required?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_CLIENT_CERTIFICATE_REQUIRED, aSelectedObject != null ? aSelectedObject.isClientCertificateRequired() : DEFAULT_CLIENT_CERTIFICATE_REQUIRED))).setHelpText("Check this if this SML requires a client certificate for access. Both Peppol production SML and SMK require a client certificate. Only a locally running SML software may not require a client certificate.").setErrorList(aFormErrors.getListOfField(FIELD_CLIENT_CERTIFICATE_REQUIRED)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP API type").setCtrl(new SMPAPITypeSelect(new RequestField(FIELD_SMP_API_TYPE, aSelectedObject != null ? aSelectedObject.getSMPAPIType().getID() : null), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SMP_API_TYPE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("SMP identifier type").setCtrl(new SMPIdentifierTypeSelect(new RequestField(FIELD_SMP_ID_TYPE, aSelectedObject != null ? aSelectedObject.getSMPIdentifierType().getID() : null), aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_SMP_ID_TYPE)));
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Production SML?").setCtrl(new HCCheckBox(new RequestFieldBoolean(FIELD_PRODUCTION, aSelectedObject != null ? aSelectedObject.isProduction() : true))).setHelpText("Check this if this SML is a production SML. Don't check e.g. for SMK.").setErrorList(aFormErrors.getListOfField(FIELD_PRODUCTION)));
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project peppol-practical by phax.
the class PagePublicContact method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final String sRecaptchWebKey = AppConfig.getRecaptchaWebKey();
final String sRecaptchSecretKey = AppConfig.getRecaptchaSecretKey();
final boolean bRecaptchaEnabled = StringHelper.hasText(sRecaptchWebKey) && StringHelper.hasText(sRecaptchSecretKey);
aNodeList.addChild(p("If you have general questions concerning Peppol technology, you may contact me using the form below. Please be aware, that I run this page on a voluntary basis and that the answers you may receive are my personal answers and not official OpenPeppol answers."));
boolean bShowForm = true;
final FormErrorList aFormErrors = new FormErrorList();
if (aWPEC.hasAction(CPageParam.ACTION_PERFORM)) {
final String sName = StringHelper.trim(aWPEC.params().getAsString(FIELD_NAME));
final String sEmail = StringHelper.trim(aWPEC.params().getAsString(FIELD_EMAIL));
final String sTopic = aWPEC.params().getAsString(FIELD_TOPIC);
final String sText = StringHelper.trim(aWPEC.params().getAsString(FIELD_TEXT));
final String sReCaptchaResponse = StringHelper.trim(aWPEC.params().getAsString(HCReCaptchaV2.RESPONSE_PARAMETER_NAME));
if (StringHelper.hasNoText(sName))
aFormErrors.addFieldError(FIELD_NAME, "Your name must be provided.");
if (StringHelper.hasNoText(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "Your email address must be provided.");
else if (!EmailAddressHelper.isValid(sEmail))
aFormErrors.addFieldError(FIELD_EMAIL, "The provided email address is invalid.");
if (StringHelper.hasNoText(sText))
aFormErrors.addFieldError(FIELD_TEXT, "A message text must be provided.");
if (bRecaptchaEnabled)
if (aFormErrors.isEmpty() || StringHelper.hasText(sReCaptchaResponse)) {
if (!CaptchaStateSessionSingleton.getInstance().isChecked()) {
// Check only if no other errors occurred
if (ReCaptchaServerSideValidator.check(sRecaptchSecretKey, sReCaptchaResponse).isFailure())
aFormErrors.addFieldError(FIELD_CAPTCHA, "Please confirm you are not a robot!");
else
CaptchaStateSessionSingleton.getInstance().setChecked();
}
}
if (aFormErrors.isEmpty()) {
if (!_isSpamBody(sText)) {
final EmailData aEmailData = new EmailData(EEmailType.TEXT);
aEmailData.setFrom(new EmailAddress("peppol-practical@helger.com", "Peppol Practical"));
aEmailData.to().add(new EmailAddress("philip@helger.com"));
aEmailData.replyTo().add(new EmailAddress(sEmail, sName));
aEmailData.setSubject("[" + AppHelper.getApplicationTitle() + "] Contact Form - " + sName);
final StringBuilder aSB = new StringBuilder();
aSB.append("Contact form from " + AppHelper.getApplicationTitle() + " was filled out.\n\n");
aSB.append("Name: ").append(sName).append("\n");
aSB.append("Email: ").append(sEmail).append("\n");
aSB.append("Topic: ").append(sTopic).append("\n");
aSB.append("Text:\n").append(sText).append("\n");
aEmailData.setBody(aSB.toString());
LOGGER.info("Sending contact form from '" + sName + "' and email '" + sEmail + "' with topic '" + sTopic + "'");
ScopedMailAPI.getInstance().queueMail(InternalErrorSettings.getSMTPSettings(), aEmailData);
} else
LOGGER.info("Ignoring spam contact form from '" + sEmail + "' with topic '" + sTopic + "'");
aNodeList.addChild(success("Thank you for your message. Please note that I run this page on a voluntary basis on my expenses - you may consider a donation."));
bShowForm = false;
}
}
if (bShowForm) {
final BootstrapForm aForm = aNodeList.addAndReturnChild(getUIHandler().createFormSelf(aWPEC));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your name").setCtrl(new HCEdit(new RequestField(FIELD_NAME))).setErrorList(aFormErrors.getListOfField(FIELD_NAME)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL)));
final HCExtSelect aSelect = new HCExtSelect(new RequestField(FIELD_TOPIC));
aSelect.addOption("SML/SMK");
aSelect.addOption("SMP");
aSelect.addOption("AccessPoint (AP)/AS4");
aSelect.addOption("Peppol Directory");
aSelect.addOption("Validation");
aSelect.addOption("CEF");
aSelect.addOption("General question");
aSelect.addOptionPleaseSelect(aDisplayLocale);
aForm.addFormGroup(new BootstrapFormGroup().setLabel("Topic").setCtrl(aSelect).setErrorList(aFormErrors.getListOfField(FIELD_TOPIC)));
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Your message").setCtrl(new HCTextAreaAutosize(new RequestField(FIELD_TEXT)).setRows(5)).setErrorList(aFormErrors.getListOfField(FIELD_TEXT)));
if (bRecaptchaEnabled)
if (!CaptchaStateSessionSingleton.getInstance().isChecked()) {
// Add visible Captcha
aForm.addFormGroup(new BootstrapFormGroup().setCtrl(HCReCaptchaV2.create(sRecaptchWebKey, aDisplayLocale)).setErrorList(aFormErrors.getListOfField(FIELD_CAPTCHA)));
}
aForm.addChild(new HCHiddenField(CPageParam.PARAM_ACTION, CPageParam.ACTION_PERFORM));
aForm.addChild(new BootstrapSubmitButton().addChild("Send message").setIcon(EFontAwesome4Icon.PAPER_PLANE));
}
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project peppol-practical by phax.
the class PagePublicSignUp method showInputForm.
protected void showInputForm(@Nonnull final Locale aDisplayLocale, @Nonnull final AbstractHCForm<?> aForm, @Nonnull final FormErrorList aFormErrors) {
final List<IHCNode> aPasswordHelpText = HCExtHelper.list2divList(GlobalPasswordSettings.getPasswordConstraintList().getAllPasswordConstraintDescriptions(aDisplayLocale));
aForm.addChild(info("Sign up to ").addChild(strong(AppHelper.getApplicationTitle())).addChild(" easily by filling out this form. No further information and no credit card information is needed."));
final BootstrapForm aRealForm = (BootstrapForm) aForm;
aRealForm.setLeft(3);
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("First name").setCtrl(new HCEdit(new RequestField(FIELD_FIRSTNAME))).setErrorList(aFormErrors.getListOfField(FIELD_FIRSTNAME)));
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Last name").setCtrl(new HCEdit(new RequestField(FIELD_LASTNAME))).setErrorList(aFormErrors.getListOfField(FIELD_LASTNAME)));
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Email address").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL1))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL1)));
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Email address (confirmation)").setCtrl(new HCEdit(new RequestField(FIELD_EMAIL2))).setErrorList(aFormErrors.getListOfField(FIELD_EMAIL2)));
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Password").setCtrl(new HCEditPassword(FIELD_PASSWORD)).setHelpText(aPasswordHelpText).setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD)));
aRealForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory("Password (confirmation)").setCtrl(new HCEditPassword(FIELD_PASSWORD_CONFIRM)).setHelpText(aPasswordHelpText).setErrorList(aFormErrors.getListOfField(FIELD_PASSWORD_CONFIRM)));
}
use of com.helger.photon.bootstrap4.form.BootstrapFormGroup in project peppol-practical by phax.
the class AppCommonUI method createViewLoginForm.
@Nonnull
public static BootstrapForm createViewLoginForm(@Nonnull final LayoutExecutionContext aLEC, @Nullable final String sPreselectedUserName, final boolean bShowRegistration) {
final Locale aDisplayLocale = aLEC.getDisplayLocale();
final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
// Use new IDs for both fields, in case the login stuff is displayed more
// than once!
final String sIDUserName = GlobalIDFactory.getNewStringID();
final String sIDPassword = GlobalIDFactory.getNewStringID();
final String sIDErrorField = GlobalIDFactory.getNewStringID();
final BootstrapForm aForm = new BootstrapForm(aLEC).setAction(aLEC.getSelfHref()).setFormType(EBootstrapFormType.DEFAULT);
aForm.setLeft(3);
// Placeholder for error message
aForm.addChild(new HCDiv().setID(sIDErrorField).addStyle(CCSSProperties.MARGIN.newValue("4px 0")));
// User name field
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(EPhotonCoreText.EMAIL_ADDRESS.getDisplayText(aDisplayLocale)).setCtrl(new HCEdit(new RequestField(CLogin.REQUEST_ATTR_USERID, sPreselectedUserName)).setPlaceholder(EPhotonCoreText.EMAIL_ADDRESS.getDisplayText(aDisplayLocale)).setID(sIDUserName)));
// Password field
aForm.addFormGroup(new BootstrapFormGroup().setLabelMandatory(EPhotonCoreText.LOGIN_FIELD_PASSWORD.getDisplayText(aDisplayLocale)).setCtrl(new HCEditPassword(CLogin.REQUEST_ATTR_PASSWORD).setPlaceholder(EPhotonCoreText.LOGIN_FIELD_PASSWORD.getDisplayText(aDisplayLocale)).setID(sIDPassword)));
// Login button
final BootstrapButtonToolbar aToolbar = aForm.addAndReturnChild(new BootstrapButtonToolbar(aLEC));
{
final JSPackage aOnClick = new JSPackage();
final JSAnonymousFunction aJSSuccess = new JSAnonymousFunction();
final JSVar aJSData = aJSSuccess.param("data");
aJSSuccess.body()._if(aJSData.ref(AjaxExecutorPublicLogin.JSON_LOGGEDIN), JSHtml.windowLocationReload(), JQuery.idRef(sIDErrorField).empty().append(aJSData.ref(AjaxExecutorPublicLogin.JSON_HTML)));
aOnClick.add(new JQueryAjaxBuilder().url(CAjax.LOGIN.getInvocationURI(aRequestScope)).method(EHttpMethod.POST).data(new JSAssocArray().add(CLogin.REQUEST_ATTR_USERID, JQuery.idRef(sIDUserName).val()).add(CLogin.REQUEST_ATTR_PASSWORD, JQuery.idRef(sIDPassword).val())).success(aJSSuccess).build());
aOnClick._return(false);
aToolbar.addSubmitButton(EPhotonCoreText.LOGIN_BUTTON_SUBMIT.getDisplayText(aDisplayLocale), aOnClick, EDefaultIcon.YES.getIcon());
}
if (bShowRegistration) {
aToolbar.addChild(new BootstrapButton(EBootstrapButtonType.SUCCESS).addChild(EPhotonCoreText.BUTTON_SIGN_UP.getDisplayText(aDisplayLocale)).setOnClick(aLEC.getLinkToMenuItem(CMenuPublic.MENU_SIGN_UP)));
}
return aForm;
}
Aggregations