MediaWiki
REL1_24
|
00001 <?php 00032 class EmailConfirmation extends UnlistedSpecialPage { 00033 public function __construct() { 00034 parent::__construct( 'Confirmemail', 'editmyprivateinfo' ); 00035 } 00036 00042 function execute( $code ) { 00043 $this->setHeaders(); 00044 00045 $this->checkReadOnly(); 00046 $this->checkPermissions(); 00047 00048 $this->requireLogin( 'confirmemail_needlogin' ); 00049 00050 // This could also let someone check the current email address, so 00051 // require both permissions. 00052 if ( !$this->getUser()->isAllowed( 'viewmyprivateinfo' ) ) { 00053 throw new PermissionsError( 'viewmyprivateinfo' ); 00054 } 00055 00056 if ( $code === null || $code === '' ) { 00057 if ( Sanitizer::validateEmail( $this->getUser()->getEmail() ) ) { 00058 $this->showRequestForm(); 00059 } else { 00060 $this->getOutput()->addWikiMsg( 'confirmemail_noemail' ); 00061 } 00062 } else { 00063 $this->attemptConfirm( $code ); 00064 } 00065 } 00066 00070 function showRequestForm() { 00071 $user = $this->getUser(); 00072 $out = $this->getOutput(); 00073 00074 if ( $this->getRequest()->wasPosted() && 00075 $user->matchEditToken( $this->getRequest()->getText( 'token' ) ) 00076 ) { 00077 $status = $user->sendConfirmationMail(); 00078 if ( $status->isGood() ) { 00079 $out->addWikiMsg( 'confirmemail_sent' ); 00080 } else { 00081 $out->addWikiText( $status->getWikiText( 'confirmemail_sendfailed' ) ); 00082 } 00083 } elseif ( $user->isEmailConfirmed() ) { 00084 // date and time are separate parameters to facilitate localisation. 00085 // $time is kept for backward compat reasons. 00086 // 'emailauthenticated' is also used in SpecialPreferences.php 00087 $lang = $this->getLanguage(); 00088 $emailAuthenticated = $user->getEmailAuthenticationTimestamp(); 00089 $time = $lang->userTimeAndDate( $emailAuthenticated, $user ); 00090 $d = $lang->userDate( $emailAuthenticated, $user ); 00091 $t = $lang->userTime( $emailAuthenticated, $user ); 00092 $out->addWikiMsg( 'emailauthenticated', $time, $d, $t ); 00093 } else { 00094 if ( $user->isEmailConfirmationPending() ) { 00095 $out->wrapWikiMsg( 00096 "<div class=\"error mw-confirmemail-pending\">\n$1\n</div>", 00097 'confirmemail_pending' 00098 ); 00099 } 00100 00101 $out->addWikiMsg( 'confirmemail_text' ); 00102 $form = Html::openElement( 00103 'form', 00104 array( 'method' => 'post', 'action' => $this->getPageTitle()->getLocalURL() ) 00105 ) . "\n"; 00106 $form .= Html::hidden( 'token', $user->getEditToken() ) . "\n"; 00107 $form .= Xml::submitButton( $this->msg( 'confirmemail_send' )->text() ) . "\n"; 00108 $form .= Html::closeElement( 'form' ) . "\n"; 00109 $out->addHTML( $form ); 00110 } 00111 } 00112 00119 function attemptConfirm( $code ) { 00120 $user = User::newFromConfirmationCode( $code ); 00121 if ( !is_object( $user ) ) { 00122 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); 00123 00124 return; 00125 } 00126 00127 $user->confirmEmail(); 00128 $user->saveSettings(); 00129 $message = $this->getUser()->isLoggedIn() ? 'confirmemail_loggedin' : 'confirmemail_success'; 00130 $this->getOutput()->addWikiMsg( $message ); 00131 00132 if ( !$this->getUser()->isLoggedIn() ) { 00133 $title = SpecialPage::getTitleFor( 'Userlogin' ); 00134 $this->getOutput()->returnToMain( true, $title ); 00135 } 00136 } 00137 } 00138 00145 class EmailInvalidation extends UnlistedSpecialPage { 00146 public function __construct() { 00147 parent::__construct( 'Invalidateemail', 'editmyprivateinfo' ); 00148 } 00149 00150 function execute( $code ) { 00151 $this->setHeaders(); 00152 $this->checkReadOnly(); 00153 $this->checkPermissions(); 00154 $this->attemptInvalidate( $code ); 00155 } 00156 00163 function attemptInvalidate( $code ) { 00164 $user = User::newFromConfirmationCode( $code ); 00165 if ( !is_object( $user ) ) { 00166 $this->getOutput()->addWikiMsg( 'confirmemail_invalid' ); 00167 00168 return; 00169 } 00170 00171 $user->invalidateEmail(); 00172 $user->saveSettings(); 00173 $this->getOutput()->addWikiMsg( 'confirmemail_invalidated' ); 00174 00175 if ( !$this->getUser()->isLoggedIn() ) { 00176 $this->getOutput()->returnToMain(); 00177 } 00178 } 00179 }