We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4698
    • 5 Posts
    I have a little snippet which can integrate another local web-application including integrated single signon capabilities.
    Current available applications are SMF, Coppermine, Mantis & TNG (easily extendable for other apps.
    Same userid/password usage for modx and application without changing core code.
    You can see it in action at www.nuy.info

      • 25663 MODX Staff
      • 12,272 Posts
      I can confidently say that it’d be tremendously helpful to learn how you’ve accomplished SSO, particularly with SMF. Can you share your code, please?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4698
        • 5 Posts
        here we go. Create a snippet called ’wrapssi’and here is the coide for the snippet:
        <?php
        $wurl1 = $wurl;
        $wurl1 .= "/index.php";
        if ($_SESSION['webUser']) { 
         	$cpgpwd=$_SESSION['webValid'];
        	$wurl .= "/index_etomite.php?parm=";
        	$wurl .= base64_decode($_SESSION['webUser'] ) ;
        	$wurl .="|" ;
        	$wurl .= $_SESSION['webEmail']  ;
        	$wurl .="|" ;
        	$wurl .= $_SESSION['webValid'];
        	$wurl .="|" ;
        	$wurl .= $wurl1 ;
        }
        $wrapped = "<IFRAME id='myframe'";
        $wrapped .= "SRC='".$wurl."'";
        $wrapped .= "scrolling='no' marginwidth='0' marginheight='0' frameborder='0' vspace='0' hspace='0' style='overflow:visible; width:100%; display:none'></iframe>";
        return $wrapped;
        ?>


        next in your template add the following code (only to avoid double scrollbars) towards the end of the HEAD section:
        <script type="text/javascript">
        
        /***********************************************
        * IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
        * Visit DynamicDrive.com for hundreds of original DHTML scripts
        * This notice must stay intact for legal use
        ***********************************************/
        
        //Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
        //Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
        var iframeids=["myframe"]
        
        //Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
        var iframehide="yes"
        
        var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
        var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers
        
        function resizeCaller() {
        var dyniframe=new Array()
        for (i=0; i<iframeids.length; i++){
        if (document.getElementById)
        resizeIframe(iframeids[i])
        //reveal iframe for lower end browsers? (see var above):
        if ((document.all || document.getElementById) && iframehide=="no"){
        var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
        tempobj.style.display="block"
        }
        }
        }
        
        function resizeIframe(frameid){
        var currentfr=document.getElementById(frameid)
        if (currentfr && !window.opera){
        currentfr.style.display="block"
        if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
        currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight; 
        else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
        currentfr.height = currentfr.Document.body.scrollHeight;
        if (currentfr.addEventListener)
        currentfr.addEventListener("load", readjustIframe, false)
        else if (currentfr.attachEvent){
        currentfr.detachEvent("onload", readjustIframe) // Bug fix line
        currentfr.attachEvent("onload", readjustIframe)
        }
        }
        }
        
        function readjustIframe(loadevt) {
        var crossevt=(window.event)? event : loadevt
        var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
        if (iframeroot)
        resizeIframe(iframeroot.id);
        }
        
        function loadintoIframe(iframeid, url){
        if (document.getElementById)
        document.getElementById(iframeid).src=url
        }
        
        if (window.addEventListener)
        window.addEventListener("load", resizeCaller, false)
        else if (window.attachEvent)
        window.attachEvent("onload", resizeCaller)
        else
        window.onload=resizeCaller
        
        </script>
        


        Call the application like:
        [!wrapssi?wurl=http://yoursite.com/smf!]
        


        Final step is to have a special index_etomite.php script which goes into the root directory of SMF.
        Here is the code for that script:
        <?php
        require "smf_api.php";
        
        $reqVar = '_' . $_SERVER['REQUEST_METHOD'];
        $form_vars = $$reqVar;
        $parm = $form_vars['parm'] ;
        $url = explode("|", $parm);
        $f_username = $url[0];
        $f_usermail = $url[1];
        $f_userpw = $url[2] ;
        $f_pwd = base64_decode($f_userpw);
        
        
        if ($f_username != ""){
        	if ($f_pwd == ""){
        		$f_pwd = ranpass() ;
        	}
        	$sql= "SELECT passwordSalt FROM $smf_settings[db_prefix]members WHERE memberName = '$f_username' LIMIT 1";
        	$result = mysql_query($sql);
        	$num_rows = mysql_num_rows($result);
        	if ($num_rows < 1){
        		// Insert the new user
        		$adding = smf_registerMember($f_username,$f_usermail,$f_pwd) ;
        	} else {
        		// update password
        		$password = sha1(strtolower($f_username) . $f_pwd);
        		$sql= "update $smf_settings[db_prefix]members set passwd='$password' WHERE memberName = '$f_username' ";
        		$result = mysql_query($sql);
        	}
        }
        
        $whereto = "./index.php" ;
        $cookok = smf_setLoginCookie(3600, $f_username,$f_pwd, false) ;
        if (!$cookok) {
        }
        $loginok = smf_authenticateUser() ;
        if (!$loginok) {
        }
        Header ("Location: $whereto");
        exit ;
        
        function ranpass($len = "8"){
         $pass = NULL;
         for($i=0; $i<$len; $i++) {
           $char = chr(rand(48,122));
           while (!ereg("[a-zA-Z0-9]", $char)){
             if($char == $lchar) continue;
             $char = chr(rand(48,90));
           }
           $pass .= $char;
           $lchar = $char;
         }
         return $pass;
        }
        ?>
        


        Basically all you need in combination with my snippet special index_etomite.php scripts.
        Those i have for the afore mentioned applications.

        Enjoy this solution.
          • 8542
          • 37 Posts
          I tried this, and it does sync the user from Modx to SMF, and even updates the password. However, the only problem I seem to be having is that when I login to modx, it does not log me into the forums automatically, like it is supposed to.

          Also a tip, on your forums, make sure you disable registrations, as this is only a one way solution. Modx users/pass will carry to the forums just fine, however from the forum to modx will not.

          I would love to get the problem with it not auto logging in correctly resolved.

          Correction: It works just fine for Internet Explorer, however it doesn’t agree well with Firefox for some reason.

          No idea why this happens. And this is kinda frustrating, as most of the time and most of the people using the site use firefox.
            • 4698
            • 5 Posts
            I will verify behavior in FF & Chrome. I indeed use IE but have also installed these browsers now.
              • 8542
              • 37 Posts
              Casn, do you happen to have anything for IPB? ^_^. Definitely a superior forum system. PM me, or post back here if we can maybe arrange something. I am decent at php and can likely help.
                • 4698
                • 5 Posts
                IPB would also be possible. It would follow the same track as for SMF (or Coppermine/Mantis).
                The issue with IPB is that this is licensed software of which I have no copy.
                  • 8542
                  • 37 Posts
                  I can provide a test board if you would like. Pm me or message me on xfire/aim/msn - Xfire = Dameon87 / Aim = Dameon87 / Msn = Dameon AT xtrememodderz DOT com
                    • 4698
                    • 5 Posts
                    Have tested this little mod under FF 3.0.10 and Chrome 3.0.190.1 and it works flawlessly on my workstation (still on Windows).
                    As for IPB, really need the sources itself to find out how the logon process is running.