X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContact%2FPage%2FAJAX.php;h=85c1cbf39f3dc9383133420bae2b7ff5f0820aa9;hb=272081ca255b523b753cf3542cbb981198eb2a72;hp=4dbb69d595da65b5b3066f1c5d42ec04b9d79dff;hpb=8c0ea1d7e8bdddcd0e10acfa6c444551fdb6c0f8;p=civicrm-core.git diff --git a/CRM/Contact/Page/AJAX.php b/CRM/Contact/Page/AJAX.php index 4dbb69d595..85c1cbf39f 100644 --- a/CRM/Contact/Page/AJAX.php +++ b/CRM/Contact/Page/AJAX.php @@ -36,6 +36,13 @@ * This class contains all contact related functions that are called using AJAX (jQuery) */ class CRM_Contact_Page_AJAX { + /** + * When a user chooses a username, CHECK_USERNAME_TTL + * is the time window in which they can check usernames + * (without reloading the overall form). + */ + const CHECK_USERNAME_TTL = 10800; // 3hr; 3*60*60 + static function getContactList() { // if context is 'customfield' if (CRM_Utils_Array::value('context', $_GET) == 'customfield') { @@ -615,6 +622,17 @@ WHERE sort_name LIKE '%$name%'"; * */ static public function checkUserName() { + $signer = new CRM_Utils_Signer(CRM_Core_Key::privateKey(), array('for', 'ts')); + if ( + CRM_Utils_Time::getTimeRaw() > $_REQUEST['ts'] + self::CHECK_USERNAME_TTL + || $_REQUEST['for'] != 'civicrm/ajax/cmsuser' + || !$signer->validate($_REQUEST['sig'], $_REQUEST) + ) { + $user = array('name' => 'error'); + echo json_encode($user); + CRM_Utils_System::civiExit(); + } + $config = CRM_Core_Config::singleton(); $username = trim($_REQUEST['cms_name']);