@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove "bin/accountadmin" and "scripts/user/add_user.php"

Summary:
Fixes T13382. Depends on D20724. These ancient scripts are no longer necessary since we've had a smooth web-based onboarding process for a long time.

I retained `bin/user empower` and `bin/user enable` for recovering from situations where you accidentally delete or disable all administrators. This is normally difficult, but some users are industrious.

Test Plan: Grepped for `accountadmin` and `add_user.php`, found no more hits.

Maniphest Tasks: T13382

Differential Revision: https://secure.phabricator.com/D20725

+2 -326
-1
bin/accountadmin
··· 1 - ../scripts/user/account_admin.php
-228
scripts/user/account_admin.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - $root = dirname(dirname(dirname(__FILE__))); 5 - require_once $root.'/scripts/__init_script__.php'; 6 - 7 - $table = new PhabricatorUser(); 8 - $any_user = queryfx_one( 9 - $table->establishConnection('r'), 10 - 'SELECT * FROM %T LIMIT 1', 11 - $table->getTableName()); 12 - $is_first_user = (!$any_user); 13 - 14 - if ($is_first_user) { 15 - echo pht( 16 - "WARNING\n\n". 17 - "You're about to create the first account on this install. Normally, ". 18 - "you should use the web interface to create the first account, not ". 19 - "this script.\n\n". 20 - "If you use the web interface, it will drop you into a nice UI workflow ". 21 - "which gives you more help setting up your install. If you create an ". 22 - "account with this script instead, you will skip the setup help and you ". 23 - "will not be able to access it later."); 24 - if (!phutil_console_confirm(pht('Skip easy setup and create account?'))) { 25 - echo pht('Cancelled.')."\n"; 26 - exit(1); 27 - } 28 - } 29 - 30 - echo pht( 31 - 'Enter a username to create a new account or edit an existing account.'); 32 - 33 - $username = phutil_console_prompt(pht('Enter a username:')); 34 - if (!strlen($username)) { 35 - echo pht('Cancelled.')."\n"; 36 - exit(1); 37 - } 38 - 39 - if (!PhabricatorUser::validateUsername($username)) { 40 - $valid = PhabricatorUser::describeValidUsername(); 41 - echo pht("The username '%s' is invalid. %s", $username, $valid)."\n"; 42 - exit(1); 43 - } 44 - 45 - 46 - $user = id(new PhabricatorUser())->loadOneWhere( 47 - 'username = %s', 48 - $username); 49 - 50 - if (!$user) { 51 - $original = new PhabricatorUser(); 52 - 53 - echo pht("There is no existing user account '%s'.", $username)."\n"; 54 - $ok = phutil_console_confirm( 55 - pht("Do you want to create a new '%s' account?", $username), 56 - $default_no = false); 57 - if (!$ok) { 58 - echo pht('Cancelled.')."\n"; 59 - exit(1); 60 - } 61 - $user = new PhabricatorUser(); 62 - $user->setUsername($username); 63 - 64 - $is_new = true; 65 - } else { 66 - $original = clone $user; 67 - 68 - echo pht("There is an existing user account '%s'.", $username)."\n"; 69 - $ok = phutil_console_confirm( 70 - pht("Do you want to edit the existing '%s' account?", $username), 71 - $default_no = false); 72 - if (!$ok) { 73 - echo pht('Cancelled.')."\n"; 74 - exit(1); 75 - } 76 - 77 - $is_new = false; 78 - } 79 - 80 - $user_realname = $user->getRealName(); 81 - if (strlen($user_realname)) { 82 - $realname_prompt = ' ['.$user_realname.']:'; 83 - } else { 84 - $realname_prompt = ':'; 85 - } 86 - $realname = nonempty( 87 - phutil_console_prompt(pht('Enter user real name').$realname_prompt), 88 - $user_realname); 89 - $user->setRealName($realname); 90 - 91 - // When creating a new user we prompt for an email address; when editing an 92 - // existing user we just skip this because it would be quite involved to provide 93 - // a reasonable CLI interface for editing multiple addresses and managing email 94 - // verification and primary addresses. 95 - 96 - $create_email = null; 97 - if ($is_new) { 98 - do { 99 - $email = phutil_console_prompt(pht('Enter user email address:')); 100 - $duplicate = id(new PhabricatorUserEmail())->loadOneWhere( 101 - 'address = %s', 102 - $email); 103 - if ($duplicate) { 104 - echo pht( 105 - "ERROR: There is already a user with that email address. ". 106 - "Each user must have a unique email address.\n"); 107 - } else { 108 - break; 109 - } 110 - } while (true); 111 - 112 - $create_email = $email; 113 - } 114 - 115 - $is_system_agent = $user->getIsSystemAgent(); 116 - $set_system_agent = phutil_console_confirm( 117 - pht('Is this user a bot?'), 118 - $default_no = !$is_system_agent); 119 - 120 - $verify_email = null; 121 - $set_verified = false; 122 - // Allow administrators to verify primary email addresses at this time in edit 123 - // scenarios. (Create will work just fine from here as we auto-verify email 124 - // on create.) 125 - if (!$is_new) { 126 - $verify_email = $user->loadPrimaryEmail(); 127 - if (!$verify_email->getIsVerified()) { 128 - $set_verified = phutil_console_confirm( 129 - pht('Should the primary email address be verified?'), 130 - $default_no = true); 131 - } else { 132 - // Already verified so let's not make a fuss. 133 - $verify_email = null; 134 - } 135 - } 136 - 137 - $is_admin = $user->getIsAdmin(); 138 - $set_admin = phutil_console_confirm( 139 - pht('Should this user be an administrator?'), 140 - $default_no = !$is_admin); 141 - 142 - echo "\n\n".pht('ACCOUNT SUMMARY')."\n\n"; 143 - $tpl = "%12s %-30s %-30s\n"; 144 - printf($tpl, null, pht('OLD VALUE'), pht('NEW VALUE')); 145 - printf($tpl, pht('Username'), $original->getUsername(), $user->getUsername()); 146 - printf($tpl, pht('Real Name'), $original->getRealName(), $user->getRealName()); 147 - if ($is_new) { 148 - printf($tpl, pht('Email'), '', $create_email); 149 - } 150 - 151 - printf( 152 - $tpl, 153 - pht('Bot'), 154 - $original->getIsSystemAgent() ? 'Y' : 'N', 155 - $set_system_agent ? 'Y' : 'N'); 156 - 157 - if ($verify_email) { 158 - printf( 159 - $tpl, 160 - pht('Verify Email'), 161 - $verify_email->getIsVerified() ? 'Y' : 'N', 162 - $set_verified ? 'Y' : 'N'); 163 - } 164 - 165 - printf( 166 - $tpl, 167 - pht('Admin'), 168 - $original->getIsAdmin() ? 'Y' : 'N', 169 - $set_admin ? 'Y' : 'N'); 170 - 171 - echo "\n"; 172 - 173 - if (!phutil_console_confirm(pht('Save these changes?'), $default_no = false)) { 174 - echo pht('Cancelled.')."\n"; 175 - exit(1); 176 - } 177 - 178 - $user->openTransaction(); 179 - 180 - $editor = new PhabricatorUserEditor(); 181 - 182 - // TODO: This is wrong, but we have a chicken-and-egg problem when you use 183 - // this script to create the first user. 184 - $editor->setActor($user); 185 - 186 - if ($is_new) { 187 - $email = id(new PhabricatorUserEmail()) 188 - ->setAddress($create_email) 189 - ->setIsVerified(1); 190 - 191 - // Unconditionally approve new accounts created from the CLI. 192 - $user->setIsApproved(1); 193 - 194 - $editor->createNewUser($user, $email); 195 - } else { 196 - if ($verify_email) { 197 - $user->setIsEmailVerified(1); 198 - $verify_email->setIsVerified($set_verified ? 1 : 0); 199 - } 200 - $editor->updateUser($user, $verify_email); 201 - } 202 - 203 - $editor->makeSystemAgentUser($user, $set_system_agent); 204 - 205 - $xactions = array(); 206 - $xactions[] = id(new PhabricatorUserTransaction()) 207 - ->setTransactionType( 208 - PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE) 209 - ->setNewValue($set_admin); 210 - 211 - $actor = PhabricatorUser::getOmnipotentUser(); 212 - $content_source = PhabricatorContentSource::newForSource( 213 - PhabricatorConsoleContentSource::SOURCECONST); 214 - 215 - $people_application_phid = id(new PhabricatorPeopleApplication())->getPHID(); 216 - 217 - $transaction_editor = id(new PhabricatorUserTransactionEditor()) 218 - ->setActor($actor) 219 - ->setActingAsPHID($people_application_phid) 220 - ->setContentSource($content_source) 221 - ->setContinueOnNoEffect(true) 222 - ->setContinueOnMissingFields(true); 223 - 224 - $transaction_editor->applyTransactions($user, $xactions); 225 - 226 - $user->saveTransaction(); 227 - 228 - echo pht('Saved changes.')."\n";
-73
scripts/user/add_user.php
··· 1 - #!/usr/bin/env php 2 - <?php 3 - 4 - $root = dirname(dirname(dirname(__FILE__))); 5 - require_once $root.'/scripts/__init_script__.php'; 6 - 7 - if ($argc !== 5) { 8 - echo pht( 9 - "Usage: %s\n", 10 - 'add_user.php <username> <email> <realname> <admin_user>'); 11 - exit(1); 12 - } 13 - 14 - $username = $argv[1]; 15 - $email = $argv[2]; 16 - $realname = $argv[3]; 17 - $admin = $argv[4]; 18 - 19 - $admin = id(new PhabricatorUser())->loadOneWhere( 20 - 'username = %s', 21 - $argv[4]); 22 - if (!$admin) { 23 - throw new Exception( 24 - pht( 25 - 'Admin user must be the username of a valid Phabricator account, used '. 26 - 'to send the new user a welcome email.')); 27 - } 28 - 29 - $existing_user = id(new PhabricatorUser())->loadOneWhere( 30 - 'username = %s', 31 - $username); 32 - if ($existing_user) { 33 - throw new Exception( 34 - pht( 35 - "There is already a user with the username '%s'!", 36 - $username)); 37 - } 38 - 39 - $existing_email = id(new PhabricatorUserEmail())->loadOneWhere( 40 - 'address = %s', 41 - $email); 42 - if ($existing_email) { 43 - throw new Exception( 44 - pht( 45 - "There is already a user with the email '%s'!", 46 - $email)); 47 - } 48 - 49 - $user = new PhabricatorUser(); 50 - $user->setUsername($username); 51 - $user->setRealname($realname); 52 - $user->setIsApproved(1); 53 - 54 - $email_object = id(new PhabricatorUserEmail()) 55 - ->setAddress($email) 56 - ->setIsVerified(1); 57 - 58 - id(new PhabricatorUserEditor()) 59 - ->setActor($admin) 60 - ->createNewUser($user, $email_object); 61 - 62 - $welcome_engine = id(new PhabricatorPeopleWelcomeMailEngine()) 63 - ->setSender($admin) 64 - ->setRecipient($user); 65 - if ($welcome_engine->canSendMail()) { 66 - $welcome_engine->sendMail(); 67 - } 68 - 69 - echo pht( 70 - "Created user '%s' (realname='%s', email='%s').\n", 71 - $username, 72 - $realname, 73 - $email);
+2 -24
src/docs/user/configuration/configuring_accounts_and_registration.diviner
··· 49 49 ...where `<username>` is the account username you want to recover access 50 50 to. This will generate a link which will log you in as the specified user. 51 51 52 - 53 - Managing Accounts with the Web Console 54 - ====================================== 55 - 56 - To manage accounts from the web, login as an administrator account and go to 57 - `/people/` or click "People" on the homepage. Provided you're an admin, 58 - you'll see options to create or edit accounts. 59 - 60 - 61 - Manually Creating New Accounts 62 - ============================== 63 - 64 - There are two ways to manually create new accounts: via the web UI using 65 - the "People" application (this is easiest), or via the CLI using the 66 - `accountadmin` binary (this has a few more options). 67 - 68 - To use the CLI script, run: 69 - 70 - phabricator/ $ ./bin/accountadmin 71 - 72 - Some options (like changing certain account flags) are only available from 73 - the CLI. You can also use this script to make a user 74 - an administrator (if you accidentally remove your admin flag) or to create an 75 - administrative account. 52 + For more details on recovering access to accounts and unlocking objects, see 53 + @{article:User Guide: Unlocking Objects}. 76 54 77 55 78 56 Next Steps