编程语言
首页 > 编程语言> > javascript-如何检测tumblr用户是否已登录?

javascript-如何检测tumblr用户是否已登录?

作者:互联网

我正在写一个主题,只想向博客的管理员显示内容,但是我不知道如何检测管理员是否已登录.

我确实注意到,在HTML的底部,在body结束标记之前,有以下代码:

<iframe src="http://assets.tumblr.com/iframe.html?10&src=http%3A%2F%2Fstaff.tumblr.com%2F&amp;lang=en_US&amp;name=staff" scrolling="no" width="330" height="25" frameborder="0" style="position:absolute; z-index:1337; top:0px; right:0px; border:0px; background-color:transparent; overflow:hidden;" id="tumblr_controls"></iframe>
<!--[if IE]>
<script type="text/javascript">document.getElementById('tumblr_controls').allowTransparency=true;</script>
<![endif]-->
<script type="text/javascript">_qoptions={qacct:"p-19UtqE8ngoZbM"};</script>
<script type="text/javascript" src="http://edge.quantserve.com/quant.js"></script>     
<noscript><img src="http://pixel.quantserve.com/pixel/p-19UtqE8ngoZbM.gif" style="display:none; border-width:0px; height:1px; width:1px;" alt=""/></noscript>

iframe中的URL(http://assets.tumblr.com/iframe.html?10\u0026amp;src=http://staff.tumblr.com/\u0026amp;lang=en_US\u0026amp;name=staff)会转到一个页面它自己检查用户是否登录.我只是无法弄清楚它是如何工作的.

由于此检查需要嵌入主题的代码中,因此必须在JavaScript中.

谢谢,斯宾塞

解决方法:

我认为无法解决问题,因为此检查必须在服务器上进行,并且由于Tumblr Theme引擎的限制而无法进行检查.

更新:返回JS版本

iframe列表:

> Tumblr iframe for non-logged user
> Tumblr iframe for logged users [owner]
> Tumblr iframe for logged users [non-owner]

这些iframe中不同的代码块:

非登录用户的Tumblr iframe:

<script type="text/javascript">
        var logged_in = (document.cookie.indexOf('logged_in=1') != -1);
</script>
…
<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
    <span id="logged_out_controls" style="display:none;">
        <a href="https://www.tumblr.com/register" target="_top" id="follow_link">
                <img id="follow_image" alt="Follow" style="width:58px;"/>
        </a>
        <a href="https://www.tumblr.com/register/join_tumblr" target="_blank"
        id="join_link">
                <img id="join_image" alt="Join Tumblr" style="width:105px;"/>
        </a>
    </span>
</div>

已登录用户的Tumblr iframe [所有者]:

<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
    <a target="_top" href="http://www.tumblr.com/customize?redirect_to=http%3A%2F%2Fexample.com%2F">
        <img src="http://assets.tumblr.com/images/iframe_customize_alpha.png?1016" alt="Customize" style="height:20px;width:80px; border-width:0px; display:block; float:left; cursor:pointer;" />
    </a>
    <a target="_top" href="http://www.tumblr.com/dashboard">
        <img src="http://assets.tumblr.com/images/iframe_dashboard_alpha.png?1016" alt="Dashboard" style="height:20px; width:81px; border-width:0px; display:block; float:left; cursor:pointer;" />
    </a>
</div>

适用于已登录用户[非所有者]的Tumblr iframe:

<div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;">
    <form action="/follow" method="post" style="display:block; float:left;"onsubmit="_gaq.push(['_trackEvent', 'Iframe', 'Follow', 'example-com');">
        <input type="hidden" name="form_key" value="83jbGySgEVpQGOoZALqqoSaKfjs"/>
        <input type="hidden" name="id" value="example-com"/>
        <input type="image" src="http://assets.tumblr.com/images/iframe_follow_alpha.png?1016"style="width:58px; height:20px; border-width:0px; display:block;margin-left:3px; cursor:pointer;"alt="Follow"/>
    </form>
    <a target="_top" href="http://www.tumblr.com/dashboard">
        <imgsrc="http://assets.tumblr.com/images/iframe_dashboard_alpha.png?1016" alt="Dashboard" style="height:20px; width:81px; border-width:0px; display:block; float:left; cursor:pointer;"/>
    </a>
</div>

可以检测到的差异:

未记录的iframe具有奇怪的脚本行:

> var logging_in =(document.cookie.indexOf(‘logged_in = 1’)!= -1);
>没有带有href属性的链接包含’customize’模式(CSS方式:a [href * =’customize’]);
>没有带有href属性的链接包含’dashboard’模式(CSS方式:a [href * =’dashboard’]);

适用于登录用户的iframe [所有者]:

>带有href属性的链接包含“仪表板”模式(CSS方式:a [href * =’dashboard’]);
>带有href属性的链接包含“自定义”模式(CSS方式:a [href * =’customize’]);
>没有“跟随”表格;

适用于已登录用户[非所有者]的iframe:

>带有href属性的链接包含“仪表板”模式(CSS方式:a [href * =’dashboard’]);
>有“跟随”表格;
>没有带有href属性的链接包含’customize’模式(CSS方式:a [href * =’customize’]);

结论

但是我发现此解决方案非常脆弱,我认为可以根据上面列出的差异检测当前博客的用户所有者.

标签:tumblr,javascript,login
来源: https://codeday.me/bug/20191011/1888973.html