diff --git a/ConfirmAccount/frontend/specialpages/actions/RequestAccount_body.php b/ConfirmAccount/frontend/specialpages/actions/RequestAccount_body.php deleted file mode 100644 index 20be5e0..0000000 --- a/ConfirmAccount/frontend/specialpages/actions/RequestAccount_body.php +++ /dev/null @@ -1,411 +0,0 @@ -getUser(); - $request = $this->getRequest(); - - $block = ConfirmAccount::getAccountRequestBlock( $reqUser ); - if ( $block ) { - throw new UserBlockedError( $block ); - } elseif ( wfReadOnly() ) { - throw new ReadOnlyError(); - } - - - - $this->setHeaders(); - - //$this->mRealName = trim( $request->getText( 'wpRealName' ) ); - # We may only want real names being used - $this->mUsername = !$this->hasItem( 'UserName' ) - ? $this->mRealName - : $request->getText( 'wpUsername' ); - $this->mUsername = trim( $this->mUsername ); - # CV/resume attachment... - if ( $this->hasItem( 'CV' ) ) { - $this->initializeUpload( $request ); - $this->mPrevAttachment = $request->getText( 'attachment' ); - $this->mForgotAttachment = $request->getBool( 'forgotAttachment' ); - } - # Other identifying fields... - $this->mEmail = trim( $request->getText( 'wpEmail' ) ); - //$this->mBio = $this->hasItem( 'Biography' ) ? $request->getText( 'wpBio', '' ) : ''; - $this->mNotes = $this->hasItem( 'Notes' ) ? $request->getText( 'wpNotes', '' ) : ''; - //$this->mUrls = $this->hasItem( 'Links' ) ? $request->getText( 'wpUrls', '' ) : ''; - # Site terms of service... - $this->mToS = $this->hasItem( 'TermsOfService' ) ? $request->getBool( 'wpToS' ) : false; - # Which account request queue this belongs in... - $this->mType = $request->getInt( 'wpType' ); - $this->mType = isset( $wgAccountRequestTypes[$this->mType] ) ? $this->mType : 0; - # Load areas user plans to be active in... - $this->mAreas = array(); - if ( $this->hasItem( 'AreasOfInterest' ) ) { - foreach ( ConfirmAccount::getUserAreaConfig() as $name => $conf ) { - $formName = "wpArea-" . htmlspecialchars( str_replace( ' ', '_', $name ) ); - $this->mAreas[$name] = $request->getInt( $formName, -1 ); - } - } - # We may be confirming an email address here - $emailCode = $request->getText( 'wpEmailToken' ); - - $action = $request->getVal( 'action' ); - if ( $request->wasPosted() - && $reqUser->matchEditToken( $request->getVal( 'wpEditToken' ) ) ) - { - $this->mPrevAttachment = $this->mPrevAttachment - ? $this->mPrevAttachment - : $this->mSrcName; - $this->doSubmit(); - } elseif ( $action == 'confirmemail' ) { - $this->confirmEmailToken( $emailCode ); - } else { - $this->showForm(); - } - - $this->getOutput()->addModules( 'ext.confirmAccount' ); // CSS - } - - protected function showForm( $msg = '', $forgotFile = 0 ) { - global $wgAccountRequestTypes, $wgMakeUserPageFromBio; - - $reqUser = $this->getUser(); - - $this->mForgotAttachment = $forgotFile; - - $out = $this->getOutput(); - $out->setPagetitle( $this->msg( "requestaccount" )->escaped() ); - # Output failure message if any - if ( $msg ) { - $out->addHTML( '
" . Xml::submitButton( $this->msg( 'requestaccount-submit' )->text() ) . "
"; - $form .= Xml::closeElement( 'form' ); - - $out->addHTML( $form ); - - $out->addWikiMsg( 'requestaccount-footer' ); - } - - protected function hasItem( $name ) { - global $wgConfirmAccountRequestFormItems; - - return $wgConfirmAccountRequestFormItems[$name]['enabled']; - } - - protected function doSubmit() { - # Now create a dummy user ($u) and check if it is valid - $name = trim( $this->mUsername ); - $u = User::newFromName( $name, 'creatable' ); - if ( !$u ) { - $this->showForm( $this->msg( 'noname' )->escaped() ); - return; - } - # Set some additional data so the AbortNewAccount hook can be - # used for more than just username validation - $u->setEmail( $this->mEmail ); - $u->setRealName( $this->mRealName ); - # FIXME: Hack! If we don't want captchas for requests, temporarily turn it off! - global $wgConfirmAccountCaptchas, $wgCaptchaTriggers; - if ( !$wgConfirmAccountCaptchas && isset( $wgCaptchaTriggers ) ) { - $old = $wgCaptchaTriggers['createaccount']; - $wgCaptchaTriggers['createaccount'] = false; - } - $abortError = ''; - if ( !wfRunHooks( 'AbortNewAccount', array( $u, &$abortError ) ) ) { - // Hook point to add extra creation throttles and blocks - wfDebug( "RequestAccount::doSubmit: a hook blocked creation\n" ); - $this->showForm( $abortError ); - return; - } - # Set it back! - if ( !$wgConfirmAccountCaptchas && isset( $wgCaptchaTriggers ) ) { - $wgCaptchaTriggers['createaccount'] = $old; - } - - # Build submission object... - $areaSet = array(); // make a simple list of interests - foreach ( $this->mAreas as $area => $val ) { - if ( $val > 0 ) { - $areaSet[] = $area; - } - } - - $submission = new AccountRequestSubmission( - $this->getUser(), - array( - 'userName' => $name, - 'realName' => $this->mRealName, - 'tosAccepted' => $this->mToS, - 'email' => $this->mEmail, - 'bio' => $this->mBio, - 'notes' => $this->mNotes, - 'urls' => $this->mUrls, - 'type' => $this->mType, - 'areas' => $areaSet, - 'registration' => wfTimestampNow(), - 'ip' => $this->getRequest()->getIP(), - 'xff' => $this->getRequest()->getHeader( 'X-Forwarded-For' ), - 'agent' => $this->getRequest()->getHeader( 'User-Agent' ), - 'attachmentPrevName' => $this->mPrevAttachment, - 'attachmentSrcName' => $this->mSrcName, - 'attachmentDidNotForget' => $this->mForgotAttachment, // confusing name :) - 'attachmentSize' => $this->mFileSize, - 'attachmentTempPath' => $this->mTempPath - ) - ); - - # Actually submit! - list( $status, $msg ) = $submission->submit( $this->getContext() ); - # Account for state changes - $this->mForgotAttachment = $submission->getAttachmentDidNotForget(); - $this->mPrevAttachment = $submission->getAttachtmentPrevName(); - # Check for error messages - if ( $status !== true ) { - $this->showForm( $msg ); - return; - } - - # Done! - $this->showSuccess(); - } - - protected function showSuccess() { - $out = $this->getOutput(); - $out->setPagetitle( $this->msg( "requestaccount" )->escaped() ); - $out->addWikiMsg( 'requestaccount-sent' ); - $out->returnToMain(); - } - - /** - * Initialize the uploaded file from PHP data - * @param $request WebRequest - */ - protected function initializeUpload( $request ) { - $file = new WebRequestUpload( $request, 'wpUploadFile' ); - $this->mTempPath = $file->getTempName(); - $this->mFileSize = $file->getSize(); - $this->mSrcName = $file->getName(); - } - - /** - * (a) Try to confirm an email address via a token - * (b) Notify $wgConfirmAccountContact on success - * @param $code string The token - * @return void - */ - protected function confirmEmailToken( $code ) { - global $wgConfirmAccountContact, $wgPasswordSender, $wgPasswordSenderName; - - $reqUser = $this->getUser(); - $out = $this->getOutput(); - # Confirm if this token is in the pending requests - $name = ConfirmAccount::requestNameFromEmailToken( $code ); - if ( $name !== false ) { - # Send confirmation email to prospective user - ConfirmAccount::confirmEmail( $name ); - # Send mail to admin after e-mail has been confirmed - if ( $wgConfirmAccountContact != '' ) { - $target = new MailAddress( $wgConfirmAccountContact ); - $source = new MailAddress( $wgPasswordSender, $wgPasswordSenderName ); - $title = SpecialPage::getTitleFor( 'ConfirmAccounts' ); - $subject = $this->msg( 'requestaccount-email-subj-admin' )->inContentLanguage()->escaped(); - $body = $this->msg( - 'requestaccount-email-body-admin', $name )->rawParams( $title->getFullUrl() )->inContentLanguage()->escaped(); - # Actually send the email... - $result = UserMailer::send( $target, $source, $subject, $body ); - if ( !$result->isOK() ) { - wfDebug( "Could not sent email to admin at $target\n" ); - } - } - $out->addWikiMsg( 'request-account-econf' ); - $out->returnToMain(); - } else { - # Maybe the user confirmed after account was created... - $user = User::newFromConfirmationCode( $code ); - if ( is_object( $user ) ) { - if ( $user->confirmEmail() ) { - $message = $reqUser->isLoggedIn() - ? 'confirmemail_loggedin' - : 'confirmemail_success'; - $out->addWikiMsg( $message ); - if ( !$reqUser->isLoggedIn() ) { - $title = SpecialPage::getTitleFor( 'Userlogin' ); - $out->returnToMain( true, $title->getPrefixedUrl() ); - } - } else { - $out->addWikiMsg( 'confirmemail_error' ); - } - } else { - $out->addWikiMsg( 'confirmemail_invalid' ); - } - } - } -}