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; }
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; }
$tpl = "%12s %-30s %-30s\n"; printf($tpl, null, 'OLD VALUE', 'NEW VALUE'); printf($tpl, 'Username', $original->getUsername(), $user->getUsername()); printf($tpl, 'Real Name', $original->getRealName(), $user->getRealName()); if ($new_email) { printf($tpl, 'Email', '', $new_email); } printf($tpl, 'Password', null, $changed_pass !== false ? 'Updated' : 'Unchanged'); printf($tpl, 'Admin', $original->getIsAdmin() ? 'Y' : 'N', $set_admin ? 'Y' : 'N'); echo "\n"; if (!phutil_console_confirm("Save these changes?", $default_no = false)) { echo "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 ($new_email) { $email = id(new PhabricatorUserEmail())->setAddress($new_email)->setIsVerified(1); $editor->createNewUser($user, $email); } else { $editor->updateUser($user); } $editor->makeAdminUser($user, $set_admin); if ($changed_pass !== false) { $envelope = new PhutilOpaqueEnvelope($changed_pass); $editor->changePassword($user, $envelope); } $user->saveTransaction();
if ($is_new) { printf($tpl, pht('Email'), '', $create_email); } printf($tpl, pht('Password'), null, $changed_pass !== false ? pht('Updated') : pht('Unchanged')); printf($tpl, pht('Bot'), $original->getIsSystemAgent() ? 'Y' : 'N', $set_system_agent ? 'Y' : 'N'); if ($verify_email) { printf($tpl, pht('Verify Email'), $verify_email->getIsVerified() ? 'Y' : 'N', $set_verified ? 'Y' : 'N'); } 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); }
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();