Fork me on GitHub

first shot at trying to hack ns_newuser/user.php  Bottom

  • I installed pnTresMailer the otherday. I will be adding like 2500 names to the subscriber list very soon however, i have noticed that if Isubmit a subscriber on the admin side, when that person decides to register for an account on the site, the new user account does not realize that this user has already been subscribed. When the new user account trys to subscribe using the user subscribe method, it returns a failed attempt to subscribe because of duplicate email addresses.

    this is what i thought. I am quite new at this post nuke stuff, but i thought i would give 'er the ol college try.

    I wanted to hack NewUser/user.php so that it would check the subscriber DB table (nuke_nl_sub) for a matching email address with the current new subscriber. if a match existed, then update the column (nuke_nl_sub.sub_uid) with the value of the user id (nuke_users.pn_uid) for the new user.

    Hopefully i haven't confused anyone. but this was my attempt at the function newuser_user_finishnewuser() within newuser/user.php. I know it is coded in a very elementary way but that is currently the only way i know how. here is the function in whole...my "hack" is close tho the bottom.

    Code

    function newuser_user_finishnewuser($var)
    {
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        list($name,
            $agreetoterms,
            $email,
            $femail,
            $vemail,
            $url,
            $pass,
            $vpass,
            $bio,
            $uname,
            $user_avatar,
            $user_icq,
            $user_occ,
            $user_from,
            $user_intrest,
            $user_sig,
            $user_aim,
            $user_yim,
            $user_msnm,
            $user_viewemail,
            $timezoneoffset,
            $dynadata) = pnVarCleanFromInput('name',
            'agreetoterms',
            'email',
            'femail',
            'vemail',
            'url',
            'pass',
            'vpass',
            'bio',
            'uname',
            'user_avatar',
            'user_icq',
            'user_occ',
            'user_from',
            'user_intrest',
            'user_sig',
            'user_aim',
            'user_yim',
            'user_msnm',
            'user_viewemail',
            'timezoneoffset',
            'dynadata');

        $system = pnConfigGetVar('system');
        $adminmail = pnConfigGetVar('adminmail');
        $sitename = pnConfigGetVar('sitename');
        $siteurl = pnGetBaseURL();
        $Default_Theme = pnConfigGetVar('Default_Theme');
        $commentlimit = pnConfigGetVar('commentlimit');
        $storynum = pnConfigGetVar('storyhome');
        if (!pnConfigGetVar('reg_optitems')) {
                // if we don't show optional items
                // we should set the timezone based on site settings
                $timezoneoffset = pnConfigGetVar('timezone_offset');
        }
        $minpass = pnConfigGetVar('minpass'); //by class007

        include 'header.php';
        $stop = userCheck($uname, $email, $agreetoterms);
        // add vpass and vemail check. by class007
        // TODO: remove it to userCheck() [class007]
        if ((isset($pass)) && ("$pass" != "$vpass")) {
            $stop = "<div style=\"text-align:center\"><span class=\"pn-title\">" . _PASSDIFFERENT . "</div></span><br /><br /><br /><br />";
        } elseif (($pass != "") && (strlen($pass) < $minpass)) {
            $stop = "<div style=\"text-align:center\"><span class=\"pn-title\">" . _YOURPASSMUSTBE . " $minpass " . _CHARLONG . "</div></span><br /><br /><br /><br />";
        } elseif (empty($pass) && !pnConfigGetVar('reg_verifyemail')) {
            $stop = "<div style=\"text-align:center\"><span class=\"pn-title\">" . _PASSWDNEEDED . "</div></span><br /><br /><br /><br />";
        } elseif ("$email" != "$vemail") {
            $stop = "<div style=\"text-align:center\"><span class=\"pn-title\">" . _EMAILSDIFF . "</div></span><br /><br /><br /><br />";
        }
        $user_regdate = time();
        if (empty($user_avatar)) $user_avatar = 'blank.gif';
        if (empty($stop)) {
            if (pnConfigGetVar('reg_verifyemail')) {
                $makepass = makepass();
                $cryptpass = md5($makepass);
            } else {
                $makepass = $pass; // for welcome email. [class007]
                $cryptpass = md5($pass);
            }
           
            // some additional checks
            if (!empty($femail)) {
                $femail = preg_replace('/[^a-zA-Z0-9_@.-]/', '', $femail);
            }
            if (!empty($url)) {
                if (!eregi("^http://[\-\.0-9a-z]+", $url)) {
                    $url = "http://" . $url;
                }
                $url = preg_replace('/[^a-zA-Z0-9_@.&#?;:\/-]/', '', $url);
            }
            // end of additional checks
             
            $uid = $dbconn->GenId($pntable['users']);
            $column = &$pntable['users_column'];
            $result =& $dbconn->Execute("INSERT INTO $pntable[users] ($column[name], $column[uname], $column[email],
                               $column[femail], $column[url], $column[user_avatar], $column[user_regdate], $column[user_icq],
                               $column[user_occ], $column[user_from], $column[user_intrest], $column[user_sig],
                               $column[user_viewemail], $column[user_theme], $column[user_aim], $column[user_yim],
                               $column[user_msnm], $column[pass], $column[storynum], $column[umode], $column[uorder],
                               $column[thold], $column[noscore], $column[bio], $column[ublockon], $column[ublock],
                               $column[theme], $column[commentmax], $column[counter], $column[timezone_offset])
                               VALUES ('"
    . pnVarPrepForStore($name) . "','" . pnVarPrepForStore($uname) . "',
                               '"
    . pnVarPrepForStore($email) . "','" . pnVarPrepForStore($femail) . "',
                               '"
    . pnVarPrepForStore($url) . "','" . pnVarPrepForStore($user_avatar) . "',
                               '"
    . pnVarPrepForStore($user_regdate) . "','" . pnVarPrepForStore($user_icq) . "',
                               '"
    . pnVarPrepForStore($user_occ) . "','" . pnVarPrepForStore($user_from) . "',
                               '"
    . pnVarPrepForStore($user_intrest) . "','" . pnVarPrepForStore($user_sig) . "',
                               '"
    . pnVarPrepForStore($user_viewemail) . "','',
                               '"
    . pnVarPrepForStore($user_aim) . "','" . pnVarPrepForStore($user_yim) . "',
                               '"
    . pnVarPrepForStore($user_msnm) . "','" . pnVarPrepForStore($cryptpass) . "',
                               '"
    . pnVarPrepForStore($storynum) . "','',0,0,0,'" . pnVarPrepForStore($bio) . "',0,'','',
                               '"
    . pnVarPrepForStore($commentlimit) . "', '0', '" . pnVarPrepForStore($timezoneoffset) . "')");
            // insert dynadata [class007]
            if (!empty($dynadata) && is_array($dynadata)) {
                while (list($key, $val) = each($dynadata)) {
                    pnUserSetVar($key, $val);
                }
            }

            if ($dbconn->ErrorNo() <> 0) {
                echo $dbconn->ErrorNo() . ": " . $dbconn->ErrorMsg() . "<br />";
                error_log ($dbconn->ErrorNo() . ": " . $dbconn->ErrorMsg() . "<br />");
            } else {
                // get the generated id
                $uid = $dbconn->PO_Insert_ID($pntable['users'], $column['uid']);

                // Let any hooks know that we have created a new item
                pnModCallHooks('item', 'create', $uid, 'uid');

                // Add user to group
                $column = &$pntable['groups_column'];
                $result =& $dbconn->Execute("SELECT $column[gid]
                                          FROM $pntable[groups]
                                          WHERE $column[name]='"
    . pnConfigGetVar('defaultgroup') . "'");
                if ($dbconn->ErrorNo() <> 0) {
                    echo $dbconn->ErrorNo() . _GETGROUP . $dbconn->ErrorMsg() . "<br />";
                    error_log ($dbconn->ErrorNo() . _GETGROUP . $dbconn->ErrorMsg() . "<br />");
                } else {
                    if (!$result->EOF) {
                        list($gid) = $result->fields;
                        $result->Close();
                        $column = &$pntable['group_membership_column'];
                        $result =& $dbconn->Execute("INSERT INTO $pntable[group_membership] ($column[gid], $column[uid])
                                                  VALUES ("
    . pnVarPrepForStore($gid) . ", " . pnVarPrepForStore($uid) . ")");
                        if ($dbconn->ErrorNo() <> 0) {
                            echo $dbconn->ErrorNo() . _CREATEGROUP . $dbconn->ErrorMsg() . "<br />";
                            error_log ($dbconn->ErrorNo() . _CREATEGROUP . $dbconn->ErrorMsg() . "<br />");
                        }
                    }
                    $message = "" . _WELCOMETO . " $sitename ($siteurl)!\n\n" . _YOUUSEDEMAIL . " ($email) " . _TOREGISTER . " $sitename. " . _FOLLOWINGMEM . "\n\n" . _UNICKNAME . " $uname\n" . _UPASSWORD . " $makepass";
                    $subject = "" . _USERPASS4 . " $uname" . _USERPASS42 . "";
                    $from = "$adminmail";
                    /**
                     * if ($system == 1) {
                     * echo "<table align=\"center\"><tr><td><span class=\"pn-normal\">"._YOURPASSIS." <strong>$makepass</strong></span><br />";
                     * echo "<a class=\"pn-normal\" href=\"user.php?module=NS-User&op=login&uname=$uname&pass=$makepass&url=user.php\">"._LOGIN."</a><span class=\"pn-normal\"> "._2CHANGEINFO."</span></td></tr></table>";
                     * } else {
                     */

                    // 11-09-01 eugeniobaldi not compliant with PHP < 4.0.5
                    // pnMail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion(), "-f$from");
                    // if (pnConfigGetVar('reg_verifyemail')) {
                    pnMail($email, $subject, $message, "From: $from\nX-Mailer: PHP/" . phpversion(), 0);
                    // }
                    if (pnConfigGetVar('reg_notifyemail') != "") {
                        $email2 = pnConfigGetVar('reg_notifyemail');
                        $subject2 = _NOTIFYEMAILSUB;
                        $message2 = _NOTIFYEMAILCONT1 . "$uname" . _NOTIFYEMAILCONT2;
                        pnMail($email2, $subject2, $message2, "From: $from\nX-Mailer: PHP/" . phpversion(), 0);
                    }
                   
                   
                   
                    OpenTable();

    //------------this is my attempt---------------------------------------------->

                    //check for subscription hack
                    $resultHACK =& $dbconn->Execute("SELECT * FROM nuke_nl_subscribers WHERE sub_email='".pnVarPrepForStore($email)."'");
                    if (mysql_num_rows($resultHACK)>=1) {
                    $rowa=@mysql_fetch_assoc($resultHACK);
                    echo("got this far");
                    }
                    else {}
                    //end Hack


    //-------------------end my attempt-----------------------

                    echo "<span class=\"pn-normal\">" . _YOUAREREGISTERED . "</span>";
                    CloseTable();
                }
               
            }
        } else {
            echo "$stop";
        }
        include 'footer.php';
    }


    as you notice, i haven't even begun to code the UPDATE portion of it. I only have echo'd "got this far" so that i might at least feel good about myself for getting one step instead of trying to accomplish it all in one giant leap.

    anyway....this is not working.....can somone tell me why?
  • Mine won't let two users have the same email address. Is this already in PN?I checked a box somewhere, sorry can't recall when/where I did
  • yeah.....that is the case. but TresMailer works off a second user table that was created on install of TresMailer (which also can not have multiple instances of the same email addy). THe process is seemless for a registered user to subscribe to a newsletter and that works great! however, my problem is we will have 2500 unregistered users in the subscription table. so when those 2500 unregistered users decide to register, they are noted as not subscribed. i am trying to come up with a way that when a new user registers, the registration checks the subscription DB for a matching email address, and updates the record accordingly.
  • I got it to work

    ............This calls for a drink! round on me......i created my first mod (that actually worked)! woo hoo!
  • could you please share with us how you done this?

    Thanks,

    Gary
  • raskolnikov

    I got it to work

    ............This calls for a drink! round on me......i created my first mod (that actually worked)! woo hoo!


    Congratulations! I'll take a single malt on the rocks. icon_lol

    Slugger

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