3

所以我使用keycloak作为认证机制,通过修改login.ftl文件来自定义登录页面。到现在为止还挺好。我正在我的 login.ftl 中导入 template.ftl 文件 - 按照 keycloak 文档的指示 - 到目前为止一切顺利。在该 template.ftl 文件中 - 有一种访问错误消息的方法,如下所示

          <#if displayMessage && message?has_content && (message.type != 'warning' || !isAppInitiatedAction??)>
          <div class="alert alert-${message.type}">
              <#if message.type = 'success'><span class="${properties.kcFeedbackSuccessIcon!}"></span></#if>
              <#if message.type = 'warning'><span class="${properties.kcFeedbackWarningIcon!}"></span></#if>
              <#if message.type = 'error'><span class="${properties.kcFeedbackErrorIcon!}"></span></#if>
              <#if message.type = 'info'><span class="${properties.kcFeedbackInfoIcon!}"></span></#if>
              <span class="kc-feedback-text">${kcSanitize(message.summary)?no_esc}</span>
          </div>
      </#if>

好的,不错!如果我不想处理该 template.ftl 文件中的错误消息 ui 怎么办?我在 login.ftl 页面上有一个表单 UI,我想在其中显示错误消息。如何将该消息传递到 login.ftl 文件或从 login.ftl 文件访问该错误消息?提前感谢您的任何指导。

4

2 回答 2

4

您可以在 login.ftl 中访问它,就像在 template.ftl 中一样

<#if message?has_content>
    message.summary
    ...
</#if>

我认为您在 login.ftl 中未设置模板变量(displayMessage,isAppInitiatedAction)时遇到问题

于 2020-11-02T09:28:02.290 回答
1

如果您在登录页面中添加新字段并且需要验证它并在字段无效时显示错误消息,则需要编写提供程序。自定义提供者必须实现 FormAction 和 FormActionFactory。有一个名为 validate 的方法,您可以在其中编写逻辑来验证字段,并为错误消息定义键和值。此密钥可在您的 login.ftl 文件中使用。这个线程我很有帮助Keycloak - 自定义表单操作在流程中不可见

于 2020-11-02T11:09:34.593 回答