Integrated user creation
Posted by shillier
Integrated user creation June 06, 2013 07:55PM |
Registered: 13 years ago Posts: 3 |
I have been developing a system where the visitor is required to log on to use the functionality.
In this system I am using the email address as the user name.
I wanted to add a forum and while creating a user for my system it would make sense to create a user in phorum using the same credentials.
After help from Maurice who pointed me in the direction of a post by KWood I achieved this.
Now because I wanted to do this creation silently and come back to my own code I made a few tweaks.
Here they are if anyone can make use of them.
In my signup routine I have the following code
Now I know what language the user is working on at this stage so I might as well pass this across to phorum so I can put language support in the forum so after my code I placed the following
That gets me onto the page I have created to create the user. Note I am passing user credentials across to this routine in an encoded query string.
Once in this routine I check and decode and explode the query string. I now pick up the exploded values and feed them into the api call.
When I wrapped up the query string I included the user id from my own code to use as the phorum user ID - just seemed to make sense.
I also included in the string some data I need when I get control back in my own code. This is passed back in the return header relocation as PASSTHRU_LICENCE_PERIOD. On the return journey there is nothing sensitive in the so I did not encode it.
If anyone finds this code snippet useful then I am glad to have helped.
Many thanks to the guys at Phorum for making this such an easy transition.
In this system I am using the email address as the user name.
I wanted to add a forum and while creating a user for my system it would make sense to create a user in phorum using the same credentials.
After help from Maurice who pointed me in the direction of a post by KWood I achieved this.
Now because I wanted to do this creation silently and come back to my own code I made a few tweaks.
Here they are if anyone can make use of them.
In my signup routine I have the following code
Language: PHPif ( ($userid = $user->get_user_id( $_POST[';email1';] )) == USER_ERROR_USERNOTEXIST ) { $sysparms = new run_class(); $user_details[USER_FIRST_NAME] = $_POST[';fname';]; $user_details[USER_LAST_NAME] = $_POST[';lname';]; $user_details[USER_USERNAME] = $_POST[';email1';]; $user_details[USER_PASSWORD] = $_POST[';pw1';]; $user_details[USER_AUTHORITY] = USER_NOT_PAID; $user_details[USER_DB_PREFIX] = ($sysparms->increment_user_prefix() . ';_';); $user_details[USER_LANGUAGE] = $_POST[';language';]; $user_details[USER_LAST_RUNNO] = USER_DEFAULT_RUN_NUMBER; $user_details[USER_LOGON_STATUS] = USER_LOGGED_OFF; $user_details[USER_CREATE_DATE] = strftime( "%Y-%m-%d", mktime( 0, 0, 0, date( "m" ), date( "d" ), date( "Y" ) ) ); $user_details[USER_RENEWAL_DATE] = strftime( "%Y-%m-%d", mktime( 0, 0, 0, (date( "m" )+$licence_period), date( "d" ), date( "Y" ) ) ); $user_details[USER_LAST_LOGON] = strftime( "%Y-%m-%d %H:%M:%S", mktime() ); $new_user_id = $user->create_new_user( $user_details ); mkdir( "userfiles/" . $user->get_user_db_prefix( $new_user_id ), 0755 );
Now I know what language the user is working on at this stage so I might as well pass this across to phorum so I can put language support in the forum so after my code I placed the following
Language: PHPforeach( $language_code as $key => $value ) { if ( $key == $user_details[USER_LANGUAGE] ) { $phorum_language_file = $value; break; } } $raw_query = sprintf( "%d][%s][%s %s][%s][%s][%s][%d", $new_user_id, $user_details[USER_USERNAME], $user_details[USER_FIRST_NAME], $user_details[USER_LAST_NAME], $user_details[USER_PASSWORD], $user_details[USER_USERNAME], $phorum_language_file, $licence_period ); $encoded_query = base64_encode(base64_encode($raw_query)); header( "Location: phorum/cuser.php?idh=" . $encoded_query );
That gets me onto the page I have created to create the user. Note I am passing user credentials across to this routine in an encoded query string.
Once in this routine I check and decode and explode the query string. I now pick up the exploded values and feed them into the api call.
Language: PHPif ( !isset($_REQUEST[';idh';]) || empty($_REQUEST[';idh';]) ) { exit(); } $idh = $_REQUEST[';idh';]; $raw_details = base64_decode( base64_decode( $idh ) ); $user_details = explode( "][", $raw_details ); define( ';phorum_page';, ';create_user'; ); global $PHORUM; include_once( ';common.php'; ); $current_working_directory = getcwd(); chdir( "../phorum" ); phorum_api_user_save( array( "user_id" => $user_details[PHORUM_USER_ID], // or the user id from your main user database "username" => $user_details[PHORUM_USER_NAME], "real_name" => $user_details[PHORUM_REAL_NAME], "display_name" => $user_details[PHORUM_REAL_NAME], "password" => $user_details[PHORUM_PASSWORD], "password_temp" => $user_details[PHORUM_PASSWORD], "active" => PHORUM_USER_ACTIVE, "admin" => FALSE, "hide_email"=> FALSE, "email" => $user_details[PHORUM_EMAIL], "user_language" => $user_details[PHORUM_LANGUAGE] ) ); chdir( $current_working_directory ); header( "Location: /signup.php?ur=" . $user_details[PHORUM_USER_ID] . "&lp=" . $user_details[PASSTHRU_LICENCE_PERIOD] );
When I wrapped up the query string I included the user id from my own code to use as the phorum user ID - just seemed to make sense.
I also included in the string some data I need when I get control back in my own code. This is passed back in the return header relocation as PASSTHRU_LICENCE_PERIOD. On the return journey there is nothing sensitive in the so I did not encode it.
If anyone finds this code snippet useful then I am glad to have helped.
Many thanks to the guys at Phorum for making this such an easy transition.
Sorry, only registered users may post in this forum.