We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37946
    • 70 Posts
    Is this possible?
    I am trying to validate and pull content from modx entirely via the API. The login snippet is really causing trouble for a simple task of validating a user. I'm looking for a way to do a "simple" mysql lookup based on provided credentials.

    if ( valid )
    {
        echo 'success';
    }
    else
    {
        echo 'fail';
    }
    


    Another thing I am curious about...I have chased the actual login snippet down to this function:
    public function redirectAfterLogin(modProcessorResponse $response)
            {
                $responseArray = $response->getObject();
                
                /* allow dynamic redirection handling */
                $redirectBack = $this->modx->getOption('redirectBack',$_REQUEST,$this->getProperty('redirectBack',''));
                $redirectBackParams = $this->modx->getOption('redirectBackParams',$_REQUEST,$this->getProperty('redirectBackParams',''));
                
                if ( !empty($redirectBackParams) )
                {
                    $redirectBackParams = $this->login->decodeParams($redirectBackParams);
                }
                
                /* otherwise specify a specific resource to redirect to */
                $loginResourceId = $this->getProperty('loginResourceId',$redirectBack);
                /* login posthooks succeeded, now redirect */
    
                if ( !empty($loginResourceId) )
                {
                    $loginResourceParams = $this->getProperty('loginResourceParams',$redirectBackParams);
                    
                    if ( !empty($loginResourceParams) && !is_array($loginResourceParams) )
                    {
                        $loginResourceParams = $this->modx->fromJSON($loginResourceParams);
                    }
                    
                    $url = $this->modx->makeUrl($loginResourceId,'',$loginResourceParams,'full');
                    $this->modx->sendRedirect($url);
                }
                elseif ( !empty($responseArray) && !empty($responseArray['url']) )
                {
                    $this->modx->sendRedirect($responseArray['url']);
                }
                else
                {
    //                $this->modx->sendRedirect($this->modx->getOption('site_url'));
                    error_log( 'USERNAME: '.$this->modx->user('username') );
                }
            }
    

    The output on my error log is: PHP Fatal error: Call to undefined method modX::user()

    I am successfully logging in... why is it that modx doesn't have access to the user at this point? [ed. note: jentree last edited this post 14 years, 4 months ago.]
      • 3749
      • 24,544 Posts
      The error is from your last line. It should be $modx->user->get('username').

      If you are instantiating and initializing the MODX object in your code, you should be able to call the Login processor with runProcessor(), but I'm not sure what the details would be.

      I think you could also use the MODX login form and put your code in a Login posthook.

      Another possibility would be a plugin tied to OnManagerLogin or OnWebLogin.

      I tried in vain to find the code that actually authenticates the user.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 4 months ago.]
        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
        • 37946
        • 70 Posts
        Ha! Yeah, I've found it to be quite a rabbit hole. Thanks for the second set of eyes! I'll dive back in.