/** * Validates user names. * * @Author CorfiX (corfix@wikia.com) * @Author Maciej Błaszkowski <marooned at wikia-inc.com> * * @Param String $uName * * @Return String */ function cxValidateUserName() { global $wgRequest; wfProfileIn(__METHOD__); $uName = $wgRequest->getVal('uName'); $result = wfValidateUserName($uName); if ($result === true) { $message = ''; if (!wfRunHooks("cxValidateUserName", array($uName, &$message))) { $result = $message; } } if ($result === true) { $data = array('result' => 'OK'); } else { $data = array('result' => 'INVALID', 'msg' => wfMsg($result), 'msgname' => $result); } $json = json_encode($data); $response = new AjaxResponse($json); $response->setContentType('application/json; charset=utf-8'); $response->setCacheDuration(60); wfProfileOut(__METHOD__); return $response; }
public static function userNameOK($uName) { return 'OK' == wfValidateUserName($uName); }
/** * Validates username user enters on rename account form * * @author grunny */ private function validateUserName($userName) { global $wgWikiaMaxNameChars; if ($userName == '') { $this->err[] = $this->msg('userlogin-error-noname')->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } // check username length if (!User::isNotMaxNameChars($userName)) { $this->err[] = $this->msg('usersignup-error-username-length', $wgWikiaMaxNameChars)->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } // check valid username if (!User::isCreatableName($userName)) { $this->err[] = $this->msg('usersignup-error-symbols-in-username')->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } $result = wfValidateUserName($userName); if ($result === true) { $msgKey = ''; if (!wfRunHooks('cxValidateUserName', array($userName, &$msgKey))) { $result = $msgKey; } } if ($result !== true) { $msg = ''; if ($result === 'userlogin-bad-username-taken') { $msg = $this->msg('userlogin-error-userexists')->escaped(); } else { if ($result === 'userlogin-bad-username-character') { $msg = $this->msg('usersignup-error-symbols-in-username')->escaped(); } else { if ($result === 'userlogin-bad-username-length') { $msg = $this->msg('usersignup-error-username-length', $wgWikiaMaxNameChars)->escaped(); } } } $this->err[] = empty($msg) ? $result : $msg; $this->errInputs['wpUserNameNew'] = true; return false; } return true; }
public function initValidationUsername() { // check empty username if ($this->mUsername == '') { $this->mainLoginForm(wfMessage('userlogin-error-noname')->escaped(), 'error', 'username'); return false; } // check username length if (!User::isNotMaxNameChars($this->mUsername)) { global $wgWikiaMaxNameChars; $this->mainLoginForm(wfMessage('usersignup-error-username-length', $wgWikiaMaxNameChars)->escaped(), 'error', 'username'); return false; } // check valid username if (!User::getCanonicalName($this->mUsername, 'creatable')) { $this->mainLoginForm(wfMessage('usersignup-error-symbols-in-username')->escaped(), 'error', 'username'); return false; } $app = F::app(); $result = wfValidateUserName($this->mUsername); if ($result === true) { $msgKey = ''; if (!wfRunHooks('cxValidateUserName', array($this->mUsername, &$msgKey))) { $result = $msgKey; } } if ($result !== true) { $msg = ''; if ($result == 'userlogin-bad-username-taken') { $msg = wfMessage('userlogin-error-userexists')->escaped(); } else { if ($result == 'userlogin-bad-username-character') { $msg = wfMessage('usersignup-error-symbols-in-username')->escaped(); } else { if ($result == 'userlogin-bad-username-length') { $msg = wfMessage('usersignup-error-username-length', $app->wg->WikiaMaxNameChars)->escaped(); } else { $msg = $result; } } } $this->mainLoginForm($msg, 'error', 'username'); return false; } return true; }