1
xoopdio
user insertion
  • 2011/11/1 9:35

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


Hi

I try to insert a new user from mysql with the following line :

$sql 'INSERT INTO ' $table ' (name, uname, pass, email, url, user_avatar, user_regdate, user_icq, actkey, user_aim, user_yim, user_msnm, theme, umode, bio) VALUES ('NAME', 'UNAME', 'PASS', 'EMAIL', 'URL', $user_avatar, $date, 'USER_ICQ', $actkey, 'USER_AIM', 'USER_YIM', 'USER_MSNM', $theme, $umode, '');';


It does work (all variables are defined and match the variables of another user who doesn't have any trouble because defined with the XOOPS interface), but this sql defined user still can't access his mail box or even disconnect ???

Do you know why ?

Thank you.
"A tree is made of non-tree elements" Thich Nhat Hanh

2
iHackCode
Re: user insertion

the user also needs to be added to a group.

you should use the memberhandler to create a new user though.
ex: the register.php file. http://dev.xoofoo.org/xoopsphpxref/20182/nav.html?register.php.source.html#l166
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

3
xoopdio
Re: user insertion
  • 2011/11/2 5:33

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


Hi

Thanks for your help. ;)

I had a look at the given link but I don't understand how to use that class :

- the createuser() function doesn't take any argument so what user could it create ?
- the insertUser() function takes 2 arguments : 1 $force ?? and the $user which I didn't find how it should be defined (or where)
...

Do you know if there is a tutorial anywhere on how to use this class to insert a new user ? I searched the documentations in vain for the moment..

Or maybe a little help on the procedure ?

I already implemented the insertion of new PHPBB3 users in the XOOPS database, but that was easy : PHPBB3 has a add_user() function with a defined array argument. But here, I boil my few last neurons on the XOOPS procedure..

Thank you.
"A tree is made of non-tree elements" Thich Nhat Hanh

4
JCash
Re: user insertion
  • 2011/11/2 5:53

  • JCash

  • Just popping in

  • Posts: 66

  • Since: 2011/2/22



5
xoopdio
Re: user insertion
  • 2011/11/2 6:14

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


Ok I reply to myself..

I found those bits of code here and here. So I came with that line of code :

include ('../../../mainfile.php');
include_once 
XOOPS_ROOT_PATH '/kernel/user.php';
include_once 
XOOPS_ROOT_PATH '/kernel/object.php';
$member_handler =& xoops_gethandler('member');
$user =& $member_handler->createUser();
$user->setVar('uname'$name);
$user->setVar('pass'md5('password'));
if (
$member_handler->insertUser($user))
{
    
$sql 'SELECT uid FROM ' $table ' WHERE uname = '' . $USER_INFOS['UNAME'] . '';';
            
$result $this->xoopsDB->queryF($sql);
            
            while(
$row $this->xoopsDB->fetchRow($result))
            {
                foreach(
$row as $value)
                {
                    
$UID = (int)$value;
                }
            }
        
$XoopsMemberShip =& $member_handler->addUserToGroup(2$UID);         
}else
{
        
$errors_array $user->getErrors();
}


Does the job.. Its all I ask.. :)

JCash -> thanks but I gonna stick with the memberhandler, it seems to be the right way to do. ;)
"A tree is made of non-tree elements" Thich Nhat Hanh

6
iHackCode
Re: user insertion

something like this. i didnt test it though

$member_handler =& xoops_gethandler('member');
//User Object. our new user that we want to insert to xoops
$newuser =& $member_handler->createUser();

//Set some variables
$newuser->setVar('user_viewemail'$user_viewemailtrue);
$newuser->setVar('uname'$unametrue);                 //username
$newuser->setVar('email'$emailtrue);                 //email address
if ($url != '') {
   
$newuser->setVar('url'formatURL($url), true);       //url
}

$newuser->setVar('user_avatar''blank.gif'true);      //avatar

$newuser->setVar('pass'md5($pass), true);              //password

$newuser->setVar('timezone_offset'$timezone_offsettrue);   //timezone offset ex: -8
$newuser->setVar('user_regdate'time(), true);
$newuser->setVar('uorder'$xoopsConfig['com_order'], true);
$newuser->setVar('umode'$xoopsConfig['com_mode'], true);

// 1 is yes, 0 is no. (Receive occasional email notices...option)
$newuser->setVar('user_mailok'$user_mailoktrue);

//0 is for the user to activate
//1 is for automatic activation
//2 is for admin activation.
//but 0 and 2 need more code for it to work
$newuser->setVar('level'1true);

//Insert the user
if (!$member_handler->insertUser($newuser)) {
   echo 
_US_REGISTERNG//an error message if we cannot add the user.
   
exit();
}

$newid $newuser->getVar('uid');
//add our new user to the Users group, which is actually the number 2
if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS$newid)) {
   echo 
_US_REGISTERNG//a message to show that the user was registered succesfully
   
exit();
}


i believe you can also pass an array for the fields and an array for the values in that setVar( method . but i havent tried that before.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

7
xoopdio
Re: user insertion
  • 2011/11/3 7:27

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


Thanks a lot for the piece of code !

I tested the admin autentification code but as you said it seems to need more coding, as XOOPS doesn't seem to see it as it should. Another hole that I'll have to dig up..

But I got a working code looking as it should !

Thanks again !

PS : So the first part is done : if anyone have time, you are welcomed to install and test !

The module is intended to synchronize users between XOOPS and PHPBB3, you can find it here, at BadDev's Place..

Thank you !
"A tree is made of non-tree elements" Thich Nhat Hanh

8
iHackCode
Re: user insertion

Quote:

xoopdio wrote:

I tested the admin autentification code but as you said it seems to need more coding, as XOOPS doesn't seem to see it as it should.


i didn't include it, but its in the register.php file.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

9
xoopdio
Re: user insertion
  • 2011/11/4 9:47

  • xoopdio

  • Just popping in

  • Posts: 29

  • Since: 2011/9/27


It's strange : I added the code (line 176-194) which as I understand it, is supposed to send the mail to the admin to request the activation of the user. But the user is still automatically registered, even with the level set to 2 in the database ??

I thought it should be sufficient condition for the user to have admin registration always enabled but no.. Do you know what could happen ? Or I miss (again.. ) something ?

Actually I mix up activation_type and level data, the first one seems to set the admin registration but the second, I don't see how it operates ?
"A tree is made of non-tree elements" Thich Nhat Hanh

10
iHackCode
Re: user insertion

Quote:

xoopdio wrote:
Actually I mix up activation_type and level data, the first one seems to set the admin registration but the second, I don't see how it operates ?


i should have put comments under the different activation_type's and here is a link to the 2.5's file, it looks easier to read.
http://dev.xoofoo.org/xoopsphpxref/251/nav.html?register.php.source.html#l134

and for the level attribute; level 1 is for people who are activated and level 0 is for those who are not. So everyone should be either a 0 or 1. Sometimes there are some greater than one, but the important thing is that they are greater than 0.

Some Extra info:
the 'groups' table controls the permissions. the permissions are set in the 'group_permission' table and the 'groups_users_link' stores who is in what groups.
CBB / LatestNews / Publisher / XM-Spotlight

(ノ◕ヮ◕)ノ*:・゚✧

Login

Who's Online

292 user(s) are online (99 user(s) are browsing Support Forums)


Members: 0


Guests: 292


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Dec 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits