Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuthPlugin.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | } |
36 | 36 | |
37 | 37 | function getDB( $db = DB_LAST ) { |
38 | | - return wfGetDB( $db, array(), $this->wikiName ); |
| 38 | + return wfGetDB( $db, array(), $this->wikiNam0e ); |
39 | 39 | } |
40 | 40 | |
41 | 41 | function userExists( $username ) { |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/NssMySQLAuth.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | |
20 | 20 | $wgExtensionCredits['other'][] = array( |
21 | 21 | 'name' => 'NssMySQLAuth', |
22 | | - 'version' => '1.0', |
| 22 | + 'version' => '1.1', |
23 | 23 | 'author' => 'Bryan Tong Minh', |
24 | 24 | 'description' => 'A plugin to authenticate against a libnss-mysql database. Contains an [[Special:AccountManager|account manager]]', |
25 | 25 | 'descriptionmsg' => 'nss-desc', |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssGroup.php |
— | — | @@ -3,8 +3,8 @@ |
4 | 4 | class NssGroup { |
5 | 5 | private static $groupsByGid = array(); |
6 | 6 | public static function nameFromGid( $gid ) { |
7 | | - if ( isset( self::$groupsByGid( $gid ) ) ) |
8 | | - return self::$groupsByGid( $gid ); |
| 7 | + if ( isset( self::$groupsByGid[$gid] ) ) |
| 8 | + return self::$groupsByGid[$gid]; |
9 | 9 | |
10 | 10 | global $wgAuth; |
11 | 11 | $dbr = $wgAuth->getDB( DB_READ ); |
— | — | @@ -13,6 +13,6 @@ |
14 | 14 | $row = $res->fetchObject(); |
15 | 15 | self::$groupsByGid[$gid] = $row ? $row->grp_name : strval( $gid ); |
16 | 16 | |
17 | | - return self::$groupsByGid( $gid ); |
| 17 | + return self::$groupsByGid[$gid]; |
18 | 18 | } |
19 | 19 | } |
\ No newline at end of file |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssProperties.php |
— | — | @@ -31,6 +31,10 @@ |
32 | 32 | $this->props = array(); |
33 | 33 | $this->changed = array(); |
34 | 34 | } |
| 35 | + |
| 36 | + function get( $name ) { |
| 37 | + return $this->props[$name]; |
| 38 | + } |
35 | 39 | function set( $name, $value ) { |
36 | 40 | $this->changed[] = $name; |
37 | 41 | $this->props[$name] = $value; |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/NssUser.php |
— | — | @@ -24,7 +24,7 @@ |
25 | 25 | // Load the user existence from passwd |
26 | 26 | $result = $dbr->select( 'passwd', |
27 | 27 | array( 'pwd_uid', 'pwd_gid', 'pwd_home', 'pwd_active', 'pwd_email' ), |
28 | | - array( 'pwd_name', $this->name ), |
| 28 | + array( 'pwd_name' => $this->name ), |
29 | 29 | __METHOD__ |
30 | 30 | ); |
31 | 31 | $row = $result->fetchObject(); |
— | — | @@ -62,9 +62,30 @@ |
63 | 63 | } |
64 | 64 | |
65 | 65 | function get( $name ) { |
66 | | - return $this->properties->get( $name ); |
| 66 | + switch ( $name ) { |
| 67 | + case 'username': |
| 68 | + return $this->name; |
| 69 | + case 'home': |
| 70 | + return $this->home; |
| 71 | + case 'active': |
| 72 | + return $this->active; |
| 73 | + case 'email': |
| 74 | + return $this->email; |
| 75 | + default: |
| 76 | + return $this->properties->get( $name ); |
| 77 | + } |
67 | 78 | } |
68 | 79 | function set( $name, $value ) { |
| 80 | + switch ( $name ) { |
| 81 | + case 'username': |
| 82 | + return; |
| 83 | + case 'home': |
| 84 | + $this->home = $value; |
| 85 | + case 'active': |
| 86 | + $this->active = $value; |
| 87 | + case 'email': |
| 88 | + $this->email = $value; |
| 89 | + } |
69 | 90 | return $this->properties->set( $name, $value ); |
70 | 91 | } |
71 | 92 | |
— | — | @@ -86,7 +107,7 @@ |
87 | 108 | global $wgAuth; |
88 | 109 | $dbr = $wgAuth->getDB( DB_READ ); |
89 | 110 | |
90 | | - $res = $dbr->select( 'passwd', 'pwd_name', __METHOD__ ); |
| 111 | + $res = $dbr->select( 'passwd', 'pwd_name', array(), __METHOD__ ); |
91 | 112 | |
92 | 113 | $names = array(); |
93 | 114 | while ( $row = $res->fetchObject() ) |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/AmUserView.php |
— | — | @@ -46,11 +46,15 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | function makeRow( $prop ) { |
| 50 | + $label = wfMsg( "am-$prop" ); |
| 51 | + if ( wfEmptyMsg( "am-$prop", $label ) ) |
| 52 | + $label = "am-$prop"; |
| 53 | + |
50 | 54 | return ( "\t<tr><td>" . |
51 | | - Xml::label( wfMsg( "am-$prop" ), "am-$prop" ) . |
| 55 | + Xml::label( $label, "am-$prop" ) . |
52 | 56 | "</td><td>" . |
53 | 57 | Xml::input( /* $name */ "am-$prop", /* $size */ false, |
54 | | - /* $value */ $this->get( $prop ), |
| 58 | + /* $value */ $this->user->get( $prop ), |
55 | 59 | array( 'id' => "am-$prop" ) ) . |
56 | 60 | "</td></tr>\n" |
57 | 61 | ); |
Index: branches/NssMySQLAuth-rewrite/NssMySQLAuth/AccountManager/SpecialAccountManager.php |
— | — | @@ -3,20 +3,77 @@ |
4 | 4 | class SpecialAccountManager extends SpecialPage { |
5 | 5 | function __construct() { |
6 | 6 | parent::__construct( 'AccountManager', 'accountmanager', false ); |
| 7 | + $this->error = false; |
7 | 8 | } |
8 | 9 | |
9 | | - function processData() { |
| 10 | + function processData( $action ) { |
10 | 11 | global $wgRequest; |
| 12 | + $action = $wgRequest->getVal( 'action' ); |
| 13 | + $username = $wgRequest->getVal( 'user' ); |
11 | 14 | |
| 15 | + if ( !( $action == 'create' || $action == 'submit' ) ) |
| 16 | + return; |
12 | 17 | |
| 18 | + $user = new NssUser( $username ); |
| 19 | + $user->load(); |
| 20 | + |
| 21 | + if ( $action == 'submit' && !$user->exists ) |
| 22 | + return; |
| 23 | + |
| 24 | + // Extract post data |
| 25 | + $post = $wgRequest->getValues(); |
| 26 | + foreach( $post as $key => $value ) { |
| 27 | + if( substr( $key, 0, 3 ) != 'am-' ) |
| 28 | + continue; |
| 29 | + $parts = explode( '-', $key, 2 ); |
| 30 | + if( count( $parts ) != 2 ) |
| 31 | + continue; |
| 32 | + |
| 33 | + $keyname = str_replace( '_', '-', strtolower( $parts[1] ) ); |
| 34 | + $user->set( $keyname, $value ); |
| 35 | + } |
| 36 | + |
| 37 | + if ( $action == 'submit' ) { |
| 38 | + $user->commit(); |
| 39 | + } else { |
| 40 | + global $wgAuth, $wgPasswordSender; |
| 41 | + |
| 42 | + $password = $wgAuth->createAccount( $username ); |
| 43 | + $user->insert(); |
| 44 | + |
| 45 | + $email = wfMsg( 'am-welcome-mail', $username, $password ); |
| 46 | + $mailSubject = wfMsg( 'am-welcome-mail-subject' ); |
| 47 | + $mailFrom = new MailAddress( $wgPasswordSender ); |
| 48 | + $mailTo = new MailAddress( User::newFromName( $username ) ); |
| 49 | + |
| 50 | + $mailResult = UserMailer::send( $mailTo, $mailFrom, $mailSubject, $email ); |
| 51 | + |
| 52 | + if ( WikiError::isError( $mailResult ) ) { |
| 53 | + $this->error = $mailResult->getMessage(); |
| 54 | + return false; |
| 55 | + } |
| 56 | + } |
| 57 | + $wgAuth->getDB( DB_WRITE )->immediateCommit(); |
| 58 | + return true; |
| 59 | + |
13 | 60 | } |
14 | 61 | |
15 | 62 | function execute() { |
16 | | - global $wgRequest; |
| 63 | + global $wgRequest, $wgUser, $wgOut; |
| 64 | + if( !$this->userCanExecute( $wgUser ) ) |
| 65 | + return $this->displayRestrictionError(); |
| 66 | + $this->setHeaders(); |
17 | 67 | |
18 | | - $action = $wgRequest->getVal( 'action' ); |
19 | 68 | $username = $wgRequest->getVal( 'user' ); |
20 | 69 | |
| 70 | + $result = $this->processData(); |
| 71 | + if ( $result === true ) { |
| 72 | + $wgOut->addHTML( Xml::element('p', array(), wfMsg( 'am-updated' ) ) ); |
| 73 | + } else if ( $result === false ) { |
| 74 | + $wgOut->addHTML( Xml::element( 'p', array( 'class' => 'error' ), |
| 75 | + wfMsg( $this->error ) ) . "\n" ); |
| 76 | + } |
| 77 | + |
21 | 78 | $list = new AmUserListView(); |
22 | 79 | $list->execute(); |
23 | 80 | |