How to detect if a tumblr user is logged in?

安稳与你 提交于 2019-12-01 19:39:19

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.

UPDATE: return to JS version

List of iframes:

Different block of code from these iframes:

Tumblr iframe for non-logged users:

<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 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 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>

Diffs which can be detected:

Iframe for non-logged has strange script line:

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

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

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

Iframe for logged users [owner]:

  • 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']);

  • There is NO 'follow' form;

Iframe for logged users [non-owner]:

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

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

Conclusion

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!