首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用jquery和模态的AEM注销

使用jquery和模态的AEM注销
EN

Stack Overflow用户
提问于 2022-07-01 09:00:53
回答 1查看 139关注 0票数 0

我已经在aem中创建了一个sign_in按钮,并试图在sign_in锚标记上调用一个模式,这将调用我的modal.js。但是当我单击锚标记时,模式不会弹出,我的url将更改为https:localhost:4502/content/my-website/home.html#sign_out.我不太擅长jquery,所以我不知道自己哪里出了问题

这是参考代码。登录/退出按钮.html

代码语言:javascript
运行
复制
<div data-sly-use.placeholderTemplate="core/wcm/components/commons/v1/templates.html"
     data-sly-test.hasContent="${properties.signInLabel != '' && properties.signInXfPath != '' && properties.signOutLabel != '' && properties.signOutXfPath != '' }"
     class="ranosys-sign-in-buttons"
     data-current-user-url="/libs/granite/security/currentuser.json">

    <span
       class="xyz-sign-in-buttons__button xyz-sign-in-buttons__button--greeting"
       id="ranosysGreetingLabel"
       >${properties.greetingLabel @ i18n}</span>

    <a href="#sign-in"
       class="xyz-sign-in-buttons__button xyz-sign-in-buttons__button--sign-in"
       data-modal-url="${ properties.signInXfPath @ selectors='content', extension = 'html'}"
       data-sly-test="${properties.signInLabel != '' }">${properties.signInLabel}</a>

    <a href="#sign-out"  
       class="xyz-sign-in-buttons__button xyz-sign-out-buttons__button--sign-out"
       data-modal-url="${ properties.signOutXfPath @ selectors='content', extension = 'html'}"
       data-sly-test="${properties.signOutLabel != '' }">${properties.signOutLabel}</a>

</div>
<sly data-sly-call="${placeholderTemplate.placeholder @ isEmpty=!hasContent}"></sly>


**sign_in/out_button.js**

import $ from "jquery";
 
// alert("hiii");
        const currentUserUrl = $('.xyz-sign-in-buttons').data('current-user-url'),
            signIn = $('[href="#sign-in"]'),
            signOut = $('[href="#sign-out"]'),
            greetingLabel = $('#ranosysGreetingLabel'),
            greetingText = greetingLabel.text(),
            body = $('body');

        $.getJSON(currentUserUrl + "?nocache=" + new Date().getTime(), function(currentUser) {
            const isAnonymous = 'anonymous' === currentUser.authorizableId;

            if(isAnonymous) {
                signIn.show();
                body.addClass('anonymous');
            } else {
                signOut.show();
                greetingLabel.text(greetingText + ", " + currentUser.name);
                greetingLabel.show();
            }
        });


**modal.js**
import $ from "jquery";

  
    let visible = false;
    
    function showModal(e) {
        e.preventDefault();

        const xfUrl = $(this).data('modal-url');

        if (visible || !xfUrl) { return; }
        const showModalEvt = new Event('xyz-modal-show');
        const body = document.querySelector('body');

        $.get(xfUrl, function (data) {
            const modal = $('<div id="xyz-modal"/>');
            $('body').append(modal.append(data));
            modal.fadeIn(300, function() { visible = true; });
            visible = true;
            // dispatch event to indicate that the modal has been shown
            // used by sign-in-form.js to dynamically update a successful sign-in redirect to the current page
            body.dispatchEvent(showModalEvt);
        });

        return false;
    }

    function hideModal(e) {
        const modal = $('#xyz-modal');
        // if the target of the click isn't the modal nor a descendant of the modal
        if (visible && modal && !modal.is(e.target) && modal.has(e.target).length === 0) {
            e.preventDefault();

            modal.fadeOut(200, function(){
                modal.remove();
                visible = false;
            });

            return false;
        }

    }


    /*eslint no-use-before-define: ["error", { "functions": false }]*/

    /**
     * Handle clicking of the Sign In button
     */
    $('body').on('click', '[data-modal-url]', showModal);


    /**
     * Handle clicking "off-modal" to hide it
     */

      $(document).on('click', (hideModal));
EN

回答 1

Stack Overflow用户

发布于 2022-10-01 18:54:14

似乎您正在从XF获取HTML;如果您希望通过基于AEM使用的AEM表单进行注销。

#1 -例如,您可以使用下面的锚;在XF中添加下面href的锚标记。

代码语言:javascript
运行
复制
<a href="/system/sling/logout.html">Log Out</a>

您还可以通过ajax访问(/system/sling/logout.html)。

#2 -您可以编写自定义注销servlet,并在按钮单击事件的模式,可以点击servlet注销。

您还可以以- org.apache.sling.auth.core.impl.LogoutServlet为例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72826822

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档