Extension:PunBB Authentication
From MediaWiki.org
|
Release status: unknown |
|||
|---|---|---|---|
| Implementation | User identity | ||
| Description | Auto-authenticates PunBB users | ||
| Author(s) | Bradley Bell | ||
| Last Version | 1.0 | ||
| License | No license specified | ||
| Download | This page | ||
|
|||
|
check usage (experimental) |
|||
[edit] Purpose
PunBB Authentication is an extension that will automatically authenticate the currently logged-in PunBB user to MediaWiki.
[edit] Installation
The login and logout hooks will not work with a stock installation of PunBB, but they could be made to work with a little customization to PunBB's login.php.
Save the source code as extensions/PunBBAuth.php
Add the line:
require_once("extensions/PunBBAuth.php");
[edit] Source code
<?php /** * PunBB MediaWiki extension * * @file * @ingroup Extensions * @version 1.0 * @author Bradley Bell * @link http://www.mediawiki.org/wiki/Extension:PunBB_Authentication Documentation */ if( !defined( 'MEDIAWIKI' ) ) die(); // Extension credits that will show up on Special:Version $wgExtensionCredits['other'][] = array( 'name' => 'PunBB Authentication', 'version' => '1.0', 'author' => 'Bradley Bell', 'url' => 'http://www.mediawiki.org/wiki/Extension:PunBB_Authentication', 'description' => 'Auto-authenticates users using PunBB database', ); # PunBB integration //define('PUN_QUIET_VISIT', 1); define('PUN_ROOT', '/path/to/punbb/'); require PUN_ROOT.'include/common.php'; $wgHooks['AutoAuthenticate'][] = 'AutoAuthenticatePunBB'; //$wgHooks['UserLogout'][] = 'UserLogoutPunBB'; //$wgHooks['UserLoginForm'][] = 'UserLoginFormPunBB'; function AutoAuthenticatePunBB( &$user ) { global $pun_user; wfSetupSession(); if( $pun_user['is_guest'] ) { return true; } /** * A lot of this is from User::newFromName */ $validate = true; // Force usernames to capital global $wgContLang; $name = $wgContLang->ucfirst( $pun_user['username'] ); // Clean up name according to title rules $t = Title::newFromText( $name ); if( is_null( $t ) ) { return null; } // Reject various classes of invalid names $canonicalName = $t->getText(); global $wgAuth; $canonicalName = $wgAuth->getCanonicalName( $t->getText() ); if( $validate && !User::isValidUserName( $canonicalName ) ) { return null; } $user->setName( $pun_user['username'] ); $user->setId( $user->idFromName( $pun_user['username'] ) ); if ( $user->getID() == 0 ) { /** * A lot of this is from LoginForm::initUser */ $user->addToDatabase(); $user->setEmail( $pun_user['email'] ); $user->setRealName( $pun_user['realname'] ); $user->setToken(); $user->confirmEmail(); if( $pun_user['g_id'] == PUN_ADMIN ) { $user->addGroup('sysop'); } } else { /* Should cache some day, I guess :) */ $user->loadFromDatabase(); $user->setToken(); } return true; } function UserLogoutPunBB( &$user ) { global $pun_user; redirect('/forums/login.php?action=out&id='.$pun_user['id'], 'Logging out. Redirecting …'); return true; } function UserLoginFormPunBB( &$template ) { $referer = $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : 'index.php'; header('Location: http://hostname/forums/login.php?redirect_url='.$referer); return true; }