如何检测tumblr用户是否已登录? [英] How to detect if a tumblr user is logged in?

查看:105
本文介绍了如何检测tumblr用户是否已登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写主题并希望仅向博客管理员显示内容,但我不知道如何检测管理员是否已登录。

I'm writing a theme and wanted to display content only to the admin of the blog, but I don't know how to detect if the admin is logged in.

我注意到在HTML的底部,就在关闭正文标记之前有这样的代码:

I did notice that at the bottom of the HTML, right before the closing body tag there is this code:

<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 中的网址(http: //assets.tumblr.com/iframe.html?10&src=http%3A%2F%2Fstaff.tumblr.com%2F&lang=en_US&name=staff)指向一个页面,如果用户自行检查登录。我只是无法弄清楚它是如何工作的。

The URL in the iframe (http://assets.tumblr.com/iframe.html?10&src=http%3A%2F%2Fstaff.tumblr.com%2F&lang=en_US&name=staff) leads to a page which does its own check if the user is logged in. I just haven't been able to figure out how it works.

因为这个检查需要嵌入主题的代码中,所以必须在JavaScript中。

Because this check would need to be embedded in the theme's code it must be in JavaScript.

谢谢,Spencer

Thanks, Spencer

推荐答案

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

I think problem cannot be solved because this check must be made on server, and check can't be made due to limitations of Tumblr Theme engine.

更新:返回JS版

  • Tumblr iframe for non-logged user
  • Tumblr iframe for logged users [owner]
  • Tumblr iframe for logged users [non-owner]
<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 [所有者]:



Tumblr iframe for logged users [owner]:

<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 [非所有者]:



Tumblr iframe for logged users [non-owner]:

<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 logged_in =(document.cookie。 indexOf('logged_in = 1')!= -1);

    Diffs which can be detected:

    Iframe for non-logged has strange script line:

    • var logged_in = (document.cookie.indexOf('logged_in=1') != -1);

      没有链接 href 属性包含'customize'模式(CSS方式: a [href * ='customize'] );

      There is NO link with href attribute contains 'customize' pattern (CSS way: a[href*='customize']);


      • href 属性包含'仪表板'模式(CSS方式: a [href * ='仪表板'] );

      • 有链接 href 属性包含'自定义'模式(CSS方式: a [href * ='customize'] );

      • There is link with href attribute contains 'dashboard' pattern (CSS way: a[href*='dashboard']);
      • There is link with href attribute contains 'customize' pattern (CSS way: a[href*='customize']);

      '关注'表单;


      • 链接 href 属性包含'dashboard'模式(CSS方式: a [href * ='dashboard'] );

      • 'follow'表格;

      • There is link with href attribute contains 'dashboard' pattern (CSS way: a[href*='dashboard']);
      • There is 'follow' form;

      NO 链接 href 属性包含'自定义'模式(CSS方式: a [href * ='自定义'] );

      There is NO link with href attribute contains 'customize' pattern (CSS way: a[href*='customize']);

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

      However I find this solution quite fragile, I think it is possible to detect is user owner of current blog based on diffs listed above.

      这篇关于如何检测tumblr用户是否已登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆