phorum_api_user_save()

Posted by sazaraki 
phorum_api_user_save()
July 20, 2008 11:40AM
i've received some strange behaviour from this api function...

if you need background, you can catch up by reading my most recents started threads

so on my main site, i get the user info that phorum_api_user_save() requires
    if ($user) {
// only if login
        $our_user['user_id'] = $user['id'];
        $our_user['username'] = $user['username'];
        $our_user['password'] = $user['userpass'];
        $our_user['email'] = $user['email'];
    } elseif (!$user) {
// anytime other than login
        $our_user['user_id'] = getsession()->m_userInfo['id'];
        $our_user['username'] = getsession()->m_userInfo['username'];
        $our_user['password'] = getsession()->m_userInfo['userpass'];
        $our_user['email'] = getsession()->m_userInfo['email'];
    } else {
        $session->addError("puke");
    }
    $our_user['admin'] = 0;
    $our_user['active'] = 1;

after this i check if the user is an admin on my site and change ['admin'] to 1. then i send it just like that to phorum_api_user_save, look at the variables, then die.

    chdir($phorumdir);
        include_once("common.php");
        $phorum_api_user_save = phorum_api_user_save($our_user, PHORUM_FLAG_RAW_PASSWORD);
    chdir($mydir);
    echo var_dump($phorum_api_user_save)."<hr>";
    echo var_dump($our_user)."<hr>";
    die();

so to setup, i delete the phorum database entry and cookie, and then i delete my cookie and the "copy successful" flag.

with the user logged out, my site gives a generic index with login fields. when a user logs in, here's the output.

int(0)
array(6) { ["user_id"]=>  string(1) "6" ["username"]=>  string(3) "rod" ["password"]=>  string(32) "7ddf32e17a6ac5ce04a8ecbf782ca509" ["email"]=>  string(15) "rod@example.com" ["admin"]=>  int(0) ["active"]=>  int(1) }

int (0) being the result of the api.

here's where it gets XFiles.

the data that i gave it seems to be alright i thought but the api returns a ZERO, meaning failed save. the headscratcher part is in the db there's an actual half save. . . it actually saved the userid and username, and nothing else.

alright... more peculiar behaviour... login to my site a 2nd time (back one page, submit again) heres the output.

int(6)
array(6) { ["user_id"]=>  string(1) "6" ["username"]=>  string(3) "rod" ["password"]=>  string(32) "7ddf32e17a6ac5ce04a8ecbf782ca509" ["email"]=>  string(15) "rod@example.com" ["admin"]=>  int(0) ["active"]=>  int(1) }

in looking at the db, this time it completed the write. it even took the time to set other profile friendly fields like pm_email_notify=1 and others.

primary question: this isn't intended behaviour is it? I mean 1 write is supposed to be all it needs right?

2ndary question, meaning the above is more important than this one, if all i send is username and id, will it puke on credentials at some point in the future without password even tho phorum auth is bypassed completely?
Re: phorum_api_user_save()
July 20, 2008 01:04PM
In your phorum user table is the user_id field autoincrement?
Re: phorum_api_user_save()
July 20, 2008 01:08PM
Last question first: no puking involved. It's okay to leave the passwords out. Only for the admin, you need to set the password (unless you have the authentication for that inherited by the other code too, I don't do that myself).

First question: I ran this test script on my 5.2 system:

<?php

define('phorum_page','test');

include_once("./common.php");

$user = array(
    'user_id'  => '666',
    'username' => 'rod',
    'password' => '7ddf32e17a6ac5ce04a8ecbf782ca509',
    'email'    => 'rod@example.com',
    'admin'    => 0,
    'active'   => 1
);

$ret = phorum_api_user_save($user, PHORUM_FLAG_RAW_PASSWORD);

var_dump($ret);

?>

The output for this script was:

int(666)

That is exactly what I expected. A return value of zero is not expected.

Can you try this basic script on your system too? (with the data a bit updated to prevent duplicate users).


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: phorum_api_user_save()
July 20, 2008 01:17PM
Quote
DavidVB
In your phorum user table is the user_id field autoincrement?

it was before when i was having this. and it was suggested to turn it off as a "well try that and see what happens" kinda thing
Re: phorum_api_user_save()
July 20, 2008 01:21PM
The api does a two step process, first saving the user_id and name. It uses a php call to determine the user_id that was inserted, then puts in the rest of the data. This call doesn't work if the field is not autoincremented. Turn it back on and the data insert should work.
Re: phorum_api_user_save()
July 20, 2008 01:22PM
Who told you to turn auto_increment off? Did we?


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce



Edited 1 time(s). Last edit at 07/20/2008 01:26PM by Maurice Makaay.
Re: phorum_api_user_save()
July 20, 2008 01:49PM
i'm working on it now it's gonna take a bit cuz i have some funky rewrites n crap going on, so it'll take a bit of setup.

meantime, wht's the define for?
Re: phorum_api_user_save()
July 20, 2008 01:52PM
Quote
Maurice Makaay
Who told you to turn auto_increment off? Did we?

No. i was having. . . odd . . . issues previously, and it was acting similarly. since we're not using phorum to build users, it was suggested as a shrugging stab at fixing it.

Quote
DavidVB
The api does a two step process, first saving the user_id and name. It uses a php call to determine the user_id that was inserted, then puts in the rest of the data. This call doesn't work if the field is not autoincremented. Turn it back on and the data insert should work.

i did that, and there it went. thanks for your help!
Re: phorum_api_user_save()
July 20, 2008 02:07PM
Quote
sazaraki
meantime, wht's the define for?

It's just to keep some warnings from happening, because in common.php the value of this define is checked at several places. Each Phorum script is expected to have a define for "phorum_page" set. The exact value does not exactly matter. As long as you don't use any of the default phorum_page defines it is okay.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: phorum_api_user_save()
July 22, 2008 12:37AM
how many queries does this run? sounds like 2 fairly simple ones.

user auth is 2 step: guy logsin to the main site, their info is copied to phorum using api_user_save. when they go to the forum, user_session_restore creates credentials based on the mainsite auth.

i activated the copy function, but didn't open the forum for use so the only use it was getting was api_user_save. on my db, queries per second jumped from ~300 to >900 average . . . and it was only getting ~100 copies/minute after a while. on top of that, i couldn't see what queries were causing all that (mtop wouldn't show)



Edited 1 time(s). Last edit at 07/22/2008 12:38AM by sazaraki.
Sorry, only registered users may post in this forum.

Click here to login