Firefox PHP

Use of existing member system [solved]

Posted by Terradon 
All files from this thread

File Name File Size   Posted by Date  
mod_inherit_authentication_from_session.php 2.9 KB open | download Maurice Makaay 10/22/2010 Read message
mod_inherit_authentication_from_session.php 3 KB open | download Maurice Makaay 10/22/2010 Read message
Use of existing member system [solved]
October 19, 2010 02:22AM
Hi all,
I have read this forum for hours now, but still haven't a clue how to start using an existing database from an existing community website, with about 1000 users.
I am just average with php.
maybe someone can help me, just 1 step at a time? Afterwards i will write just a simple step-by-step manual for dummies, like me, who does not understand the concept of phorum yet.

I have edited this post, to write a short-short version of the result of my question.
I hope this will be usefull for many webmasters!


Installation:
Download and install phorum script.
Create admin user.
Download and install language pack

Integration:
Download Module: External Authentication Module (Full version)
Extract and place map external_authentication directly under your phorummap/mods map

Now check if you have installed this module correctly
=> go to phorum admin => Global Settings => modules

In your list of Phorum Module Settings you should see External Authentication (version 5.2.1.04)
if not, you did not correctly install this module.

If correctly installed:
In map your_phorum_map/mods/external_authentication/plugins_bin
create a new map, for example: comm_external_auth_plugin

Inside this map, you just need to create 2 files:
info.php
hook_user_session_restore.php

info.php:
Language: PHP
//add this external application';s info to the list of possible apps   $PHORUM["phorum_mod_external_authentication"]["possible_apps"][] = array(   //The name of your external application, possibly with the supported version //number   "name" => "comm_external_auth_plugin",   //The folder for your plugin (the folder which contains this info.php file)   "app_folder" => "comm_external_auth_plugin",   //The required version of the External Authentication which has the //necessary hook support for your module   "required_version" => "5.2.1.01",   //Your name, callsign, etc.   "author" => "Me, I and Myself", );

hook_user_session_restore.php:
Language: PHP
/* phorum module info hook: user_session_restore|inherit_authentication_from_session title: Inherit authentication from session desc: This module will use session data of a main application to create and authenticate a Phorum user. Note that this module was written as an example and will need work if you want to apply it for your own purposes. */   function inherit_authentication_from_session($session_data) { // Initialize the session data as "not logged in". $session_data[PHORUM_SESSION_LONG_TERM] = FALSE; $session_data[PHORUM_SESSION_SHORT_TERM] = FALSE;   // Start the PHP session management when it';s not already started. if (!session_id()) session_start();   // In the main application, the user data is stored in the session. // If no user is set, then we are done here. if(empty($_SESSION[';nick';])) return $session_data; //session_start();   // Build a Phorum compatible user data array. $active_user_data = array( ';username'; => $_SESSION[';nick';], ';password'; => md5($_SESSION[';password';]), // not needed for regular users ';email'; => ';notset@xxxxxxxx.nl';, // needed for e-mail notifications $_SESSION[';userEmail';] ';admin'; => 0, ';active'; => PHORUM_USER_ACTIVE );   // Hardcoded: user "Terradon" is admin in phorum if ($active_user_data[';username';] == ';some_name'; OR $active_user_data[';username';] == ';other_name';) { $active_user_data[';admin';] = 1;   }   // Load the Phorum api code for various user-related functions. include_once "./include/api/user.php";   // Check if a Phorum user exists for the active username. // If the user does not exist. Create a new user. $user_id = phorum_api_user_search("username", $active_user_data[';username';]); if (!$user_id) { // prevent conflicts with Phorum user_ids by letting Phorum generate // its own user_id value. $active_user_data[';user_id';] = NULL; $user_id = phorum_api_user_save($active_user_data, PHORUM_FLAG_RAW_PASSWORD); }   // Load the existing user data. $phorum_user_data = phorum_api_user_get($user_id);   // If the user is not active, then do not log them in. if ($phorum_user_data[';active';] != PHORUM_USER_ACTIVE) { return $session_data; }   // Sync user data if any of the input fields is different from the // data that is stored for the Phorum user in the database. if ($active_user_data[';admin';] != $phorum_user_data[';admin';] || $active_user_data[';email';] != $phorum_user_data[';email';] || $active_user_data[';active';] != $phorum_user_data[';active';] || $active_user_data[';password';] != $phorum_user_data[';password';]) { $active_user_data[';user_id';] = $phorum_user_data[';user_id';]; phorum_api_user_save($active_user_data, PHORUM_FLAG_RAW_PASSWORD); }   // We have a legit user, so set the session info. $session_data[PHORUM_SESSION_LONG_TERM] = $user_id; $session_data[PHORUM_SESSION_SHORT_TERM] = $user_id;   return $session_data; } $session_data = inherit_authentication_from_session($session_data);

Go back to:
=> phorum admin => Global Settings => modules

At External Authentication select ON and push submit.

Go back to
=> phorum admin => Global Settings => modules
click on settings at External Authentication.

=> Which external application will be the authentication master
=> choose ""comm_external_auth_plugin"
and select all options (after saving you can select all)

Now, for all logged in users, phorum accounts will be automatically created.


Extra:

To complete your websites usersystem:
- existing users can be copied to phorum users' table
- You MUST edit your own registration system, so you save userdata twice,=> your own tables and => phorum tables.

These 2 actions are needed if you want to use the private message system and profiles.
if you dont do this, then only users who have visited your phorum will be able to use pm and profiles.

That's all!
(now you do not have to read this whole topic)

Many thanks for the very good assistance of the Phorum team.



Edited 13 time(s). Last edit at 11/08/2010 12:44PM by Terradon.
Re: Use of existing member system
October 19, 2010 03:01AM
Integration is not a simple subject and definitely not a subject that can be covered in a single step-by-step manual.

For example, there are multiple ways in which you can integrate a user database. One way could be that you write a module that authenticates users against your database from within the Phorum authentication phase. Another way could be that you allow users to login on your own site, automatically carrying over the user to the Phorum environment from withing the Phorum session management.

Starting points to search for are the external authentication module and the user_session_restore hook.

In general, you need to write code for handling user database integration. Whether or not this is hard, depends on your PHP coding experience.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Use of existing member system
October 19, 2010 03:17AM
Thanks Maurice,
my goal is that users login via an existing website and can use the forum without logging in again.
Forum must be inaccessable, not even readable, when not logged in.
I think this is a common wish. So therefore a step-by-step guide can be very usefull.

I do have some php experience, but ussually i dont know where to begin and usually i get to much feedback at once:)
i prefer to cut down my big problem in many very small problems,which i probably do understand:)

I have found the External Authentication module.
It seems to me, that it must be possible to create some common code/functions where i just can pass values to phorum.
For example myfunction($user,$value1,$value2,$etc)
When i have accomplished this, (a common external user integration ), it can be added to this module:)

I will go on reading the documentation and arising question will be placed here.

My first question is, i MUST save userrecords twice?



Edited 1 time(s). Last edit at 10/19/2010 03:22AM by Terradon.
Re: Use of existing member system
October 19, 2010 03:28AM
What you need on a technical plane, is that there is a Phorum user in the Phorum database, which is associated with the user from your own login system. If with "twice" you mean a Phorum user and a user of yourself, then yes. One of the reasons for this, is that Phorum needs the user record for storing settings and data for the users. The record would not have been required if it were for handling authentication alone.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Use of existing member system
October 19, 2010 07:23PM
Ok, i did copy a same username into the usertable of phorum as i already have in our website userslist.
I installed External Authentication Module (Full version)
In my admin page i can now choose yes for External Authentication Module.

But when i click on settings i get an adminpage with only the menu on the left, but no further content?
I have not written a plugin yet, but i should have had a possibility to choose an application like LDAP, Drupal and so on?
Re: Use of existing member system
October 19, 2010 07:41PM
Quote
Terradon
Ok, i did copy a same username into the usertable of phorum as i already have in our website userslist.

This worries me. There are many other fields required by Phorum than just username. Did you generate content for those fields?

Quote

I installed External Authentication Module (Full version)
In my admin page i can now choose yes for External Authentication Module.

But when i click on settings i get an adminpage with only the menu on the left, but no further content?
I have not written a plugin yet, but i should have had a possibility to choose an application like LDAP, Drupal and so on?

You should see a full settings page for the module. Do you see any errors in the Event Logging module? in your PHP logs?


Joe Curia (aka Azumandias)
Modules: l0Admin Mass Email00000000l000000Automatic Time Zones000ll.l00000Enhanced Custom Profiles0.00Google Calendar0000l.l000000Post Previews
000000000Admin Security Suite000000000000Check Modules for Upgrades0000External Authentication000000Group Auto-Email00000.00000Private Message Alerts
000000000Attachment Download Counter0000Custom Attachment Icons000ll.ll00Favorite Forums000000.00000Highlighted Search Terms0000Self-Delete Posts Option
000000000Attachment Watermarks0l00000000Custom Language Database00l.l.0Forum Lockdown00000.00000Ignore Forums0000000000000Threaded Tree View
000000000Automatic Message Pruning00.llll.00Easy Color Scheme Manager0l.l00Forum Subscriptions0000lll000Moderated User Group
Templates:lGeneric Integration000000000 0000Simple Rounded000000 00000000Tabbed Emerald
Re: Use of existing member system
October 19, 2010 08:34PM
Hi Joe,
i added one user the normal way during installation. Then i added directly via phpMyAdmin a second user and filled in the fields that were filled in with the first user, except for password, cookie_sessid_lt, sessid_st and password_temp fields.

Did not check the errorlogs yet, i am trying to find out how to go on with External Authentication module.
As posted at October 19, 2010 12:23PM, i can choose yes for External Authentication but then i do not have a clue how to go on further (get no content when choosing settings for External Authentication)
Re: Use of existing member system
October 19, 2010 09:58PM
I found out why i do not get any content after Set External Authentication => yes

I changed in admin.php:

//@include_once "./include/admin/$module.php";
include_once "./include/admin/$module.php"; // REMOVED @ <<<<<<<<<<<<<<<<<<<<<<<<<

Then i get next error:

Fatal error: Call to undefined function: scandir() in /home/xxx.nl/public_html/xxx.nl/forum_v5/mods/external_authentication/settings.php on line 134



Edited 1 time(s). Last edit at 10/19/2010 09:58PM by Terradon.
Re: Use of existing member system
October 19, 2010 10:06PM
I'd say that you are running on (ancient by now) PHP4. The scandir() function was introduced in PHP5.


Maurice Makaay
Phorum Development Team
my blog linkedin profile secret sauce
Re: Use of existing member system
October 19, 2010 10:14PM
whoops, i found out..historical problem.

for now solved with:

/* PHP5 functie :(

// get a list of possible apps
$possible_app_dirs = scandir("./mods/external_authentication/plugins_bin");
}
*/

/* PHP4 alternatief */

$dh = opendir("./mods/external_authentication/plugins_bin");
while (false !== ($filename = readdir($dh)))
{
if(is_dir($filename))
$possible_app_dirs[] = $filename;
}

/* Einde PHP4 alternatief */
Sorry, only registered users may post in this forum.

Click here to login