コード例 #1
0
function axACWRequestCheckBirthday()
{
    global $wgRequest;
    $sYear = $wgRequest->getVal('year');
    $sMonth = $wgRequest->getVal('month');
    $sDay = $wgRequest->getVal('day');
    $errDiv = "wiki-birthday-error";
    $sResponse = AutoCreateWiki::checkBirthdayIsCorrect($sYear, $sMonth, $sDay);
    $isError = !empty($sResponse) ? true : false;
    $aResponse = array('div-body' => $sResponse, 'div-name' => $errDiv, 'div-error' => $isError);
    return json_encode($aResponse);
}
コード例 #2
0
 /**
  * create account function (see SpecialUserLogin.php to compare)
  */
 private function addNewAccount()
 {
     global $wgUser, $wgOut;
     global $wgEnableSorbs, $wgProxyWhitelist;
     global $wgMemc, $wgAccountCreationThrottle;
     global $wgAuth;
     global $wgRequest;
     wfProfileIn(__METHOD__);
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
         return false;
     }
     $ip = $wgRequest->getIP();
     #-- check username
     $sResponse = AutoCreateWiki::checkUsernameIsCorrect($this->mUsername);
     if (!empty($sResponse)) {
         $this->makeError("wiki-username", $sResponse);
     }
     #-- check email
     $sResponse = AutoCreateWiki::checkEmailIsCorrect($this->mEmail);
     if (!empty($sResponse)) {
         $this->makeError("wiki-email", $sResponse);
     }
     #-- check if the date has been choosen
     $sResponse = AutoCreateWiki::checkBirthdayIsCorrect($this->mUser_year, $this->mUser_month, $this->mUser_day);
     if (!empty($sResponse)) {
         $this->makeError("wiki-birthday", $sResponse);
     }
     # Check permissions
     if (!$wgUser->isAllowed('createaccount')) {
         $this->makeError("wiki-username", wfMsg('autocreatewiki-blocked-username'));
     } elseif ($wgUser->isBlockedFromCreateAccount()) {
         $blocker = User::whoIs($wgUser->mBlock->mBy);
         $block_reason = $wgUser->mBlock->mReason;
         if (strval($block_reason) === '') {
             $block_reason = wfMsg('blockednoreason');
         }
         $this->makeError("wiki-username", wfMsg('autocreatewiki-blocked-username', $ip, $block_reason, $blocker));
     }
     $ip = $wgRequest->getIP();
     if ($wgEnableSorbs && !in_array($ip, $wgProxyWhitelist) && $wgUser->inSorbsBlacklist($ip)) {
         $this->makeError("wiki-username", wfMsg('sorbs_create_account_reason') . ' (' . htmlspecialchars($ip) . ')');
     }
     $sResponse = AutoCreateWiki::checkPasswordIsCorrect($this->mUsername, $this->mPassword);
     if (!empty($sResponse)) {
         $this->makeError("wiki-password", $sResponse);
     }
     $sResponse = AutoCreateWiki::checkRetypePasswordIsCorrect($this->mPassword, $this->mRetype_password);
     if (!empty($sResponse)) {
         $this->makeError("wiki-retype-password", $sResponse);
     }
     # Now create a dummy user ($oUser) and check if it is valid
     $name = trim($this->mUsername);
     $oUser = User::newFromName($name, 'creatable');
     $oExtUser = ExternalUser::newFromName($this->mUsername);
     if (!$oUser instanceof User) {
         $this->makeError("wiki-username", wfMsg('noname'));
     } elseif (is_object($oExtUser) && 0 != $oExtUser->getId()) {
         $this->makeError("wiki-username", wfMsg('userexists'));
     } elseif (0 != $oUser->idForName()) {
         $this->makeError("wiki-username", wfMsg('userexists'));
     } else {
         # Set some additional data so the AbortNewAccount hook can be
         # used for more than just username validation
         $oUser->setEmail($this->mEmail);
         $abortError = '';
         if (!wfRunHooks('AbortNewAccount', array($oUser, &$abortError))) {
             // Hook point to add extra creation throttles and blocks
             wfDebug("LoginForm::addNewAccountInternal: a hook blocked creation\n");
             $this->makeError("wiki-blurry-word", $abortError);
         } else {
             if ($wgAccountCreationThrottle && $wgUser->isPingLimitable()) {
                 $key = wfMemcKey('acctcreate', 'ip', $ip);
                 $value = $wgMemc->incr($key);
                 if (!$value) {
                     $wgMemc->set($key, 1, 86400);
                 }
                 if ($value > $wgAccountCreationThrottle) {
                     $this->makeError("wiki-username", wfMsgExt('acct_creation_throttle_hit', array("parse"), $wgAccountCreationThrottle));
                 }
             }
             if (empty($this->mErrors) && !$wgAuth->addUser($oUser, $this->mPassword, $this->mEmail, "")) {
                 $this->makeError("wiki-username", wfMsg('externaldberror'));
             }
         }
     }
     if ($this->mErrors > 0) {
         $oUser = null;
     } else {
         $userBirthDay = strtotime("{$this->mUser_year}-{$this->mUser_month}-{$this->mUser_day}");
         $oUser->mBirthDate = $userBirthDay;
         $oUser = $this->initUser($oUser, false);
         $user_id = $oUser->getID();
         if (!empty($user_id)) {
             global $wgExternalSharedDB;
             $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB);
             $dbw->update('`user`', array('user_birthdate' => date('Y-m-d', $userBirthDay)), array('user_id' => $user_id), __METHOD__);
         }
         $result = $oUser->sendConfirmationMail();
     }
     wfProfileOut(__METHOD__);
     return $oUser;
 }