We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I am currently working on trying to integrate MODx webusers with Facebook connect, I currently have the system set up to authenticate the user via facebook connect, if this is the first time the user has logged in it then creates a user within MODx allocated to a specific group.

    Now what I want to do is using a snippet log the user in, I can’t use weblogin or webloginpe (I think) since the user will not entering their password or username. All authentication is done on the facebook side all I want to do is once that authentication comes back show MODx that the user is logged in so that document groups / user groups reconise the fact.

    So what I am saying is, is there some system variable/ cookie / db that I can update once the user is authenticated.

    Hope that make sense.
      • 30223
      • 1,010 Posts
      As far as I know there’s nothing ready-made.
      Have a look at weblogin.processor.inc.php in snippets/weblogin/ from about line 186. You’d need to more or less duplicate the code from there minus any $_POST handling and perhaps the events.
        • 34193
        • 330 Posts
        Had a go at this but it errors out at
         $modx->invokeEvent("OnBeforeWebLogin",
                                    array(
                                        "username"        => $username,
                                        "userpassword"    => $givenPassword,
                                        "rememberme"    => $rememberme
                                    ));

        The error is basically invokeEvent on non object any ideas.
          • 20413
          • 2,877 Posts
            @hawproductions | http://mrhaw.com/

            Infograph: MODX Advanced Install in 7 steps:
            http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

            Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
            http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
            • 34193
            • 330 Posts
            Just so people can see what the code is
            <?php
            $user_id = $facebook->require_login();
            
             // if statement dealing with account creation this all works
            
            else
            {
            login($user_id);
            return '<span class="important">'.$nlxAdded.'</span>';}
            
            function login($user) {
            # process login
            
                $username = $modx->db->escape(strip_tags($user));
                $givenPassword = $modx->db->escape($user.'appendextraprivatetopassword']);
                //$captcha_code = isset($_POST['captcha_code'])? $_POST['captcha_code']: '';
                //$rememberme = $_POST['rememberme'];
            
               // invoke OnBeforeWebLogin event
                $modx->invokeEvent("OnBeforeWebLogin",
                                        array(
                                            "username"        => $username,
                                            "userpassword"    => $givenPassword,
                                            "rememberme"    => $rememberme
                                        ));
            


            generates the following error

            Fatal error: Call to a member function escape() on a non-object in ....

            Any help appriciated.
              • 4172
              • 5,888 Posts
              Try:

              <?php
              $user_id = $facebook->require_login();
              
               // if statement dealing with account creation this all works
              
              else
              {
              login($user_id);
              return '<span class="important">'.$nlxAdded.'</span>';}
              
              function login($user) {
              # process login
              
              global $modx;
                  $username = $modx->db->escape(strip_tags($user));
                  $givenPassword = $modx->db->escape($user.'appendextraprivatetopassword']);
                  //$captcha_code = isset($_POST['captcha_code'])? $_POST['captcha_code']: '';
                  //$rememberme = $_POST['rememberme'];
              
                 // invoke OnBeforeWebLogin event
                  $modx->invokeEvent("OnBeforeWebLogin",
                                          array(
                                              "username"        => $username,
                                              "userpassword"    => $givenPassword,
                                              "rememberme"    => $rememberme
                                          ));
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 34193
                • 330 Posts
                Thanks that got me past that problem now the next one. But that is something to do with the SQL statement taken stright from weblogin but not working havent got to look at it now so will come back to it.
                  • 30223
                  • 1,010 Posts
                  Unless you are expecting plugins to work with your snippet and you provide code that acts on the return of these plugins in a consistent way (consistent with how weblogin handles them) there is no need to include the modx->invokeEvent() code in your snippet.
                    • 34193
                    • 330 Posts
                    Quote from: TobyL at Feb 13, 2009, 08:34 AM

                    Unless you are expecting plugins to work with your snippet and you provide code that acts on the return of these plugins in a consistent way (consistent with how weblogin handles them) there is no need to include the modx->invokeEvent() code in your snippet.

                    Thanks for that TobyL I litrally copied the code in weblogin so I therefore assume that it acts on it in some way  further down the code.  And since the idea is to give users a way of using Facebook to log in to MODx it needs to work in as many different situations as possible.  Any how the bit that was causing the problem was solved by adding the
                     global $modx; 
                    suggested by bruno17.

                    The snippet is working except for the log and redirect to home functions which I have currently just commented out since I don’t need immediatly but will look at getting working later. I think this is just a matter of including the relevant files that contain the correct procedures from weblogin.

                    Thanks for the help folks