We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20215
    • 144 Posts
    I have a user, member of the UserGrop "UG01".
    UG01 has access to the contexts "mgr" and "context01" role Editor-10, access policy AdminLite

    In the frontend I want to check if that user is logged in to the manager to avoid calling a snippet.

    something like this
    [[!isLogged:is=`1`:then=``:else=`[[!HitsPage?&saveTv=`true`]]`]]


    my isLogged snipped code:
    if ($modx->user instanceof modUser) {
      if ( $modx->user->hasSessionContext('mgr') ) {
        return 1;
      }else{
        return 0;
      }
    }


    [[!isLogged]] return 1 only if logged in as an Admin, return 0 if logged in as an Editor (UG01 group)

    MODX Revolution 2.2.6-pl (traditional)
    PHP version 5.2.4

    This question has been answered by mopmodx. See the first response.

      ----------------------------------
      canale irc Italiano #modx server: tophost.azzurra.org
      • 20215
      • 144 Posts
      I tried with new code
      isLogged snippet:
      return $modx->user->get('username'); 

      Manager Logged in as User01 member of the UserGrop "UG01" //return "(anonymous)"
      Manager Logged in as Administrator //return "Admin" - ok
        ----------------------------------
        canale irc Italiano #modx server: tophost.azzurra.org
        • 52634
        • 60 Posts
        Try something like this (i use it to display a special debug-box in the frontend when beeing logged in as a developer):

        [[[[+modx.user.username:is=`yourUG01-Username`:then=` `:else==`!HitsPage?&saveTv=`true``]]]]
        


        Be aware of the double-double-brackets [[[[ ]]]]! This is due to caching and the computing of modx. If you directly call the HitsPage inside, it would be evaluated every time regardless of the conditional "before".
          • 20215
          • 144 Posts
          hi inreti
          [[+modx.user.username]] same result
          Manager Logged in as User01 member of the UserGrop "UG01" // (anonymous)
          Manager Logged in as Administrator // Admin
            ----------------------------------
            canale irc Italiano #modx server: tophost.azzurra.org
          • discuss.answer
            • 20215
            • 144 Posts
            I printed the two different sessions $ _SESSION


            Logget as User01 member of the UserGrop "UG01":
            Array
            (
                [modx.user.contextTokens] => Array
                    (
                    )
            
                [modx.user.0.resourceGroups] => Array
                    (
                        [context01] => Array
                            (
                            )
            
                    )
            
                [modx.user.0.attributes] => Array
                    (
                        [context01] => Array
                            (
                                [modAccessContext] => Array
                                    (
                                        [context02] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                        [context01] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                        [web] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                    )
            
                                [modAccessResourceGroup] => Array
                                    (
                                    )
            
                                [modAccessCategory] => Array
                                    (
                                    )
            
                                [sources.modAccessMediaSource] => Array
                                    (
                                    )
            
                            )
            
                    )
            
            )
            


            Logged in as Admin (Administrator group)

            Array
            (
                [modx.user.contextTokens] => Array
                    (
                        [mgr] => 1
                    )
            
                [modx.user.0.resourceGroups] => Array
                    (
                        [context01] => Array
                            (
                            )
            
                    )
            
                [modx.user.0.attributes] => Array
                    (
                        [context01] => Array
                            (
                                [modAccessContext] => Array
                                    (
                                        [context02] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                        [context01] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                        [web] => Array
                                            (
                                                [0] => Array
                                                    (
                                                        [principal] => 0
                                                        [authority] => 0
                                                        [policy] => Array
                                                            (
                                                                [load] => 1
                                                            )
            
                                                    )
            
                                            )
            
                                    )
            
                                [modAccessResourceGroup] => Array
                                    (
                                    )
            
                                [modAccessCategory] => Array
                                    (
                                    )
            
                                [sources.modAccessMediaSource] => Array
                                    (
                                    )
            
                            )
            
                    )
            
                [modx.mgr.user.token] => modx51544e10edbee6.71439684_1518a28cb96cd13.76311982
                [modx.mgr.session.cookie.lifetime] => 0
            )
            
              ----------------------------------
              canale irc Italiano #modx server: tophost.azzurra.org