[DEV][Function] insert_user()

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Locked
Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

[DEV][Function] insert_user()

Post by Graham » Mon Mar 01, 2004 1:01 pm

(I pondered whether to post this here or in Beta Dev since it's not a MOD in it's own right, and couldn't make my mind up, so MOD Team move it if you think it's better over there)

Given the amount of times I find myself using similar code to carry out user registrations in my convertor scripts and MODs, I've decided that it is worse abstracting this code. However, given the number of requests I see from people looking to carry out registration from pages on their website, I thought it worth getting opinions from other MOD Authors on what they think is required in a tool like this.

My initial thoughts are to implement this as an object, rather than a function to allow more extendability of the code.
The object will have:
  • A creator method which will take the 3 pieces of essential data - username, password and email address
  • A method to set any of the other user fields
  • Specific methods to set some of the fields (eg signature) which will carry out any special processing on them
  • A method to add the user to specified usergroups when it is inserted
  • A method to actually insert the user into the database
I'm interested in thoughts on the above and any additional requirements that other MOD Authors may have on this to make it a tool useful to others as well, so please post anything that you can think of below.

-----

I have now produced an initial version of this code which is available for download and look forward to any comments.

MOD DB thread

[Edited 20061014 - changed download links to point to MOD DB]
Last edited by Graham on Sat Oct 14, 2006 3:30 pm, edited 3 times in total.
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

User avatar
netclectic
Former Team Member
Posts: 4439
Joined: Wed Mar 13, 2002 3:08 pm
Location: Omnipresent
Contact:

Post by netclectic » Mon Mar 01, 2004 1:30 pm

Sounds good.

If you're going to implement it as a class, then i would recommend providing a wrapper function or two cos guarenteed there'll be a few folks who'd want to use it but don't have the first clue about instantiating objects.

A few more of these "helper functions" and we'll have a nice little API :)
Defend the game:
Image

User avatar
morpheus2matrix
Former Team Member
Posts: 9171
Joined: Wed Apr 10, 2002 7:31 pm
Location: France
Contact:

Post by morpheus2matrix » Mon Mar 01, 2004 4:00 pm

Great !

Good luck :wink:
Former phpBB MOD-Team Member -

Forgive my bad English :(

No support by PM/Email - Thanks - You can thanks me here :) - Pay me for installing MOD's :lol:

Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham » Mon Mar 08, 2004 12:45 pm

[Removed old links - 20061014]
Last edited by Graham on Sat Oct 14, 2006 3:31 pm, edited 1 time in total.
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham » Mon Mar 22, 2004 1:16 pm

Anyone who is using this, I've updated the code (and the download link above) to address a problem where the USER_GROUP_TABLE was not being properly populated.
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

User avatar
netclectic
Former Team Member
Posts: 4439
Joined: Wed Mar 13, 2002 3:08 pm
Location: Omnipresent
Contact:

Post by netclectic » Tue Apr 06, 2004 10:18 am

It's a good idea to keep the first post updated with info about the latest version. Make it easier to find :)
Defend the game:
Image

Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham » Tue Apr 06, 2004 11:32 am

Done. I'll update it fully once I've written the API Documentation. :)
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

edslaw
Registered User
Posts: 3
Joined: Thu Jun 10, 2004 1:16 pm

Post by edslaw » Thu Jun 10, 2004 9:13 pm

Graham,

Sorry to revive an old thread but I have been looking through the web to try and find out a way to intergrate our user database with that of our forums(phpBB).i.e. when a user registers with our website we want to be able to run a script similar to this script that will create the user's account in phpbb tables.

Is there a way to call this script in the backround, without having to load the phpbb pages?

confoosious
Registered User
Posts: 20
Joined: Sat Jun 05, 2004 8:31 pm

bump

Post by confoosious » Thu Jun 10, 2004 11:54 pm

Definitely something that I'm looking for as well. Currently, I have a signup process on my site and my users need to sign up twice.

edslaw
Registered User
Posts: 3
Joined: Thu Jun 10, 2004 1:16 pm

Post by edslaw » Fri Jun 11, 2004 7:07 am

After another look at the php file I wanted to ask if the following changes would allow me to call this function from any of my pages?

replace all instances of:

db->sql_query() with mysql_query()
(creating your own link identifier before hand)

all defined variables indentifing the Mysql tables's .i.e. USERS_TABLE, USERS_GROUPS etc with the actual table names?

Any input would be greatly appreciated. Thanks

edslaw
Registered User
Posts: 3
Joined: Thu Jun 10, 2004 1:16 pm

Post by edslaw » Fri Jun 11, 2004 7:14 am

After another look at the php file I wanted to ask if the following changes would allow me to call this function from any of my pages?

replace all instances of:

db->sql_query() with mysql_query()
(creating your own link identifier before hand)

all defined variables indentifing the Mysql tables's .i.e. USERS_TABLE, USERS_GROUPS etc with the actual table names?

Any input would be greatly appreciated. Thanks

Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham » Mon Jun 14, 2004 11:10 am

Yes that should work in principle (although I haven't tried it).

However, you will need to have defined $phpbb_root_path in the script which includes this file as well to allow this to include the necessary functions from the phpBB includes folder.
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

chilling
Registered User
Posts: 336
Joined: Tue Jul 06, 2004 11:59 am
Location: Winchester, England
Contact:

Post by chilling » Wed Jul 28, 2004 10:49 am

Really useful bit of code for a phpbb newbie - thanks...

Question ... how would you change "insert_user" function so that the true return value is the new userID rather than 1 (True)?
(ie the $result value is blank or 0 for false and the new userID for true)
Christopher Hilling
SpaDental Management llp
http://www.spadental.co.uk

Graham
Former Team Member
Posts: 8462
Joined: Tue Mar 19, 2002 7:11 pm
Location: UK
Contact:

Post by Graham » Wed Jul 28, 2004 11:08 am

The simple way to get that value is to call $user->get_user_id() which is the method created to give you the user_id value ;)

However for what you want, find this

Code: Select all

		return ($error == true) ? false : true;
and replace the true at the end with $this->user_id

On a related note, I've just spotted what looks to be a bug :roll:
There are a couple of references to $this->$user_id which should actually be changed to read $this->user_id in the code.
"So Long, and Thanks for All the Fish"

phpBB Useful Links: Knowledge Base | Userguide | Forum Search | MOD Database | Styles Database
My Links: Blog!

chilling
Registered User
Posts: 336
Joined: Tue Jul 06, 2004 11:59 am
Location: Winchester, England
Contact:

Post by chilling » Wed Jul 28, 2004 11:22 am

Thanks - that did the trick ... :)

I have also changed all the $this->$user_id to $this->user_id although it was not giving an error. :?
Christopher Hilling
SpaDental Management llp
http://www.spadental.co.uk

Locked

Return to “[2.0.x] MOD Writers Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests

cron