Fork me on GitHub

Simultaneous PostNuke DB login and other DB login  Bottom

  • first.
    can't call myself a 'developer' (but I do aspire wink ) so please bear with my n00blishness icon_rolleyes

    what I'm trying to accomplish:
    login to PostNuke and automatically login (setting cookies,too) to an external portion of my website,sparing users from logging in twice.
    (something like the pnphpbb module)

    particulars:
    I'm running a, uhm.. tracker using:
    XBTT as the tracker, and using
    BTIT as a front end for the tracker.

    I would like users to access PostNuke, see the news articles,and click attached link to see more details/download torrent from the tracker (these are functions of BTIT.)
    However, I do not want most users to access the main tracker itself.

    so what I have done so far is:

    Modified New Accounts,Recover Lost Password,Change Info.
    i.e user registers with PN,is registered with BTIT. same with recover password (on recover it updates BTIT DB). same with change info.
    These modifications are really simply copying code from BTIT into the appropriate PN *.php code.

    In order not to clutter this post I am posting those working changes outside this board.
    NS-NewUser\user.php
    NS-LostPassword\user.php
    NS-Your_Account\user…ules\changeinfo.php

    now to the problem:
    here is the BTIT code for logging in/out
    first BTIT's include.php has the following functions

    Code

    function logincookie($id, $passhash, $expires = 0x7fffffff)
    {
        setcookie("uid", $id, $expires, "/");
        setcookie("pass", $passhash, $expires, "/");
    }

    function logoutcookie() {
        setcookie("uid", "", 0x7fffffff, "/");
        setcookie("pass", "", 0x7fffffff, "/");

    (I cannot use it as an include in PN as some other BTIT functions clash with PN,so I have to copy/paste those two functions into wherever the PN login/out functions are)

    code login

    Code

    // *** btit begin edit ***

             $res = mysql_query("SELECT * FROM users WHERE username ='$uname' AND password ='" . md5($pass) . "'") or die(mysql_error());
        $row = mysql_fetch_array($res);
        logincookie($row["id"],$row["password"]);

    // *** btit end edit ***

    and logout

    Code

    // *** btit begin edit ***

            logoutcookie();

    // *** btit end edit ***


    now where to put these?

    n00bly I put them in to 'www\includes\pnUser.php' :wince:

    well it worked..sort of.

    it logins to to PN and BTIT (cookies created) and logs out ok..but...
    If,while logged in I change my account info,it will let me do so ONCE.
    When attempting to change info again, I get:
    'Sorry! You did not enter the same password in each password field. Please enter the same password twice'

    eww!

    Its not a 'changeinfo.php' or the other modification issue as I played around changing back my changes and narrowing it down to the 'pnUser.php' change.

    here is the code of change:

    Code

    // Original Author of file: Jim McDonald
    // Purpose of file: User functions
    // ----------------------------------------------------------------------

    // *** btit begin edit ***

    function logincookie($id, $passhash, $expires = 0x7fffffff)
    {
        setcookie("uid", $id, $expires, "/");
        setcookie("pass", $passhash, $expires, "/");
    }

    function logoutcookie() {
        setcookie("uid", "", 0x7fffffff, "/");
        setcookie("pass", "", 0x7fffffff, "/");
    }

    // *** btit end edit ***

    /**
     * @package PostNuke_Core
    .
    .
    .
    .
    // Set session variables
            pnSessionSetVar('uid', (int)$uid);

            if (!empty($rememberme)) {
                pnSessionSetVar('rememberme', 1);
            }
         }
    // *** btit begin edit ***

             $res = mysql_query("SELECT * FROM users WHERE username ='$uname' AND password ='" . md5($pass) . "'") or die(mysql_error());
        $row = mysql_fetch_array($res);
        logincookie($row["id"],$row["password"]);

    // *** btit end edit ***
         return true;

    }

    /**
     * Compare Passwords
    .
    .
    .
    function pnUserLogOut()
    {
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        if (pnUserLoggedIn()) {
            // Reset user session information (new table)
            $sessioninfocolumn = &$pntable['session_info_column'];
            $sessioninfotable = $pntable['session_info'];
            $query = "UPDATE $sessioninfotable
                      SET $sessioninfocolumn[uid] = 0
                      WHERE $sessioninfocolumn[sessid] = '" . pnVarPrepForStore(session_id()) . "'";
            $dbconn->Execute($query);

            pnSessionDelVar('rememberme');
            pnSessionDelVar('uid');
            pnSessionDestroy(session_id());

    // *** btit begin edit ***

            logoutcookie();

    // *** btit end edit ***

        }
    }

    /**


    I assume PN does something like set a session cookie checking perms when making changes and after altering the user DB info the first time when attempting to change info a 2nd time,perms dont match,or something deep like that. :)
    I know modding the pnUser.php (or any of core) is a big no-no :( ,especially by n00bs but I cant figure any place else to put it :scratches head:
    What I've attempted is a pretty coarse/unelegant mod ((besides not working :/ ) just remember my utter n00bness,please forgive
    :)

    any suggestions as to what,where to hack/insert these BTIT login/out functions/code would be highly appreciated

    thanks,

    AuntieSocial (The DEV! icon_lol )
  • Sorry, dont have any help for you, but thanks for posting your hacks. I am definately going to follow this thread.
  • {bump}

    any ideas at all? :(

    BTW, it seems the logout cookie code does work.

    its where to put the login cookie code thats the problem.

    ???

    tnx
  • problem solved.

    problem was on BTIT end,not PN.

    BTIT sets two cookies.
    "uid" and "pass".
    This apparently clashes with PN (not sure why,maybe someone can explain?)

    so,I changed "uid" to "bt_uid" (you can change it to whatever),and "pass" to "bt_pass".

    Changes were made to BTIT's './include/functions.php' (I mistakenly referred to it as 'includes.php' in my first post) at line #587,so it looks like this:

    Code

    // *** edit *** cookie names were changed so as not to conflict with PostNuke cookie. Original names are: "uid" and "pass.

    function logincookie($id, $passhash, $expires = 0x7fffffff)
    {
        setcookie("bt_uid", $id, $expires, "/");
        setcookie("bt_pass", $passhash, $expires, "/");
    }

    function logoutcookie() {
        setcookie("bt_uid", "", 0x7fffffff, "/");
        setcookie("bt_pass", "", 0x7fffffff, "/");
    }
    .
    .
    .
    line #666
    // guest
        if (empty($_COOKIE["bt_uid"]) || empty($_COOKIE["bt_pass"]))
           $id=1;

        if (!isset($_COOKIE["bt_uid"])) $_COOKIE["bt_uid"] = "";
         $id = 0 + $_COOKIE["bt_uid"];
        // it's guest
    .
    .
    .
    line #684
    if (!isset($_COOKIE["bt_pass"])) $_COOKIE["bt_pass"] = "";
        if (($_COOKIE["bt_pass"] != $row["password"]) && $id != 1)
           {


    and changes to 'pnUser.php':
    @ beginning of file:

    Code

    // *** btit begin edit ***

    function logincookie($id, $passhash, $expires = 0x7fffffff)
    {
        setcookie("bt_uid", $id, $expires, "/");
        setcookie("bt_pass", $passhash, $expires, "/");
    }

    function logoutcookie() {
        setcookie("bt_uid", "", 0x7fffffff, "/");
        setcookie("bt_pass", "", 0x7fffffff, "/");
    }

    // *** btit end edit ***


    logincookie code added @: line #92

    Code

    // Set session variables
            pnSessionSetVar('uid', (int)$uid);

            if (!empty($rememberme)) {
                pnSessionSetVar('rememberme', 1);
            }
         }
    // *** btit begin edit ***

             $res = mysql_query("SELECT * FROM users WHERE username ='$uname' AND password ='" . md5($pass) . "'") or die(mysql_error());
        $row = mysql_fetch_array($res);
        logincookie($row["id"],$row["password"]);

    // *** btit end edit ***
         return true;

    }


    and logout code @: line #161

    Code

    pnSessionDestroy(session_id());

    // *** btit begin edit ***

            logoutcookie();

    // *** btit end edit ***

        }


    note: line #'s refer to line #'s before code insertion {duh! ;) }

    so now I have a working login/out to PN and BTIT.

    (I made other changes to PN to allow for simultaneous PN/BTIT registration, and change account info, have work to do to hack PN to integrate other admin functions with BTIT,i.e deleting users,admin changing user info etc. But the basics are there I posted those changes elsewhere here on forum)

This list is based on users active over the last 60 minutes.