Forum (SMF), users integration, am I doing it right?

Forum (SMF), users integration, am I doing it right?

Wednesday 29 April 2009 4:52:49 am - 6 replies

Modified on Wednesday 29 April 2009 5:11:20 am by Dimiter Ivanov

Author Message

Dimiter Ivanov

Thursday 07 May 2009 1:00:59 pm

Hi again.

My extension for adding users to the forum, and updating passwords/email information works fine, but now, i can't figure out how to do it the other way around.
I want when the user changes his password from the forum software, to update it in ezpublish's database.
What is the proper way to do it and how?
Can I include some file from ezpublish, and make the API calls from there, or the only way to do it is with eZScript (for wich i need CLI access)?
Or simply i should 'hack' the database and change the password myself?

Any pointers appreciated.

André R.

Friday 08 May 2009 12:41:34 am

You can take a look in the eZ Publish views to see how the api is used, in this case in user/password aka kernel/user/password.php.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Dimiter Ivanov

Friday 08 May 2009 1:34:49 am

André, my problem is using the API 'outside' of eZPubluish.

Is it possible to use the API ( fetch user object, and alter it and store it) within another application?

For example, I created a clean .php file, and tried to fetch user object with the API, change the password and store it. The file is in the eZPublish root folder, and to make it work I had to include autoload.php and access.php, to set the correct access.
It works, I can change the user object when I load the page from the browser, but when I Include this file from other directory, outside of the eZPublish root, even after I add the eZPublish root folder to the php include_path, it still crashes with errors.

Jianjun Hu

Saturday 09 May 2009 5:43:31 pm

I'm interested in this topic.

OnlyBlue

☆..·°∴°.☆°°.☆°.
°∴ °☆ .·enjoy star° .·★°∴°
∴°.°★ .·°
  ミ☆°∴°.★☆° ∴·°
°.☆° .·∴° 

Is it a pleasure after all to practice in due time what one has learnt?

Kristof Coomans

Wednesday 13 May 2009 12:09:52 pm

Hi Dimiter

To me, using a web service looks like a good solution to the problem you are facing.
After all, you want to let 2 completely disconnected applications communicate with each other.

Did you have a look at the eZ Publish built-in SOAP support, or at the NuSOAP extension ( http://projects.ez.no/nusoap )?
Good luck!

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Dimiter Ivanov

Wednesday 13 May 2009 3:29:20 pm

Well, the applications are not <i>that</i> disconected, since they both live in the same filesystem, and database server, soap maybe is a good general solution, i will look it up..

But here is what i cam up with, the solution (as it allways happens) is much more simpler than i was expecting.

Setting, the <b>current working dir</b> for the .php file did the trick.
here is the code that i used, to 'initialize' the eZPublish environment.
this sits in a 'clean', 'empy' .php file:

$path="/full/path/to/ezpublish/root";
//the magick trick
chdir($path);
//these files sit in the eZPublish root 
require ('autoload.php');
require_once("access.php");

/*!
  Dummy function, required by some scripts in eZ Publish.
*/
function eZUpdateDebugSettings( $useDebug = null )
{
}
//create eZINI instance providing the root folder for the settings files
$ini = eZINI::instance("site.ini",$path . "/settings",null,false);

$siteaccess = $ini->variable( 'SiteSettings', 'DefaultAccess' );

$access = array( 'name' => $siteaccess,
				 'type' => EZ_ACCESS_TYPE_DEFAULT );

$access = changeAccess( $access );
// here ends the eZPublish 'init'


// I omit some required SMF defines

//from here on, this (what i needed) works:

function integrate_reset_pass($old_username, $username, $password)
{	
	$user= eZUser::fetchByName($old_username,true);
	if($user)
	{
		$site=$user->site();
		$type = $user->attribute( "password_hash_type" );
		$newHash = $user->createHash( $old_username, $password, $site, $type );
		$user->setAttribute( "password_hash", $newHash );
		$user->store();
	}
}
function integrate_change_member_data($members, $var, $data)
{	
	if($var=="emailAddress")
	{
		$user= eZUser::fetchByName($members[0],true);
		if($user)
		{			
			$user->setAttribute( "email", trim($data,"'") );
			$user->store();
		}
	}
}

When this file is included in the SMF forum's index.php file, the forum will call the integrate_* functions that i have defined and that's it.

I don't know if this is a proper way to do it, but form what i have tested it works.

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.