Revision: 49875 Author: btongminh Date: 2009-04-25 14:33:43 +0000 (Sat, 25 Apr 2009)
Log Message: ----------- Update error handling, among other things. Modified Paths: -------------- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -46,11 +46,15 @@ } function makeRow( $prop ) { + $label = wfMsg( "am-$prop" ); + if ( wfEmptyMsg( "am-$prop", $label ) ) + $label = "am-$prop"; + return ( "\t<tr><td>" . - Xml::label( wfMsg( "am-$prop" ), "am-$prop" ) . + Xml::label( $label, "am-$prop" ) . "</td><td>" . Xml::input( /* $name */ "am-$prop", /* $size */ false, - /* $value */ $this->get( $prop ), + /* $value */ $this->user->get( $prop ), array( 'id' => "am-$prop" ) ) . "</td></tr>\n" ); Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -3,8 +3,8 @@ class NssGroup { private static $groupsByGid = array(); public static function nameFromGid( $gid ) { - if ( isset( self::$groupsByGid( $gid ) ) ) - return self::$groupsByGid( $gid ); + if ( isset( self::$groupsByGid[$gid] ) ) + return self::$groupsByGid[$gid]; global $wgAuth; $dbr = $wgAuth->getDB( DB_READ ); @@ -13,6 +13,6 @@ $row = $res->fetchObject(); self::$groupsByGid[$gid] = $row ? $row->grp_name : strval( $gid ); - return self::$groupsByGid( $gid ); + return self::$groupsByGid[$gid]; } } \ No newline at end of file Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -31,6 +31,10 @@ $this->props = array(); $this->changed = array(); } + + function get( $name ) { + return $this->props[$name]; + } function set( $name, $value ) { $this->changed[] = $name; $this->props[$name] = $value; Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -24,7 +24,7 @@ // Load the user existence from passwd $result = $dbr->select( 'passwd', array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ), - array( 'pwd_name', $this->name ), + array( 'pwd_name' => $this->name ), __METHOD__ ); $row = $result->fetchObject(); @@ -62,9 +62,30 @@ } function get( $name ) { - return $this->properties->get( $name ); + switch ( $name ) { + case 'username': + return $this->name; + case 'home': + return $this->home; + case 'active': + return $this->active; + case 'email': + return $this->email; + default: + return $this->properties->get( $name ); + } } function set( $name, $value ) { + switch ( $name ) { + case 'username': + return; + case 'home': + $this->home = $value; + case 'active': + $this->active = $value; + case 'email': + $this->email = $value; + } return $this->properties->set( $name, $value ); } @@ -86,7 +107,7 @@ global $wgAuth; $dbr = $wgAuth->getDB( DB_READ ); - $res = $dbr->select( 'passwd', 'pwd_name', __METHOD__ ); + $res = $dbr->select( 'passwd', 'pwd_name', array(), __METHOD__ ); $names = array(); while ( $row = $res->fetchObject() ) Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -3,20 +3,77 @@ class SpecialAccountManager extends SpecialPage { function __construct() { parent::__construct( 'AccountManager', 'accountmanager', false ); + $this->error = false; } - function processData() { + function processData( $action ) { global $wgRequest; + $action = $wgRequest->getVal( 'action' ); + $username = $wgRequest->getVal( 'user' ); + if ( !( $action == 'create' || $action == 'submit' ) ) + return; + $user = new NssUser( $username ); + $user->load(); + + if ( $action == 'submit' && !$user->exists ) + return; + + // Extract post data + $post = $wgRequest->getValues(); + foreach( $post as $key => $value ) { + if( substr( $key, 0, 3 ) != 'am-' ) + continue; + $parts = explode( '-', $key, 2 ); + if( count( $parts ) != 2 ) + continue; + + $keyname = str_replace( '_', '-', strtolower( $parts[1] ) ); + $user->set( $keyname, $value ); + } + + if ( $action == 'submit' ) { + $user->commit(); + } else { + global $wgAuth, $wgPasswordSender; + + $password = $wgAuth->createAccount( $username ); + $user->insert(); + + $email = wfMsg( 'am-welcome-mail', $username, $password ); + $mailSubject = wfMsg( 'am-welcome-mail-subject' ); + $mailFrom = new MailAddress( $wgPasswordSender ); + $mailTo = new MailAddress( User::newFromName( $username ) ); + + $mailResult = UserMailer::send( $mailTo, $mailFrom, $mailSubject, $email ); + + if ( WikiError::isError( $mailResult ) ) { + $this->error = $mailResult->getMessage(); + return false; + } + } + $wgAuth->getDB( DB_WRITE )->immediateCommit(); + return true; + } function execute() { - global $wgRequest; + global $wgRequest, $wgUser, $wgOut; + if( !$this->userCanExecute( $wgUser ) ) + return $this->displayRestrictionError(); + $this->setHeaders(); - $action = $wgRequest->getVal( 'action' ); $username = $wgRequest->getVal( 'user' ); + $result = $this->processData(); + if ( $result === true ) { + $wgOut->addHTML( Xml::element('p', array(), wfMsg( 'am-updated' ) ) ); + } else if ( $result === false ) { + $wgOut->addHTML( Xml::element( 'p', array( 'class' => 'error' ), + wfMsg( $this->error ) ) . "\n" ); + } + $list = new AmUserListView(); $list->execute(); Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -18,7 +18,7 @@ $wgExtensionCredits['other'][] = array( 'name' => 'NssMySQLAuth', - 'version' => '1.0', + 'version' => '1.1', 'author' => 'Bryan Tong Minh', 'description' => 'A plugin to authenticate against a libnss-mysql database. Contains an [[Special:AccountManager|account manager]]', 'descriptionmsg' => 'nss-desc', Modified: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php =================================================================== --- branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php 2009-04-25 14:16:02 UTC (rev 49874) +++ branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php 2009-04-25 14:33:43 UTC (rev 49875) @@ -34,7 +34,7 @@ } function getDB( $db = DB_LAST ) { - return wfGetDB( $db, array(), $this->wikiName ); + return wfGetDB( $db, array(), $this->wikiNam0e ); } function userExists( $username ) { _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs