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)

Andreas 06-09-2005 10:00 PM

Add new Users (automatically)
 
As this is a common request for integration purposes, I thought I should write up another HowTo :)

If you want to add a new user to the vBulletin database, you can use Class vB_Datamanager_User.
This Calss does make sure that everything is OK, it will also take care of the default registration options.

Example
PHP Code:

$newuser =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
$newuser->set('username''phpNukeUser');
$newuser->set('email''foo@bar.com');
$newuser->set('password''verysecret');
$newuser->set('usergroupid'2); 

If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
PHP Code:

$newuser->errors 

This is an array containing the errors.

If everything is OK
PHP Code:

$newuserid $newuser->save(); 

This will create a new User called phpNukeNuser (UserID returned in $newuserid).

You can also set many other info too:
  • membergroupids = comma-separated string of all additional usergroups (Default=Empty)
  • displaygroupid = ID of the usergroup this user should show up as (Default=0)
    Note that this must be set after usergroupid and membergroupids!
  • styleid = ID of the Style to be used by this user (Default=Board Default)
  • languageid = ID of the language to be used by this user (Default=Board Default)
  • threadedmode = Whether to use Flat (0), Hybrid (1) or Threaded (2) Display Mode
  • maxposts = Integer, how many posts should be shown on one Page (Default=Board Default)
  • ipaddress = String, IP-Adress of the User registering (Default=Empty)
  • refererid = String, Username or UserID of the User this user was refered by
  • parentemail = String. eMail-Address of the users Parents
  • daysprune = Integer, show threads from the last X days
  • startofweek = Integer, When does the week start (1=Sunday, 2=;onday, ...) (Default=Board Default)
  • timezoneoffset = Integer, spexifying the Timezone (-12 .. +12)
  • autosubscribe = Integer, defining default mode for Thread subscription
    -1 = no Subscription, 1 = Instant, 2 = Daily Digest, 3 = Weekly Digest
    (Default=Board Default)
  • homepage = String, URL of the users Homepage (Default=Empty)
  • icq = String, the Users ICQ # (Default=Empty)
  • aim = String, the Users AIM ID (Default=Empty)
  • yahoo = String, the Users Yahoo ID (Default=Empty)
  • MSN = String, the Users MSN ID (Default=Empty)
  • usertitle = String, the Usertitle this user should have
  • customtitle = Integer, defining behaviour of Usertitle. 0=No Custom Title, 1=Custom, Title with HTML, 2=Custom Title without HTML (Default=
  • birthday = array(month, day, year). The users birthdate.
  • avatarid = Integer, ID of the Avatar being used for this user
  • signature = String. The Users Signature
  • subfolders = Array. The Users Subscription Folders
  • pmfolders = Array. The Users Subscription Folders
  • buddylist = String. Space separated List of UserIDs defining the Users buddylist
  • ignorelist = String. Space separated List of UserIDs defining the Users ignorelist

Besides that, you can also set the options Bitfield (Receive Admin PMs, etc.)
PHP Code:

$userdata->set_bitfield('options''optionname''value'); 

The available Options are
  • showsignatures = Show Signatures
  • showavatars = Show Avatars
  • showimages = Show Images, incl. attached Images and [img] BBCode
    If this is not set they will show up as links
  • coppauser = User is COPPA User
  • adminemail = Receive Admin eMails
  • showvcard = Allow vCard Download
  • dstauto = Automatically detect DST setting
  • dstonoff = DST turned On
  • showemail = Receive eMails from other Users
  • invisible = Be invisible
  • showreputation = Show Reputation
  • receivepm = PM turned on
  • emailonpm = eMail notification for new PMs

Value must be 0 or 1 (false or true), depending if you want to set the option or not.
If the Options are not set, the Default Registration Options/Board Default Options will be used.

Important Notice
It is assumed that you are using this code from 'within' vBulletin, eg with the vBulletin backend loaded.
If this is not the case, you must include smth. like the following code in global context:
PHP Code:

define('VB_AREA''External');
define('SKIP_SESSIONCREATE'1);
define('SKIP_USERINFO'1);
define('CWD''/path/to/vbulletin');
require_once(
CWD '/includes/init.php'); 

Keep in mind that if you are using the a/m Datamanager-Code within a function or method you must global $vbulletin.

This How-To is (C) 2005 by KirbyDE and you are not allowed to redistribute it in any way without my explicit consent.

MrNase 06-10-2005 02:30 PM

What does $newuser->errors look like? Is it an array() so that we have to use foreach ( ... AS ...) { } to display them?

Andreas 06-10-2005 02:34 PM

Example (Username already taken):

Code:

Array
(
    [0] => That username is already in use. If you are phpNukeuser and you have forgott click <a href="login.php?do=lostpw">here</a>
)


Revan 06-10-2005 03:24 PM

Good, thanks for clarifying the array. I wrote my own error handler for the events I needed to output any errors, and it was a simple foreach that went like this:
PHP Code:

foreach ($pmdm->errors as $errors)
{
    
$error .= "<li>$errors</li>";


The $error was then echoed out in the print_standard_error.

Btw while Im at it, if we need to for instance add 2 users with different values, or send 2 pms, do we need to put the
PHP Code:

 $newuser =& datamanager_init('User'$vbulletinERRTYPE_ARRAY); 

line every time? Also do the variable names have to be different for those 2 instances?

TIA :)

Marco van Herwaarden 06-10-2005 03:54 PM

Quote:

Originally Posted by MrNase
What does $newuser->errors look like? Is it an array() so that we have to use foreach ( ... AS ...) { } to display them?

Please read the stickied post in the top of this forum.

kall 06-15-2005 03:20 AM

Quote:

Originally Posted by MarcoH64
Please read the stickied post in the top of this forum.

So...we aren't allowed to ask questions in these How-to threads, is that what you are referring to the sticky thread for?

Seems a bit strange to me...surely that thread is meaning 'Don't Start question threads'.

N8 06-15-2005 03:59 AM

I don't see the point in this, why not just create a new user via the admin cp?

Andreas 06-15-2005 04:03 AM

Quote:

Originally Posted by N8_115
I don't see the point in this, why not just create a new user via the admin cp?

Quote:

Originally Posted by KirbyDE
As this is a common request for integration purposes,

Does this answer your question? :)

dwh 06-29-2005 10:37 PM

What if you want to create a new user, assign him

$newuser->set('usergroupid', 10);



but you'd like his email verified first through the usual system and once he gets verified then he's placed in 10?

EDIT: I keep clicking on the black font color, in this screen the above text turns black. I hit enter, it reverts to green?

Andreas 06-29-2005 10:42 PM

You would have t hook into register_activate_process and change the Usergroupid there.

Anyway, the described method does not generate an activation ID and such.
If you are interested in this I can write up some description.


All times are GMT. The time now is 08:32 AM.

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

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01225 seconds
  • Memory Usage 1,768KB
  • 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
  • (1)bbcode_code_printable
  • (7)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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