View Full Version : hook for password / email update
zero-two
03-12-2011, 08:59 AM
Hi everyone.
I want an external db to be syncronized with the vb forum one.
i already managed to have the registration hook working so that every new user confirmed is actually backupped in my other db.
Now i want to keep this data syncronizedm especially the password and the salt fields.
i hooked an update script to profile_updatepassword_complete and the script is correctly called. but
$userinfo['username'], $userinfo['userid']
are empty! where i can find the info i just updated so i can keep them syncronized?
thanks for your help!
Lynne
03-12-2011, 04:55 PM
Go look at the hook. It's in profile.php. If you look it up, you will see what the correct variable names are for what you want.
zero-two
03-12-2011, 06:01 PM
i'm new to vbulletin and the hook system, hope i'm not doing mess :P.
i'm not sure but may be perhaps $userdata?
if i use that i get
Fatal error: Cannot use object of type vB_DataManager_User as array in /var/www/forum/hook.php on line 32
where hook.php is the script that sent the data to the other mysql db.
on that line i just say $udata[u_id]=$userinfo['userid']; where userinfo is just the passed array that contains userdata and udata is the new array wich need to be written.
perhaps this is a problem related in used reserved names like userdata , userinfo?
thanks for your assistance, much appreciated :)
Lynne
03-12-2011, 06:04 PM
Did you look up the file I asked you to and find the hook? Right above it, they define $username and $userid. Please look in the code and you will see what I mean.
zero-two
03-13-2011, 08:51 AM
i had a look at profile.php.
but
$username is empty
$password is empty.
$userid is empty
$userinfo have other stuff into it.
$userdata is empty
i can't fetch any data at all...i can't know what user is performing the email/password update!
---------------MY SOLUTION
Thanks for your help,i still need to learn Vbulletin, is an amazing software.
i found a more elegant solution for my problem to sync data between those two db.
I post it here for everyone that need the same backup system...
this may not be fit for everyone,but in my case i wanted the website to be autonomous from the server, so i need data redundancy and i need to save on a secondary db login access plus more data related to the website. this way i still can use all website custom functions (such as login, commenting email profiling etc) while , for example, forum is under mainteinance, shut down, defaced, or even absent al all.
This allows also to change the board in the future still being able to have data saved virtually everywhere.
Also a quick and dirty backup of access data table only can be done much faster and stored or sent via rsync on the backup server much more frequently since it's smaller than the Vb user table.
for creating a user:
hook a function in "register_activate_process" then fetch user data and insert custom fields OR use an insert trigger.
(the hook is better since it will create the data once the user is verified, ence able to login effectlively from website or forum)
to keep data syncronized just go to your phpmyadmin panel or similar, and drop the SQL code while your forum DB is selected:
CREATE TRIGGER update_trigger AFTER UPDATE ON forum.t_user
FOR EACH ROW
UPDATE db_site.t_users SET u_username = NEW.username , u_password = NEW.password , u_salt = NEW.salt WHERE u_id = NEW.userid;
and the following to auto delete deleted users
CREATE TRIGGER delete BEFORE DELETE ON forum.t_user
FOR EACH ROW
DELETE from db_site.t_users WHERE u_id = OLD.userid;
to show active triggers just do a SHOW TRIGGERS.
if you want to remove a trigger just do a DROP TRIGGER triggername
Obviusly in the update trigger you will also need to specify if the user is active,so he can eventually login or not.
you may perhaps do more stuff, like sync across multiple websites.
CREATE TRIGGER update_trigger AFTER UPDATE ON forum.t_user
FOR EACH ROW
UPDATE db_site.t_users SET u_username = NEW.username , u_password = NEW.password , u_salt = NEW.salt WHERE u_id = NEW.userid;
UPDATE db_site1.t_users SET u_username = NEW.username , u_password = NEW.password , u_salt = NEW.salt WHERE u_id = NEW.userid;
UPDATE db_site2.t_users SET u_username = NEW.username , u_password = NEW.password , u_salt = NEW.salt WHERE u_id = NEW.userid;
Very important: In my case, since i did not needed data to be manipulated, this is, imho, the best option.
if you need data manipulation you will still need to use the hooks.
For example i did not used the insert trigger because i wanted to process user data.
hope it helps.
Cya
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.