function autoSignup($sUsername, $sPassword, $aExtra, $oSource) { $oAuthenticator =& $this->getAuthenticator($oSource); $dn = $oAuthenticator->checkSignupPassword($sUsername, $sPassword); if (PEAR::isError($dn)) { return; } if (!is_string($dn)) { return; } if (empty($dn)) { return; } $aResults = $oAuthenticator->getUser($dn); $sUserName = $aResults[$this->aAttributes[1]]; $sName = $aResults[$this->aAttributes[0]]; $sEmailAddress = $aResults[$this->aAttributes[4]]; $sMobileNumber = $aResults[$this->aAttributes[5]]; $oUser = User::createFromArray(array("Username" => $sUserName, "Name" => $sName, "Email" => $sEmailAddress, "EmailNotification" => true, "SmsNotification" => false, "MaxSessions" => 3, "authenticationsourceid" => $oSource->getId(), "authenticationdetails" => $dn, "authenticationdetails2" => $sUserName, "password" => "")); if (PEAR::isError($oUser)) { return; } if (!is_a($oUser, 'User')) { return; } $this->_createSignupGroups($dn, $oSource); return $oUser; }
function do_createUser() { // FIXME generate and pass the error stack to adduser. $old_search = KTUtil::arrayGet($_REQUEST, 'old_search'); $aErrorOptions = array('redirect_to' => array('addUser', sprintf('old_search=%s&do_search=1', $old_search))); $aInputKeys = array('newusername', 'name', 'email_address', 'email_notifications', 'mobile_number', 'max_sessions'); $this->persistParams($aInputKeys); $username = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'newusername'), KTUtil::meldOptions($aErrorOptions, array('message' => _kt("You must specify a new username.")))); $name = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'name'), KTUtil::meldOptions($aErrorOptions, array('message' => _kt("You must provide a name")))); $email_address = KTUtil::arrayGet($_REQUEST, 'email_address'); $email_notifications = KTUtil::arrayGet($_REQUEST, 'email_notifications', false); if ($email_notifications !== false) { $email_notifications = true; } $mobile_number = KTUtil::arrayGet($_REQUEST, 'mobile_number'); $max_sessions = $this->oValidator->validateInteger(KTUtil::arrayGet($_REQUEST, 'max_sessions'), KTUtil::meldOptions($aErrorOptions, array('message' => _kt("You must specify a numeric value for maximum sessions.")))); $password = KTUtil::arrayGet($_REQUEST, 'new_password'); $confirm_password = KTUtil::arrayGet($_REQUEST, 'confirm_password'); $KTConfig =& KTConfig::getSingleton(); $minLength = (int) $KTConfig->get('user_prefs/passwordLength', 6); $restrictAdmin = (bool) $KTConfig->get('user_prefs/restrictAdminPasswords', false); if ($restrictAdmin && strlen($password) < $minLength) { $this->errorRedirectTo('addUser', sprintf(_kt("The password must be at least %d characters long."), $minLength), sprintf("old_search=%s&do_search=1", $old_search)); } else { if (empty($password)) { $this->errorRedirectTo('addUser', _kt("You must specify a password for the user."), sprintf("old_search=%s&do_search=1", $old_search)); } else { if ($password !== $confirm_password) { $this->errorRedirectTo('addUser', _kt("The passwords you specified do not match."), sprintf("old_search=%s&do_search=1", $old_search)); } } } if (preg_match('/[\\!\\$\\#\\%\\^\\&\\*]/', $username)) { $this->errorRedirectTo('addUser', _kt("You have entered an invalid character in your username.")); } if (preg_match('/[\\!\\$\\#\\%\\^\\&\\*]/', $name)) { $this->errorRedirectTo('addUser', _kt("You have entered an invalid character in your name.")); } $dupUser =& User::getByUserName($username); if (!PEAR::isError($dupUser)) { $this->errorRedirectTo('addUser', _kt("A user with that username already exists")); } $oUser =& User::createFromArray(array("sUsername" => $username, "sName" => $name, "sPassword" => md5($password), "iQuotaMax" => 0, "iQuotaCurrent" => 0, "sEmail" => $email_address, "bEmailNotification" => $email_notifications, "sMobile" => $mobile_number, "bSmsNotification" => false, "iMaxSessions" => $max_sessions)); if (PEAR::isError($oUser) || $oUser == false) { $this->errorRedirectToMain(_kt("failed to create user."), sprintf("old_search=%s&do_search=1", $old_search)); exit(0); } $this->successRedirectToMain(_kt('Created new user') . ': ' . $oUser->getUsername(), 'name=' . $oUser->getUsername(), sprintf("old_search=%s&do_search=1", $old_search)); }
/** * Get a single user-document, identified by the username * * This will throw if the document cannot be fetched from the server * * @throws Exception * * @param mixed $username - username as a string * * @return User - the user-document fetched from the server */ public function get($username) { $url = UrlHelper::buildUrl(Urls::URL_USER, array($username)); $response = $this->getConnection()->get($url); $data = $response->getJson(); $options = array('_isNew' => false); return User::createFromArray($data, $options); }