Prevent to Cache Login Information

2019-08-02 17:31发布

I'am using femanager to manage user registration, login and logout.

Like many other websites, I'd like to show some user information on the top of the page (using Boostraps mini-navbar).

  • If the user is logged out, this should look like: Call for registration if the user is not logged in
  • If the user is logged in, this information should displayed: Greetings if the user is logged in

As a Typo3 beginner, I implement this with Typo Script and a partial in Fluid Template. The Typo Script reads the current user (user id and e-mail address).

userdata = COA_INT
userdata {
  10 = TEXT
  10.data = TSFE:fe_user|user|uid
  20 = TEXT
  20.data = TSFE:fe_user|user|username
}

The partial uses the user id to check if the user is logged in or logged out.

<f:if condition="{f:cObject(typoscriptObjectPath: 'userdata.10')} > 0">
  <f:then>
      <!-- user is logged in -->
      <span class="greeting">
        <i class="fa fa-user"></i> <f:cObject typoscriptObjectPath="userdata.20" />
      </span>
      <f:link.page pageUid="319" additionalParams="{logintype: 'logout'}" class="pull-right"><i class="fa fa-power-off"></i> Logout</f:link.page>
  </f:then>
  <f:else>
     <!-- user is logged out -->
      <span class="greeting">
        Test it for free
      </span>
      <f:link.page pageUid="317" class="pull-right"><i class="fa fa-arrow-circle-down"></i> Register</f:link.page>
      <f:link.page pageUid="319" class="pull-right"><i class="fa fa fa-sign-in"></i> Log in</f:link.page>
  </f:else>
</f:if>

This works OK but I have problems with caching. Sometimes the mini-navbar is shown for an other user.

My question is: How can I prevent the partial from caching?

标签: caching typo3
1条回答
Animai°情兽
2楼-- · 2019-08-02 18:14

Caching in Partials can be tricky sometimes..

Take a look at the security viewhelper within the VHS viewhelper collection. It has some nice functionality which covers your case:

<v:security.allow anyFrontendUser="TRUE">
    <f:then><!-- protected information displayed --></f:then>
    <f:else><!-- link to login form displayed --></f:else>
</v:security.allow>

See the documenation for more information.

查看更多
登录 后发表回答