vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   Add new Users (automatically) (https://vborg.vbsupport.ru/showthread.php?t=82836)

asphix 06-21-2006 04:50 PM

thanks a million for this script cause I really needed it
it works like a charm

bradsears 06-21-2006 04:53 PM

I'd really like to be able to set the cookie and log the user in after they are instantly registered. Any ideas?

scorinaldi 07-10-2006 04:48 AM

i agree wtih bradsears. can anyone shed some light on how to automatically log in a user?

do we just set the cookies and that's it?

workRelated 07-26-2006 11:13 PM

I recently added a field to the user profile (gender)
I also renamed location to country
I would like to be able to automatically set these fields similarly to the other fields in the above example. Im unclear as to how this would be possible.

Any help would be greatly appreciated.

djdrey 10-05-2006 12:49 AM

Quote:

Originally Posted by bigtime
How would a new user be added without using curl?

Thanks,

Tim

You don't have to use CURL to do it, but you have to include globals.php in your script root if you want to create the user from within a function or method.

You also have to remember to retrieve the global vbulletin variable to pass into the datamanager class.

I spent the last few hours working that out, hopefully it'll help someone else!

bigtime 10-05-2006 12:52 AM

Thanks. Would you mind posting the code you used?

novastar 10-27-2006 01:59 AM

i use a modified version of the code they gave a couple posts back which works great for me.
Code:

<?php
$username="username";
$email="email@address.com";
$password="password";
$usergroupid="2";
$timezoneoffset="-6";
define('THIS_SCRIPT', 'remote_register.php');
chdir('/home/site/public_html/forum');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
} else {
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
}
chdir('/home/site/public_html/');
?>

I would have taken more time to tinker with it, and possibilly put it in a function, but as there is only 1 place in my scripting but that works fine for me.
Im running it on vBulletin 3.6.2

XxRaidenxX 12-22-2006 08:25 AM

Hello,

i use the code it's work fine but i have one problem. I can login the user but when i in the admincp and i edit the user i dont see any username in the inputfield! What is wrong?

Raiden

testebr 12-23-2006 12:24 PM

Its possible verify if the usergroup exists before add to database the new user?

Exemple, to test I set the usergroup to 2000000 and VB ignore and inserted the user normally.

ps: same problem with password field, I set like empty and vbulletin inserted the data..

timedgar 02-13-2007 12:06 AM

Hello All,


I'm using the following code, posted by Brad Sears, for sending out activation emails after adding a user via the script on this thread:

PHP Code:

$activateid build_user_activation_id($newuserid20);
eval(
fetch_email_phrases('activateaccount'));
vbmail($email$subject$messagetrue); 


It works, sort of. The only problem is that the email does not contain the username of the user being emailed (it begins "Welcome, (blank)"). The userid in the links and the email address it sends to are correct, but no username...

Do I need to pass additional variables to these functions?


Thanks!

Tim

Ba$im 04-24-2007 12:45 AM

i dont know how do it?
let c what i can understand
first creat vB_Datamanager_User.php file then put this code and upload to vb folder in your site
then
ask this
http://yoursite/vb/vB_Datamanager_User.php
it just registerd 1 user???
and i should change username and email again and reupload???

how it does automatically???

can any one help me how do this plz

Spandauer 04-27-2007 03:56 PM

Hi everybody,

is it also possible to pass a simple URL to a script, which takes the variables from the URL and registers the new user? The problem is, that i dont have the possibility to send something else... the only thing i can do for my project is sending an URL... will it be possible?

Poc1984 04-30-2007 10:09 PM

Is it possible to use this and pass in a password that is already an md5 hash?

for example:

$userdm->set('password', "5f0f8c991d3d31c63ab531916c298c65");

Ba$im 06-28-2007 10:45 PM

plz some 1 tell me how do that?

mpage 07-04-2007 01:42 PM

Quote:

Originally Posted by Spandauer (Post 1236547)
Hi everybody,

is it also possible to pass a simple URL to a script, which takes the variables from the URL and registers the new user? The problem is, that i dont have the possibility to send something else... the only thing i can do for my project is sending an URL... will it be possible?

Yuo would just have to pass the variable to the cURL or modified script above via the _GET method . The cURL would then post this to the datamanager, Im just about to set this up myself, so Im no expert.

I will also have to use the modified method above since I cant install curl on my host.

I cant belive this isnt made easyier (for external sign ups)

Quote:

Originally Posted by djdrey (Post 1090273)
You don't have to use CURL to do it, but you have to include globals.php in your script root if you want to create the user from within a function or method.

You also have to remember to retrieve the global vbulletin variable to pass into the datamanager class.

I spent the last few hours working that out, hopefully it'll help someone else!



How can you have globals.php in your script root for a 2nd host/server/url, unless its coppied over, or the registration code is also in the root of forum.

Hmm, Ill look into this!

thbertram 07-05-2007 04:51 PM

This is making driving me batty... With the "save" line commented, no errors are found. When I uncomment it, the data gets saved, BUT the error message line executes as if the entire program reruns itself. The 2 errors generated are duplicate username and duplicate email. Anyone have any ideas?

Code:

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->adminoverride = true;

$userdata->set('username', 'phpNukeUser');
$userdata->set('email', 'foo@bar.com');
$userdata->set('password', 'verysecret');
$userdata->set('usergroupid', 500);
$userdata->set('usertitle','Tourist');

if(count($userdata->errors))
{
        echo "<b>".count($userdata->errors) . " errors </b>";
}
else
{
//        $uid = $userdata->save();
        echo "<br/>User " . $uid . " added.";
}


Searchworm1 07-18-2007 11:03 PM

My God - the curl thing worked. It took me all week to find this post. Thanks.

beejeebers 07-19-2007 04:24 PM

Novastar's script worked beautifully on the first try!

Thanks dude.

:)

mpage 07-23-2007 07:36 PM

anyone having trouble with new users not getting a welcome post via datamanager, no idea how to make sure new users get a welcome post, there must be a way

RonInMaine 07-31-2007 01:55 PM

When I use any variations of the scripts (with cURL and without) in this thread, I get these errors:

Notice: Undefined index: HTTPS in /var/www/html/includes/class_core.php on line 1599
Notice: Undefined index: HTTPS in /var/www/html/includes/class_core.php on line 1599
Notice: Undefined index: HTTP_REFERER in /var/www/html/includes/class_core.php on line 1626

I'm using VB 3.6.7 -- has something changed in this version that might be causing this? Is there another file I need to include to get the environment set up right?

I see where these indices are used in class_core.php, but I haven't (yet) found where they are defined. Still looking ...

Any suggestions would be appreciated.

Thanks,
Ron.

Okay, I'm not thinking straight. Of course, php sets the $_Server superglobal. SO, I guess my job is to find out why the HTTPS and HTTP_REFERER values are not being set.

Thanks,
Ron.

Marco van Herwaarden 07-31-2007 03:28 PM

Add the following to the top of your script:

PHP Code:

error_reporting(E_ALL & ~E_NOTICE); 


RonInMaine 07-31-2007 03:57 PM

Thank you. That worked nicely.

But, now you've got me curious. How did changing the error reporting options fix the problem?

Thanks,
Ron.

psalzmann 08-09-2007 04:02 AM

Brilliant! Thanks Novastar!

blogtorank 08-12-2007 05:40 AM

I've made it possible for you all to start creating members automatically here in this new hack:

https://vborg.vbsupport.ru/showthread.php?t=154637

I branched differently with all full sources of .NET and PHP using what I seen on the forums here with my .NET, and putting it all to work within XML_RPC I hope this helps others out as well.

psalzmann 08-15-2007 01:52 AM

We are using novastar's hack as mentioned above and it's working fine. However, adding users is one thing, updating is another .. which brings me to my next question:

Will this work to actually "update" an existing user, all we're trying to do is update an existing user in the forum to a new usergroup:

PHP Code:

$userdm = new vB_DataManager_User($vbulletinERRTYPE_ARRAY);

$userdm->set('username'$_POST['username']);
$userdm->set('usergroupid'"9");
$userdm->set('displaygroupid'"9");

$forumuserid $userdm->save(); 

But before I execute and implement that code above, I just want to make sure this won't actually "insert/register or create" a user, I would like to just update.

Any clues? is there a $userdm->update(); instead of save? I noticed a pre_save() option and now it's got me a bit curious :)

Thanks in advance!

Okay I did some more reading.. would someone be able to verify the following code:

PHP Code:

$forumuserid 10;

$userdm = new vB_DataManager_User($vbulletinERRTYPE_ARRAY);

$existing = array(
    
'userid' => $forumuserid,
    
'usergroupid' => 9,
    
'usertitle' => 'Licensed Member',
    
'customtitle' => 1
);

$userdm->set_existing(&$existing);

$userdm->save(); 

TIA

blogtorank 08-15-2007 02:22 AM

Quote:

We are using novastar's hack as mentioned above and it's working fine. However, adding users is one thing, updating is another .. which brings me to my next question:

Not off hand I don't think there is anything that can make it update without modifying the code to make it UPDATE, unless you make the set work as an update within a sql statement inside your PHP code....

taras 09-06-2007 01:06 AM

Hey novastar
How do you pass varibles from another DB?
we tryed:
PHP Code:

session_start();
//connections whith DataBase
$str=file("config.php");
$k str_replace("hostName="""$str[0]); $k rtrim($k);
$o str_replace("userName="""$str[1]); $o rtrim($o);
$d str_replace("password="""$str[2]); $d rtrim($d);
$db str_replace("datebase="""$str[3]); $db rtrim($db);
$DB mysql_connect($k,$o,$d);
mysql_select_db($db,$DB);

$id =$_GET['id'];
$active =$_GET['active'];

$checkA =  mysql_query("select active,userName,email,userPass from tusers where userID = ".$id$DB);
$checkA mysql_result($checkA,0,'active');

if(
$checkA == $active)
{
    
$checkA =  mysql_query("UPDATE tusers SET active = '' where userID = ".$id$DB);
    
session_register('userIDD');
    
$_SESSION['userIDD'] = $id;
    
setcookie("userIDD"$id);
    
$username=mysql_result($checkA,0,'userName');
    
$email=mysql_result($checkA,0,'email');
    
$password=mysql_result($checkA,0,'userPass');
    
virtual("file_with_your_code.php");
    
$redirect "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=somefile.php'>\n";
}
else
{
$redirect "";} 

But it's not working...



Quote:

Originally Posted by novastar (Post 1105250)
i use a modified version of the code they gave a couple posts back which works great for me.
Code:

<?php
$username="username";
$email="email@address.com";
$password="password";
$usergroupid="2";
$timezoneoffset="-6";
define('THIS_SCRIPT', 'remote_register.php');
chdir('/home/site/public_html/forum');
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');
$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', $username);
$userdm->set('email', $email);
$userdm->set('password', $password);
$userdm->set('usergroupid',$usergroupid);
$userdm->set('ipaddress', $ipaddress);
$userdm->set('timezoneoffset', $timezoneoffset);
$userdm->set_bitfield('options', 'adminemail', '1');
$userdm->set_bitfield('options', 'showemail', '1');

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
} else {
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
}
chdir('/home/site/public_html/');
?>

I would have taken more time to tinker with it, and possibilly put it in a function, but as there is only 1 place in my scripting but that works fine for me.
Im running it on vBulletin 3.6.2


skattabrain 10-08-2007 01:33 PM

novastar ... added user without trouble, thanks!

any ideas on how to add the custom field data?

amatulic 10-13-2007 03:16 AM

After much testing and examining vBulletin code, I finally finished my PHP class for performing basic operations on user accounts (create user, modify user, delete user, log on, log off). This has enabled me to integrate the forum into my site. Users who log in to my site are logged in to the forum, users who register on my site automatically get an account on the forum, etc.

Once that was done, I just had to modify all the vBulletin templates that contained a login form, logout link, register link, or user account modification link, and make sure those things use MY code for those functions. Now users can log in either from the forum or from my main site, and user account registration and modification are all handled on my main site, outside of the forum. It all works pretty well, without modifying a single line of the vBulletin source code.

Here is the code for class.forumops.php, with extensive usage comments:
PHP Code:

<?php
//==============================================================
// class ForumOps - intended to be used with vBulletin 3.7.2
// by Alex Matulich, June 2008, Unicorn Research Corporation
//
// Setup:
// ------
//
// 1. First, make sure FORUMPATH is defined properly below.
//
// 2. Next, make sure the function userdata_convert correctly converts
// an array of your own user data to an array of vBulletin user data.
// Minimally, you need to convert your data to an array containing
// the keys 'username', 'password', and 'email'.  If your data array
// already contains these keys, simply have userdata_convert return
// the original array, otherwise translate your array to a vBulletin
// array having those keys.
//
// Usage:
// ------
//
// At the top of your php modules where you need to perform vBulletin
// user operations (creation, deletion, updating, login, and logout),
// put these two lines (where MY_PATH is the path to this file):
//
//     require_once(MY_PATH.'/class.forumops.php');
//     $forum = new ForumOps();
//
// Now get your user data array from $_POST or whatever.  Let's call
// this array $userdata.  Here's what you can do:
//
// CREATE AND REGISTER NEW USER:
//
//    $errmsg = $forum->register_newuser($userdata);
//
// UPDATE EXISTING USER DATA:
//
//    $errmsg = $forum->update_user($userdata);
//
// (In this case, $userdata need contain only the username and anything
// else you wish to update, such as password and/or email address.)
//
// $errmsg contains any error messages separated by <br> codes.
// If no errors occured then NULL is returned.
//
// DELETE USER:
//
//    $forum->delete_user($username); // $username = user name
//
// LOGIN USER TO THE FORUM:
//
//    $forum->login(  // requires array to be passed
//       array('username' => $username, 'password' => $pw);
//
// LOG OFF USER FROM THE FORUM:
//
//    $forum->logout();
//
// WARNING: It is common for you to have TABLE_PREFIX defined for
// your own database.  You must call it something else (for example,
// remove the underscore) or it will conflict with the vBulletin
// definition of the same name.
//===============================================================

//===============================================================
// Change this definition and the userdata_convert() function
// to suit your needs:

define('FORUMPATH''/home/my_website_path/forum'); // path to your forum

function userdata_convert(&$userdata// internal function
{
   
// $userdata is our array that contains user data from our own
   // user database, which we must convert to the vBulletin values.
   // Minimally, it must contain the username, email and/or password.

   // required fields
   
$vbuser = array( 'username' => $userdata['userid'] );
   if (isset(
$userdata['email']))
      
$vbuser['email'] = $userdata['email'];
   if (isset(
$userdata['password']))
      
$vbuser['password'] = $userdata['password'];

   
// extra stuff, expand as desired
   
if ($userdata['birthdate'])
      
$vbuser['birthday_search'] = date('Y-m-d'$userdata['birthdate']);
   return 
$vbuser;
}
// end of configuration stuff
//===============================================================

define('REGISTERED_USERGROUP'2); // typical default for registered users
define('PERMANENT_COOKIE'false); // false=session cookies (recommended)

define('THIS_SCRIPT'__FILE__);
$cwd getcwd();
chdir(FORUMPATH);
require_once(
'./includes/init.php'); // includes class_core.php
require_once('./includes/class_dm.php'); // for class_dm_user.php
require_once('./includes/class_dm_user.php'); // for user functions
require_once('./includes/functions.php'); // vbsetcookie etc.
require_once('./includes/functions_login.php'); // process login/logout


//---------------------------------------------------------------------
// This function duplicates the functionality of fetch_userinfo(),
// using the user name instead of numeric ID as the argument.
// See comments in includes/functions.php for documentation.
//---------------------------------------------------------------------
function fetch_userinfo_from_username(&$username$option=0$languageid=0)
{
   global 
$vbulletin;
   
$useridq $vbulletin->db->query_first_slave("SELECT userid FROM "
      
TABLE_PREFIX "user WHERE username='{$username}'");
   if (!
$useridq) return $useridq;
   
$userid $useridq['userid'];
   return 
fetch_userinfo($userid$option$languageid);
}


//---------------------------------------------------------------------
// CLASS ForumOps
//---------------------------------------------------------------------
class ForumOps extends vB_DataManager_User {
   var 
$userdm;

   function 
ForumOps() // constructor
   
{
      global 
$vbulletin;
      
$this->userdm =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
   }


   
//======== USER REGISTRATION / UPDATE / DELETE ========

   
function register_newuser(&$userdata$login true)
   {
      global 
$vbulletin;
      
$vbuser userdata_convert($userdata);
      foreach(
$vbuser as $key => $value)
         
$this->userdm->set($key$value);
      
$this->userdm->set('usergroupid'REGISTERED_USERGROUP);

      
// Bitfields; set to desired defaults.
      // Comment out those you have set as defaults
      // in the vBuleltin admin control panel
      
$this->userdm->set_bitfield('options''adminemail'1);
      
$this->userdm->set_bitfield('options''showsignatures'1);
      
$this->userdm->set_bitfield('options''showavatars'1);
      
$this->userdm->set_bitfield('options''showimages'1);
      
$this->userdm->set_bitfield('options''showemail'0);

      if (
$login$this->login($vbuser);

      
//$this->userdm->errors contains error messages
      
if (empty($this->userdm->errors))
         
$vbulletin->userinfo['userid'] = $this->userdm->save();
      else
         return 
implode('<br>'$this->userdm->errors);
      return 
NULL;
   }


   function 
update_user(&$userdata)
   {
      global 
$vbulletin;
      
$vbuser userdata_convert($userdata);
      if (!(
$existing_user fetch_userinfo_from_username($vbuser['username'])))
         return 
'fetch_userinfo_from_username() failed.';

      
$this->userdm->set_existing($existing_user);
      foreach(
$vbuser as $key => $value)
         
$this->userdm->set($key$value);

      
// reset password cookie in case password changed
      
if (isset($vbuser['password']))
         
vbsetcookie('password',
            
md5($vbulletin->userinfo['password'].COOKIE_SALT),
            
PERMANENT_COOKIEtruetrue);

      if (
count($this->userdm->errors))
         return 
implode('<br>'$this->userdm->errors);
      
$vbulletin->userinfo['userid'] = $this->userdm->save();
      return 
NULL;
   }


   function 
delete_user(&$username)
   {
   
// The vBulletin documentation suggests using userdm->delete()
   // to delete a user, but upon examining the code, this doesn't
   // delete everything associated with the user.  The following
   // is adapted from admincp/user.php instead.
   // NOTE: THIS MAY REQUIRE MAINTENANCE WITH NEW VBULLETIN UPDATES.

      
global $vbulletin;
      
$db = &$vbulletin->db;
      
$userdata $db->query_first_slave("SELECT userid FROM "
         
TABLE_PREFIX "user WHERE username='{$username}'");
      
$userid $userdata['userid'];
      if (
$userid) {

      
// from admincp/user.php 'do prune users (step 1)'

         // delete subscribed forums
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribeforum WHERE userid={$userid}");
         
// delete subscribed threads
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribethread WHERE userid={$userid}");
         
// delete events
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"event WHERE userid={$userid}");
         
// delete event reminders
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"subscribeevent WHERE userid={$userid}");
         
// delete custom avatars
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"customavatar WHERE userid={$userid}");
         
$customavatars $db->query_read("SELECT userid, avatarrevision FROM "
          
TABLE_PREFIX "user WHERE userid={$userid}");
         while (
$customavatar $db->fetch_array($customavatars)) {
            @
unlink($vbulletin->options['avatarpath'] . "/avatar{$customavatar['userid']}_{$customavatar['avatarrevision']}.gif");
         }
         
// delete custom profile pics
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"customprofilepic WHERE userid={$userid}");
         
$customprofilepics $db->query_read(
            
"SELECT userid, profilepicrevision FROM "
            
TABLE_PREFIX "user WHERE userid={$userid}");
         while (
$customprofilepic $db->fetch_array($customprofilepics)) {
            @
unlink($vbulletin->options['profilepicpath'] . "/profilepic$customprofilepic[userid]_$customprofilepic[profilepicrevision].gif");
         }
         
// delete user forum access
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"access WHERE userid={$userid}");
         
// delete moderator
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"moderator WHERE userid={$userid}");
         
// delete private messages
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"pm WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"pmreceipt WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"session WHERE userid={$userid}");
         
// delete user group join requests
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usergrouprequest WHERE userid={$userid}");
         
// delete bans
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"userban WHERE userid={$userid}");
         
// delete user notes
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usernote WHERE userid={$userid}");

      
// from admincp/users.php 'do prune users (step 2)'

         // update deleted user's posts with userid=0
         
$db->query_write("UPDATE " TABLE_PREFIX
            
"thread SET postuserid = 0, postusername = '"
            
$db->escape_string($username)
            . 
"' WHERE postuserid = $userid");
         
$db->query_write("UPDATE " TABLE_PREFIX
            
"post SET userid = 0, username = '"
            
$db->escape_string($username)
            . 
"' WHERE userid = $userid");

         
// finally, delete the user
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"usertextfield WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"userfield WHERE userid={$userid}");
         
$db->query_write("DELETE FROM " TABLE_PREFIX
            
"user WHERE userid={$userid}");
      }
   
/*
      the following is suggested in the documentation but doesn't work:

      $existing_user = fetch_userinfo_from_username($username);
      $this->userdm->set_existing($existing_user);
      return $this->userdm->delete();
   */
   
}


   
// ======== USER LOGIN / LOGOUT ========

   
function login($vbuser)
   {
      global 
$vbulletin;
      
$vbulletin->userinfo fetch_userinfo_from_username($vbuser['username']);

      
// update password expire time to
      // to prevent vBulletin from expiring the password
      
$this->userdm->set_existing($vbulletin->userinfo);
      
$this->userdm->set('passworddate''FROM_UNIXTIME('.TIMENOW.')'false);
      
$this->userdm->save();

      
// set cookies
      
vbsetcookie('userid'$vbulletin->userinfo['userid'],
         
PERMANENT_COOKIEtruetrue);
      
vbsetcookie('password',
         
md5($vbulletin->userinfo['password'].COOKIE_SALT),
         
PERMANENT_COOKIEtruetrue);

      
// create session stuff
      
process_new_login(''1'');
   }


   function 
logout()
   {
      
process_logout(); // unsets all cookies and session data
   
}

// end class ForumOps
chdir($cwd);
?>

As you can see, most of the operations above are pretty simple, except for the user deletion function. Also, to update user account information, see the first post of this thread for options you can use.

The wordwrapping above looks funny, but if you quote this message as if to reply, the wordwrapping will be correct when you copy and paste it.

I hope this helps some people.
-Alex

Lordy 10-14-2007 06:47 PM

When using your code (amatulic), I get
Quote:

Fatal error: Call to a member function query_first() on a non-object in /home/lordy/domains/animefill.com/public_html/project/forum/includes/class_dm_user.php on line 380
I'm passing the variables this way

PHP Code:

    $userdata['userid']=$_POST['uname'];
       
$userdata['password']=$_POST['password'];
           
$userdata['email']=$_POST['email'];
       
$errmsg=$forum->register_newuser($userdata); 

line 380 is
PHP Code:

        else if (htmlspecialchars_uni($username_raw) != $this->existing['username'] AND $user $this->dbobject->query_first(


amatulic 10-15-2007 01:20 AM

Quote:

Originally Posted by Lordy (Post 1359988)
When using your code (amatulic), I get "Fatal error: Call to a member function query_first() on a non-object in /home/lordy/domains/animefill.com/public_html/project/forum/includes/class_dm_user.php on line 380"

Odd. It's working for me. Try this hard-coded example, in the same directory where you have class.forumops.php. You can run it from the commandline:
PHP Code:

<?php
require_once('class.forumops.php');

$userdata = array(
   
'userid' => 'test_user',
   
'password' => 'my_password',
   
'email' => 'test_user@example.com' );

$forum = new ForumOps();
$errmsg $forum->register_newuser($userdata);
if (
$errmsg) echo $errmsg;
else echo 
"User test_user created successfully.<br>\n";
?>

You can go to the admin control panel "Prune / Move Users" and verify the user account 'test_user' got created. I just did a diff of what I posted vs what I have, and the only difference I see is that I am now passing the username by reference to delete_user(). That shouldn't make any difference. I'll update my source in my previous message anyway.
-Alex

Lordy 10-17-2007 07:16 PM

Yup, seems that that does work. Can't seem to figure out how to do.

I tried putting
PHP Code:

require_once('class.forumops.php');
$forum=new ForumOps(); 

in my config file, and just including it. I think i'll probably have to code around that as it seems its setting some issues

I'll have to debug this on my end it seems.

I think I may have figured it out.

thanks =) I'll post back when I have a definite answer.

Lordy 10-18-2007 11:26 PM

Recoded my reg form and it works fine now. Can't seem to work out the login form, so I looked at your login script.

PHP Code:

 // ======== USER LOGIN / LOGOUT ========

   
function login($vbuser)
   {
      global 
$vbulletin;
      
$vbulletin->userinfo fetch_userinfo_from_username($vbuser['username']);
      
// set cookies
      
vbsetcookie('userid'$vbulletin->userinfo['userid'],
         
PERMANENT_COOKIEtruetrue);
      
vbsetcookie('password',
         
md5($vbulletin->userinfo['password'].COOKIE_SALT),
         
PERMANENT_COOKIEtruetrue);
      
// create session stuff
      
process_new_login(''1'');
   } 

which i'm assuming is that? if so, passing as $forum->login($userdata) is not working for me, but looking through your code, I also don't know if that does work.

A58676333470 10-19-2007 11:06 PM

Weee! EXACTLY what im looking for @amatulic ! Works Perfect! Thx!

SolidSlug 11-24-2007 05:32 AM

amatulic,

Your code works great from a PHP page that has no other includes, but as soon as I plugged it into my own CMS, I got the dreaded:

PHP Fatal error: Call to a member function query_first_slave() on a non-object in /var/www/html/papatangopapa.com/forums/includes/functions.php on line 1194

My CMS has its own session management stuff and also uses a custom __autoload function, I wonder if that breaks things in some weird way.

--------------- Added [DATE]1195925781[/DATE] at [TIME]1195925781[/TIME] ---------------

I think it's due to vBulletin's insane reliance on global variables.

When you have:

A.php including init.php and functions.php directly,

there is no problem.

When you have:

a function in B.php including including C.PHP, which includes init.php and functions.php,

you get:

PHP Fatal error: Call to a member function query_first_slave() on a non-object in /var/www/html/papatangopapa.com/forums/includes/functions.php on line 1194

--------------- Added [DATE]1195926210[/DATE] at [TIME]1195926210[/TIME] ---------------

That's also how and why you might end up using cURL in order to keep your application and the namespace polluting vBulletin back-end completely separate.

stoppy 11-25-2007 09:24 PM

Hi!
I'm using 3.6.8 version, I'm trying to add user to vb using my own registration system.

The constructor of the class I have take 2 parameters in input

function vB_DataManager_User(&$registry, $errtype = ERRTYPE_STANDARD)

How I have to use it?

May I include directly this class in my code... it look like not... How can I do?

I proposed another way to solve this problem here: https://vborg.vbsupport.ru/showthrea...27#post1389327

Thanks

Moooooon 12-01-2007 08:55 PM

Would this approach still work in 3.6.8?

Quote:

Originally Posted by GrowersPro (Post 864803)
following code place earlier plus example of code for the curl call in php


STEP I

this file need to to be placed in the forum directory of vbulletin
(make sure it is in this directory to initialise vbulletin stuff ......)


no change done from previous poster


you can include the code below in one php page. call it whatever you want

i call it great_stuff_dude.php

thus i need to MAKE sure that the name of the page is correctly entered
in the define below

define('THIS_SCRIPT', 'GREAT_STUFF_DUDE.php');

do the same in the code below
----------------------------------------------------------------------
<?php
# Add a user to vBulletin (offline)

function qpc_post($varname)
{
return trim(stripslashes((get_magic_quotes_gpc()) ? $_POST[$varname] : addslashes($_POST[$varname])));
}

define('THIS_SCRIPT', 'GREAT_STUFF_DUDE.php');

require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');

$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', qpc_post('username'));
$userdm->set('email', qpc_post('email'));
$userdm->set('password', qpc_post('password'));
$userdm->set('usergroupid',qpc_post('usergroupid'));
$userdm->set('ipaddress', qpc_post('ipaddress'));
$userdm->set('referrerid', qpc_post('referrername'));
$userdm->set('timezoneoffset', qpc_post('timezoneoffset'));
$userdm->set_bitfield('options', 'adminemail', intval(qpc_post('adminemail')));
$userdm->set_bitfield('options', 'showemail', intval(qpc_post('showemail')));

$dst_setting = intval(qpc_post('dst'));
switch ($dst_setting)
{
case 0:
case 1:
$userdm->set_bitfield('options', 'dstonoff', $dst_setting);
break;
case 2:
$userdm->set_bitfield('options', 'dstauto', 1);
break;
}

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
} else {
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
}
?>
-------------------------------------------------------------------


STEP II



You can have the following code on server running PHP WHEREVER YOU WANT. it does not need to be on the same domain as long as you have the curl compiled


in that script (again call it whatever you want it does not matter)

you call the url of your web server and path to go to the page GREAT_STUFF_DUDE.php

you can of course include it in the login code of your CMS to create profiles in both systems in one step.


-------------------------------------------------------------------

<?php

$url="http://www.mysite.com/vbulletin3000/GREAT_STUFF_DUDE.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=keith_mayass&email=keith_mayass@no_worry s.com&password=up_yours&usergroupid=2&");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);

?>
---------------------------------------------------------

you can of course pass as may variables as you want if you have them available in your CMS to complete the profile.

like

parentemail
showbirthday
homepage
icq
aim
yahoo
msn
skype
usertitle
customtitle
birthday



__-----__________------___
Ni vu ni connu, jt' embrouille


makouvlei 12-06-2007 07:59 PM

Quote:

Originally Posted by Altec (Post 975567)
I've managed to automatically add users to vBulletin via our website which is done in ASP. The only issue I'm having is that a user cannot 'SAVE' their signature (strange). Everything else works great...

Anyone have any ideas why?

Thanks.

I am looking to implement a similar system managing vBulletin users from an asp site. I'm very comfortable with asp, but not at all with php -- any pointers as to how to (and how not to) approach this would be much appreciated.

jazeera 12-10-2007 11:39 AM

Quote:

Originally Posted by GrowersPro (Post 864803)
following code place earlier plus example of code for the curl call in php


STEP I

this file need to to be placed in the forum directory of vbulletin
(make sure it is in this directory to initialise vbulletin stuff ......)


no change done from previous poster


you can include the code below in one php page. call it whatever you want

i call it great_stuff_dude.php

thus i need to MAKE sure that the name of the page is correctly entered
in the define below

define('THIS_SCRIPT', 'GREAT_STUFF_DUDE.php');

do the same in the code below
----------------------------------------------------------------------
<?php
# Add a user to vBulletin (offline)

function qpc_post($varname)
{
return trim(stripslashes((get_magic_quotes_gpc()) ? $_POST[$varname] : addslashes($_POST[$varname])));
}

define('THIS_SCRIPT', 'GREAT_STUFF_DUDE.php');

require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_user.php');

$userdm = new vB_DataManager_User($vbulletin, ERRTYPE_ARRAY);

$userdm->set('username', qpc_post('username'));
$userdm->set('email', qpc_post('email'));
$userdm->set('password', qpc_post('password'));
$userdm->set('usergroupid',qpc_post('usergroupid'));
$userdm->set('ipaddress', qpc_post('ipaddress'));
$userdm->set('referrerid', qpc_post('referrername'));
$userdm->set('timezoneoffset', qpc_post('timezoneoffset'));
$userdm->set_bitfield('options', 'adminemail', intval(qpc_post('adminemail')));
$userdm->set_bitfield('options', 'showemail', intval(qpc_post('showemail')));

$dst_setting = intval(qpc_post('dst'));
switch ($dst_setting)
{
case 0:
case 1:
$userdm->set_bitfield('options', 'dstonoff', $dst_setting);
break;
case 2:
$userdm->set_bitfield('options', 'dstauto', 1);
break;
}

#If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
if (count($userdm->errors)) {
for($i=0; $i<count($userdm->errors); $i++) {
print "ERROR{$i}:{$userdm->errors[$i]}\n";
}
} else {
# If everything is OK
$newuserid = $userdm->save();
print "vbuserid:$newuserid\n";
}
?>
-------------------------------------------------------------------


STEP II



You can have the following code on server running PHP WHEREVER YOU WANT. it does not need to be on the same domain as long as you have the curl compiled


in that script (again call it whatever you want it does not matter)

you call the url of your web server and path to go to the page GREAT_STUFF_DUDE.php

you can of course include it in the login code of your CMS to create profiles in both systems in one step.


-------------------------------------------------------------------

<?php

$url="http://www.mysite.com/vbulletin3000/GREAT_STUFF_DUDE.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=keith_mayass&email=keith_mayass@no_worry s.com&password=up_yours&usergroupid=2&");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);

?>
---------------------------------------------------------

you can of course pass as may variables as you want if you have them available in your CMS to complete the profile.

like

parentemail
showbirthday
homepage
icq
aim
yahoo
msn
skype
usertitle
customtitle
birthday



__-----__________------___
Ni vu ni connu, jt' embrouille

This code is work properly
then i need to activate this user when his account on my site activated

--------------- Added [DATE]1197356952[/DATE] at [TIME]1197356952[/TIME] ---------------

Quote:

Originally Posted by Moooooon (Post 1393155)
Would this approach still work in 3.6.8?

it works properly i'm using 3.6.8

TheNewWebGuy 12-18-2007 12:53 PM

Quote:

Originally Posted by amatulic (Post 1358740)
I hope this helps some people.
-Alex

I've been trying to get your code working, but I keep getting the error

Code:

Fatal error: Registry object is not an object in /includes/class_dm.php on line 177
And that's from just having
Code:

require_once ($_SERVER['DOCUMENT_ROOT'] . "/include/class.forumops.php");

$forum = new ForumOps();

I can't see anything that would be amiss so any help would be welcomed

Thanks

--------------- Added [DATE]1197991803[/DATE] at [TIME]1197991803[/TIME] ---------------

Quote:

Originally Posted by TheNewWebGuy (Post 1403576)
Code:

Fatal error: Registry object is not an object in /includes/class_dm.php on line 177

I was able to fix this by doing te following
Code:

require_once ($_SERVER['DOCUMENT_ROOT'] . "/include/class.forumops.php");

$forum = new ForumOps( $vbulletin );

Code:

function __construct( &$vbulletin ) // constructor
  {
      $this->vbulletin =& $vbulletin;
      $this->userdm =& datamanager_init('user', $vbulletin, ERRTYPE_ARRAY);
  }

Stiil though, I'm not sure why I can see $vbulliten outside of the class yet not inside it


All times are GMT. The time now is 06:55 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02940 seconds
  • Memory Usage 2,102KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (11)bbcode_php_printable
  • (13)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (3)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete