protected function generateNewTestUser() { $seed = $this->getNextObjectSeed(); $user = id(new PhabricatorUser())->setRealName("Test User {$seed}}")->setUserName("test{$seed}")->setIsApproved(1); $email = id(new PhabricatorUserEmail())->setAddress("testuser{$seed}@example.com")->setIsVerified(1); $editor = new PhabricatorUserEditor(); $editor->setActor($user); $editor->createNewUser($user, $email); return $user; }
printf($tpl, pht('Admin'), $original->getIsAdmin() ? 'Y' : 'N', $set_admin ? 'Y' : 'N'); echo "\n"; if (!phutil_console_confirm(pht('Save these changes?'), $default_no = false)) { echo pht('Cancelled.') . "\n"; exit(1); } $user->openTransaction(); $editor = new PhabricatorUserEditor(); // TODO: This is wrong, but we have a chicken-and-egg problem when you use // this script to create the first user. $editor->setActor($user); if ($is_new) { $email = id(new PhabricatorUserEmail())->setAddress($create_email)->setIsVerified(1); // Unconditionally approve new accounts created from the CLI. $user->setIsApproved(1); $editor->createNewUser($user, $email); } else { if ($verify_email) { $user->setIsEmailVerified(1); $verify_email->setIsVerified($set_verified ? 1 : 0); } $editor->updateUser($user, $verify_email); } $editor->makeAdminUser($user, $set_admin); $editor->makeSystemAgentUser($user, $set_system_agent); if ($changed_pass !== false) { $envelope = new PhutilOpaqueEnvelope($changed_pass); $editor->changePassword($user, $envelope); } $user->saveTransaction(); echo pht('Saved changes.') . "\n";
protected function generateNewTestUser() { $seed = $this->getNextObjectSeed(); $user = id(new PhabricatorUser())->setRealName(pht('Test User %s', $seed))->setUserName("test{$seed}")->setIsApproved(1); $email = id(new PhabricatorUserEmail())->setAddress("testuser{$seed}@example.com")->setIsVerified(1); $editor = new PhabricatorUserEditor(); $editor->setActor($user); $editor->createNewUser($user, $email); // When creating a new test user, we prefill their setting cache as empty. // This is a little more efficient than doing a query to load the empty // settings. $user->attachRawCacheData(array(PhabricatorUserPreferencesCacheType::KEY_PREFERENCES => '[]')); return $user; }
if ($is_first_user) { echo "You must first create an admin user before being able to create a system agent.\n"; exit(1); } $username = $argv[1]; $email = $argv[2]; $realname = $argv[3]; if (!PhabricatorUser::validateUsername($username)) { $valid = PhabricatorUser::describeValidUsername(); echo "The username '{$username}' is invalid. {$valid}\n"; exit(1); } $existing_user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username); if ($existing_user) { throw new Exception("There is already a user with the username '{$username}'!"); } $existing_email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $email); if ($existing_email) { throw new Exception("There is already a user with the email '{$email}'!"); } $user_object = new PhabricatorUser(); $user_object->setUsername($username); $user_object->setRealname($realname); $user_object->setIsApproved(1); $user_object->openTransaction(); $email_object = id(new PhabricatorUserEmail())->setAddress($email)->setIsVerified(1); $editor = new PhabricatorUserEditor(); $editor->setActor($user_object); $editor->createNewUser($user_object, $email_object); $editor->makeSystemAgentUser($user_object, true); $user_object->saveTransaction();