Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-20455

eZUser::isLoggedIn does not correctly check user's state

    Details

      Description

      The eZUser::isLoggedIn method will always return true, when given a valid userID. This is because the method simply checks that a given userID maps to a user with a ContentID that does not match an Anonymous id, or -1.

      I assume that the initial idea was that this method would always act on the current active user (thus returning a correct result), but in reality it can also be used on any User, using ::fetch, for example:

      eZUser::fetch(<user id>)->isLoggedIn()
      

      This will always return true, as long as user id is valid, regardless of that user's state.

      The eZUser::isUserLoggedIn method already correctly returns if a user is logged in or not, so my suggestion for a fix is to make use of it. In pseudo-code:

      function isLoggedIn
        if (thisUser) is (activeUser)
          return thisUser is valid
        else
          return ::isUserLoggedIn(thisUser->id)
      

      The result of isUserLoggedIn will also ideally be cached with the user instance it relates to, to prevent repeat queries to ezuservisit

        Activity

        Hide
        Patrick Allaert (Inactive) added a comment -
        Show
        Patrick Allaert (Inactive) added a comment - Pull request proposed at: https://github.com/ezsystems/ezpublish-legacy/pull/566
        Show
        André Rømcke added a comment - Fixed in https://github.com/ezsystems/ezpublish-legacy/commit/73ccec1d8fbf63b90f12a8c6c58228a4793541ea
        Hide
        Chen Xiongjie (Inactive) added a comment -

        Note to myself: the eZUser::isUserLoggedIn is not change by the pull request.

        Show
        Chen Xiongjie (Inactive) added a comment - Note to myself: the eZUser::isUserLoggedIn is not change by the pull request.
        Hide
        Chen Xiongjie (Inactive) added a comment -

        Update to @Pedro's comment:

        It works fine on 4.7. On 5.0 it always returns true.

        Show
        Chen Xiongjie (Inactive) added a comment - Update to @Pedro's comment: It works fine on 4.7. On 5.0 it always returns true.
        Hide
        Chen Xiongjie (Inactive) added a comment -

        Revert last comment. It's the same behavior of 4.7 and 5.0.

        Added pull request: https://github.com/ezsystems/ezpublish-legacy/pull/613

        Show
        Chen Xiongjie (Inactive) added a comment - Revert last comment. It's the same behavior of 4.7 and 5.0. Added pull request: https://github.com/ezsystems/ezpublish-legacy/pull/613
        Show
        Yannick Roger (Inactive) added a comment - Fixed in: eZ Publish master: https://github.com/ezsystems/ezpublish-legacy/commit/73ccec1d8fbf63b90f12a8c6c58228a4793541ea eZ Publish master: https://github.com/ezsystems/ezpublish-legacy/commit/1a1b070819beadc6e01dc998d64f656f9786c109

          People

          • Assignee:
            Unassigned
            Reporter:
            Filipe Dobreira (Inactive)
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - Not Specified
              Not Specified
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 1 day, 5 hours, 35 minutes
              1d 5h 35m