We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34459
    • 134 Posts
    Normally you specify the page that you go after login but is it possible to redirect user a user after login to a page depending on his user name/access permissions? The goal is to redirect users after login to their home pages created earlier instead of a general page.
      Check out blackflow.pl
      • 33968
      • 863 Posts
      You’ll need to use a postHook together with a short snippet that will do your redirect for you.

      Look into $modx->user->isMember() and $modx->sendRedirect() to switch to the correct member page on login.
        • 34459
        • 134 Posts
        ok, so...

        to my login page


        [[!Login? &loginTpl=`lgnLoginTpl` &logoutTpl=`lgnLogoutTpl` &errTpl=`lgnErrTpl` &logoutResourceId=`5` &redirectToPrior=`1`]]


        I add a hook

        &postHooks=`hookUserLogin`


        and in the snippet I would add this?

        $username_login =  $hook->getValue(‘username’)
        $modx->sendRedirect($username_login)
        


        The thing is that in theory every user is going to have his own page with different content.For that I wanted to create individual group for every user (I am aware is not very elegant but it is a very small scale thing and I’m relatively new to modx.)instead of user access groups so I cant use isMember(). Am I even remotely on the right track?
          Check out blackflow.pl
          • 33968
          • 863 Posts
          How are you relating users with their pages, is that something you would configure manually for each?
          Do they register themselves or are you setting them up?

          Your snippet code is a little off, you’re looking for something more like this (untested):
          <?php
          $username = $hook->getValue('username');
          switch ($username) {
              case 'Josh' :
                  $pageid = '4';  // Josh's login page
                  break;
              case 'Michael' :
                  $pageid = '12';  // Michael's login page
                  break;
              case 'Kate' :
                  $pageid = '14';  // Kate's login page
                  break;
          }
          
          $userpage = $modx->makeUrl($pageid); 
          $modx->sendRedirect($userpage); 
          

          Ideally you wouldn’t have to manually set the pages in the snippet; there should be some kind of relationship between each user and their login page that we can access via modx.

          Do users register themselves or are you setting them up? Is there a profile field or similar where the login page id is held?
            • 34459
            • 134 Posts
            I would set them up manually...It’s a fairly simple concept to make personal pages for clients with stuff that we designed for them.
            My first idea was to make access groups for each individual user, e.g for Josh I would create Josh access group and page(resource) Josh with link to 3 sub pages that only Josh can enter due to access privileges. I thought that as long as the username is identical to the name of his page I could skip the switch statement.

            The more elegant way as I did it in plain php, was to make universal resources(pages) and then generate the frotend content depending on the individual user id. But for that I need more practise so I came up with the thing above.
              Check out blackflow.pl