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

Spe*_*cer 4 javascript login tumblr

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

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

<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>
Run Code Online (Sandbox Code Playgroud)

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

因为这个检查需要嵌入主题代码中,所以必须使用JavaScript.

谢谢,斯宾塞

Vla*_*kov 6

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

更新:返回JS版本

iframe列表:

来自这些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>
Run Code Online (Sandbox Code Playgroud)

已登录用户[所有者]的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>
Run Code Online (Sandbox Code Playgroud)

已登录用户的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>
Run Code Online (Sandbox Code Playgroud)

可以检测到的差异:

非记录的 iframe 有奇怪的脚本行:

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

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

  • NO与链路href属性包含"仪表盘"图案(CSS方式:a[href*='dashboard']);

记录用户[所有者]的 iframe :

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

  • "关注"的形式;

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

  • href属性的链接包含'仪表板'模式(CSS方式:) a[href*='dashboard'];
  • "跟随"形式;

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

结论

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