r24115 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24114‎ | r24115 | r24116 >
Date:09:04, 15 July 2007
Author:aaron
Status:old
Tags:
Comment:
*Honor alternate name input. Escape text of request to avoid injections. Send out rejection emails :(
Modified paths:
  • /trunk/extensions/ConfirmAccount/ConfirmAccount.i18n.php (modified) (history)
  • /trunk/extensions/ConfirmAccount/ConfirmAccount_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ConfirmAccount/ConfirmAccount_body.php
@@ -359,7 +359,7 @@
360360 $this->acrID = $wgRequest->getIntOrNull( 'acrid' );
361361 # For renaming to alot for collisions with other local requests
362362 # that were added to some global $wgAuth system first.
363 - $this->mUsername = $wgRequest->getIntOrNull( 'wpNewName' );
 363+ $this->mUsername = $wgRequest->getText( 'wpNewName' );
364364
365365 $this->skin = $wgUser->getSkin();
366366
@@ -381,46 +381,60 @@
382382 $wgOut->returnToMain( null, $wgTitle );
383383 return;
384384 }
385 -
 385+
386386 if( $action == 'reject' ) {
 387+ # Make proxy user to email a rejection message :(
 388+ $u = User::newFromName( $row->acr_name, 'creatable' );
 389+ $u->setEmail( $row->acr_email );
 390+ $result = $u->sendMail( wfMsg( 'confirmaccount-email-subj' ),
 391+ wfMsg( 'confirmaccount-email-body2', $u->getName() ) );
 392+ if( WikiError::isError( $result ) ) {
 393+ $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
 394+ $this->showForm( $error );
 395+ return false;
 396+ }
 397+
387398 $dbw = wfGetDB( DB_MASTER );
388399 $dbw->delete( 'account_requests', array('acr_id' => $this->acrID), __METHOD__ );
389 -
 400+
390401 $this->showSuccess( $action );
391402 } else if( $action == 'accept' ) {
392403 global $wgMakeUserPageFromBio;
393404 # Check if the name is to be overridden
394405 $name = $this->mUsername ? trim($this->mUsername) : $row->acr_name;
395 - # Now create a dummy user ($u) and check if it is valid
396 - $u = User::newFromName( $name, 'creatable' );
397 - if( is_null( $u ) ) {
 406+ # Now create user and check if the name is valid
 407+ $user = User::newFromName( $name, 'creatable' );
 408+ if( is_null( $user ) ) {
398409 $this->showForm( wfMsgHtml('noname') );
399410 return;
400411 }
401412 # Check if already in use
402 - if( 0 != $u->idForName() || $wgAuth->userExists( $u->getName() ) ) {
 413+ if( 0 != $user->idForName() || $wgAuth->userExists( $user->getName() ) ) {
403414 $this->showForm( wfMsgHtml('userexists') );
404415 return;
405416 }
406 -
 417+ # Make a random password
407418 $pass = User::randomPassword();
408 - if( !$wgAuth->addUser( $u, $pass, $row->acr_email, $row->acr_real_name ) ) {
409 - $this->showForm( wfMsg( 'externaldberror' ) );
410 - return false;
411 - }
412 - # Now that name is validated, create the stub account
413 - $user = User::createNew( $name );
414419 # VERY important to set email now. Otherwise user will have to request
415420 # a new password at the login screen...
416421 $user->setEmail( $row->acr_email );
417 - $user->setRealName( $row->acr_real_name );
418 - $user->setPassword( $pass );
419 - $user->saveSettings(); // Save this stuff now
420 - # Email this password
421 - $user->sendMail( wfMsg( 'confirmaccount-email-subj' ),
 422+ $result = $user->sendMail( wfMsg( 'confirmaccount-email-subj' ),
422423 wfMsg( 'confirmaccount-email-body',
423424 $user->getName(),
424425 $pass ) );
 426+ if( WikiError::isError( $result ) ) {
 427+ $error = wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) );
 428+ $this->showForm( $error );
 429+ return false;
 430+ }
 431+ if( !$wgAuth->addUser( $user, $pass, $row->acr_email, $row->acr_real_name ) ) {
 432+ $this->showForm( wfMsg( 'externaldberror' ) );
 433+ return false;
 434+ }
 435+ # Set password and realname
 436+ $user->setPassword( $pass );
 437+ $user->setRealName( $row->acr_real_name );
 438+ $user->saveSettings(); // Save this into the DB
425439 # Check if the user already confirmed email address
426440 $dbw = wfGetDB( DB_MASTER );
427441 $dbw->update( 'user',
@@ -428,17 +442,16 @@
429443 'user_email_token_expires' => $row->acr_email_token_expires ),
430444 array( 'user_id' => $user->getID() ),
431445 __METHOD__ );
432 -
433446 # OK, now remove the request
434447 $dbw->delete( 'account_requests', array('acr_id' => $this->acrID), __METHOD__ );
435 -
 448+
436449 wfRunHooks( 'AddNewAccount', array( $user ) );
437450 # Start up the user's brand new userpage
438451 if( $wgMakeUserPageFromBio ) {
439452 $userpage = new Article( $user->getUserPage() );
440453 $userpage->doEdit( $row->acr_bio, wfMsg('confirmaccount-summary'), EDIT_NEW );
441454 }
442 -
 455+
443456 $this->showSuccess( $action, $user->getName() );
444457 }
445458 }
@@ -472,14 +485,14 @@
473486
474487 $econf = $row->acr_email_authenticated ? ' <strong>'.wfMsg('confirmaccount-econf').'</strong>' : '';
475488 $form .= "<tr><td>".wfMsgHtml('requestaccount-email')."</td>";
476 - $form .= "<td>".$row->acr_email.$econf."</td></tr>\n";
 489+ $form .= "<td>".htmlspecialchars($row->acr_email).$econf."</td></tr>\n";
477490 $form .= '</table></fieldset>';
478491
479492 $form .= '<fieldset>';
480493 $form .= '<legend>' . wfMsg('requestacount-legend2') . '</legend>';
481494 $form .= '<table cellpadding=\'4\'>';
482495 $form .= "<tr><td>".wfMsgHtml('requestaccount-real')."</td>";
483 - $form .= "<td>".$row->acr_real_name."</td></tr>\n";
 496+ $form .= "<td>".htmlspecialchars($row->acr_real_name)."</td></tr>\n";
484497 $form .= '</table cellpadding=\'4\'>';
485498 $form .= "<p>".wfMsgHtml('requestaccount-bio')."</p>";
486499 $form .= "<p><textarea tabindex='1' readonly name='wpBio' id='wpBio' rows='10' cols='80' style='width:100%'>" .
@@ -491,11 +504,11 @@
492505 $form .= '<legend>' . wfMsg('requestacount-legend3') . '</legend>';
493506 $form .= "<p>".wfMsgHtml('requestaccount-notes')."</p>\n";
494507 $form .= "<p><textarea tabindex='1' readonly name='wpNotes' id='wpNotes' rows='3' cols='80' style='width:100%'>" .
495 - $row->acr_notes .
 508+ htmlspecialchars($row->acr_notes) .
496509 "</textarea></p>";
497510 $form .= "<p>".wfMsgHtml('requestaccount-urls')."</p>\n";
498511 $form .= "<p><textarea tabindex='1' readonly name='wpUrls' id='wpUrls' rows='2' cols='80' style='width:100%'>" .
499 - $row->acr_urls .
 512+ htmlspecialchars($row->acr_urls) .
500513 "</textarea></p>";
501514 $form .= '</fieldset>';
502515
@@ -565,12 +578,15 @@
566579 $r = '<li>';
567580 $r .= $time." ($link)".'<br/>';
568581 $r .= '<table cellspacing=\'1\' cellpadding=\'3\' border=\'1\' width=\'100%\'>';
569 - $r .= '<tr><td><strong>'.wfMsg('confirmaccount-name').'</strong></td><td width=\'100%\'>'.$row->acr_name.'</td></tr>';
570 - $r .= '<tr><td><strong>'.wfMsg('confirmaccount-real').'</strong></td><td width=\'100%\'>'.$row->acr_real_name.'</td></tr>';
 582+ $r .= '<tr><td><strong>'.wfMsg('confirmaccount-name').'</strong></td><td width=\'100%\'>' .
 583+ htmlspecialchars($row->acr_name) . '</td></tr>';
 584+ $r .= '<tr><td><strong>'.wfMsg('confirmaccount-real').'</strong></td><td width=\'100%\'>' .
 585+ htmlspecialchars($row->acr_real_name) . '</td></tr>';
571586 $econf = $row->acr_email_authenticated ? ' <strong>'.wfMsg('confirmaccount-econf').'</strong>' : '';
572 - $r .= '<tr><td><strong>'.wfMsg('confirmaccount-email').'</strong></td><td width=\'100%\'>'.$row->acr_email.$econf.'</td></tr>';
 587+ $r .= '<tr><td><strong>'.wfMsg('confirmaccount-email').'</strong></td><td width=\'100%\'>' .
 588+ htmlspecialchars($row->acr_email) . $econf.'</td></tr>';
573589 # Truncate this, blah blah...
574 - $bio = substr( $row->acr_bio, 0, 500 );
 590+ $bio = substr( htmlspecialchars($row->acr_bio), 0, 500 );
575591 $bio = strlen($bio) < strlen($row->acr_bio) ? "$bio . . ." : $bio;
576592
577593 $r .= '<tr><td><strong>'.wfMsg('confirmaccount-bio').'</strong></td><td width=\'100%\'><i>'.$bio.'</i></td></tr>';
Index: trunk/extensions/ConfirmAccount/ConfirmAccount.i18n.php
@@ -68,7 +68,7 @@
6969 'confirmaccount-real' => 'Name',
7070 'confirmaccount-email' => 'Email',
7171 'confirmaccount-bio' => 'Biography',
72 - 'confirmaccount-review' => 'Review this request in detail',
 72+ 'confirmaccount-review' => 'Approve/Reject',
7373 'confirmacount-confirm' => 'Use the buttons below to irreversibly confirm this request and create the account or deny it.',
7474 'confirmaccount-econf' => '(confirmed)',
7575 'confirmacount-create' => 'Confirm (create account)',
@@ -85,4 +85,9 @@
8686
8787 You may have been granted a slightly different name than requested. This could be due to name collisions
8888 or policy reasons. Also, please immediatly login, go to your preferences options, and set a new password.',
89 -);
 89+ 'confirmaccount-email-body2' => 'Sorry, your request for an account "$1" has been rejected on {{SITENAME}}.
 90+
 91+There are several ways this can happen. You may not have filled out the form correctly, did not provide adequate
 92+length in your responses, or otherwise failed to meet some policy criteria. There may be contact lists on site that
 93+you can use if you want to know more about user account policy.',
 94+);
\ No newline at end of file

Status & tagging log