0
phpBB3 Authentifizierung in Zend Framework nutzen
Da ich mein altes phpBB2 Bowling Forum zur Zeit in ein schmuckes phpBB3 Board verwandel, stand ich vor der Frage, wie man am besten die bereits vorhandene Authentifizierung und ACLs von phpBB3 im Zend Framework nutzen kann. Auf diesem baut nämlich mein dazugehöriges Portal auf und eine doppelte Authentifizierung will man natürlich nicht haben.
Die Suche bei Google erbrachte nicht viel, ausser Postings in denen andere Webmaster auch auf der Suche nach solch einer Lösung waren. Also blieb nur selbst schreiben über. Ich habe das ganze als Service in meinem Default Module angelegt, so dass es modulübergreifend genutzt werden kann.
<?php
/**
* Bowling Community
*
* PHP version 5.3.2
*
* @author Udo Telaar
* @copyright Copyright (c) 2010 Udo Telaar
* @version $Id:$
*/
/**
* Default_Service_Auth
*
* @author Udo Telaar <post@udo-telaar.de>
*/
class Default_Service_Auth extends App_Service_Abstract
{
protected $_auth = null;
protected $_user = null;
/**
* Constructor mainly setup the phpbb environment and writes
* auth and user object into local variables
*
* @global string $phpbb_root_path
* @global string $phpEx
* @global object $db
* @global array $config
* @global object $user
* @global object $auth
* @global object $cache
*/
public function __construct()
{
define('IN_PHPBB', true);
//set scope for variables required later
global $phpbb_root_path;
global $phpEx;
global $db;
global $config;
global $user;
global $auth;
global $cache;
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$phpbb_root_path = './forum/';
require($phpbb_root_path .'common.php');
$user->session_begin();
$auth->acl($user->data);
$this->_auth = $auth;
$this->_user = $user;
}
/**
* Check if current user is an admin (type 3)
* @return boolean
*/
public function isAdmin()
{
return (3 == $this->getUserData('user_type')) ? true : false;
}
/**
* Check if current user is logged in
* @return boolean
*/
public function isLoggedIn()
{
return $this->getUserData('is_registered') ? true : false;
}
/**
* Check if current user is allowed to access a given resource.
* This function uses the phpbb acl
*
* @param string $resource
* @return boolean
*/
public function isAllowed($resource)
{
return $this->_auth->acl_get($resource) ? true : false;
}
/**
* Get all or a specific data from user data array
*
* @param string|null $data
* @return mixed
*/
public function getUserData($data = null)
{
if (null !== $data) {
return isset($this->_user->data[$data]) ?
$this->_user->data[$data] : null;
}
return $this->_user->data;
}
}
