We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3634
    • 19 Posts
    I have tried to handle the web login for users and I have accomplished this by executing login processor under security location.
    However it looks that the event object doesn’t actually receive a modUser reference($modx->event->params[’user’] is of type modUser_mysql), in its user member as described in docs so I dig a lil further and:

    I have updated the executeProcessor with the newly runProcessor.
    I have updated xpdo files with the latest changes so xpdo respect the class key, and now the login processor file raise an error:

    Fatal error: Call to a member function get() on a non-object in \core\model\modx\processors\security\login.php on line 88

    $up->get(’failed_logins’)

    ...just so you know that this file has to be updated as well, it seams.

    or I am confused smiley
      • 3749
      • 24,544 Posts
      You’re much more likely to get help here if you explain what you’re trying to do and why (for example, why you’re not using the Login snippet) and what version of MODx you’re using.

      There may be a way of doing what you want without altering the core code, but you’d have to tell us what you want to do to find out.





        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 3634
        • 19 Posts
        Ok. First of all I don’t intend to alter the core, I just tried to solve my problem smiley

        I have tried to use the Login snippet but somehow it didn’t worked as I expected so I decided to write my own snippet to handle logins.

        So:
        - I am using MODx Revolution 2.0.4-pl2.
        - I am writing a plugin that listen for OnWebLogin.

        The problem:
        - Inside the plugin, the reference $modx->event->user is not of expected type modUser but of type modUser_mysql and I thought that might be because of the way I am loging in my users.

        My login snippet code:

        <?php
        //get current url
        $url = $modx->makeUrl($modx->resource->get('id'));  
        
        //check if logout is requested
        if($modx->user->isAuthenticated('web') && isset($_REQUEST['logout']))
        {
           $modx->executeProcessor(array(
                        'action' => 'logout',
                        'location' => 'security'
                    ));
          $modx->sendRedirect($url);
          return;
        }
        
        //check if login is requested
        if (!$modx->user->isAuthenticated('web') && isset($_REQUEST['login']) ) { 
        
          $response = $modx->executeProcessor(array(
                        'action' => 'login',
                        'location' => 'security'
            ,
                       'username' => $_REQUEST['username'],
                      'password' => $_REQUEST['password'],  
                      'login_context' => 'web'  
                    ));
        
          if( $response['success'] ) $modx->sendRedirect($url);
          return;
        }
        ?>
        


        Another problem is that inside the plugin, OnWebLogin, even after the user entered the correct details and it is logged in, the $modx->user is (anonymous) and will be set to the correct reference just after browser redirects to the other url (so after session ends and restarts).

        I hope I was clearer this time. Thank you.
          • 3634
          • 19 Posts
          Also,
          I solved the problem itself but I think the $modx->event->user should be of expected type,
          and $modx->user should get the right value after OnWebAuthentication during OnWebLogin.
          I had to construct the user instance inside plugin code to do what I was looking for:
          <?php
          $modx->setLogLevel(modX::LOG_LEVEL_INFO);  
          $modx->setLogTarget('FILE');
          $modx->log(modX::LOG_LEVEL_INFO,$modx->event->name);
          
           if($modx->event->name == 'OnWebLogin')
           {
              $user = $modx->getObject('modUser',$modx->event->params['user']->id);
              $profile = $user->getOne('Profile');
              /*...*/
          }
          ?>
          
            • 3749
            • 24,544 Posts
            I don’t know if this will help you, but OnWebAuthentication fires after the user has been found and authenticated and is determined to be headed for the front-end context, but before the user has been determined to be authorized to access that context. OnWebLogin fires just after the user has been cleared for access to the front end context.

            You haven’t really said why the existing Login snippet didn’t work for you. An awful lot of people are using it to log users in. wink
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 3634
              • 19 Posts
              Yes, but both events should have a reference to a modUser object and they don’t (instead they have references to a modUser_mysql object). Also in both of them $modx->user is not what would’ve been expected but (anonymous).

              I didn’t use Login snippet because I was to lazy to customize its templates smiley) and also probable because of the upper presented behavior, which I thought could be an issue of the Login snippet but it is an issue of the core.

              Thank you.