2011-05-12 20:02:59 +02:00
|
|
|
#!/usr/bin/env php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
$root = dirname(dirname(dirname(__FILE__)));
|
|
|
|
require_once $root.'/scripts/__init_script__.php';
|
|
|
|
|
2013-12-02 20:25:42 +01:00
|
|
|
$table = new PhabricatorUser();
|
|
|
|
$any_user = queryfx_one(
|
|
|
|
$table->establishConnection('r'),
|
|
|
|
'SELECT * FROM %T LIMIT 1',
|
|
|
|
$table->getTableName());
|
|
|
|
$is_first_user = (!$any_user);
|
|
|
|
|
|
|
|
if ($is_first_user) {
|
|
|
|
echo pht(
|
|
|
|
"WARNING\n\n".
|
|
|
|
"You're about to create the first account on this install. Normally, you ".
|
|
|
|
"should use the web interface to create the first account, not this ".
|
|
|
|
"script.\n\n".
|
|
|
|
"If you use the web interface, it will drop you into a nice UI workflow ".
|
|
|
|
"which gives you more help setting up your install. If you create an ".
|
|
|
|
"account with this script instead, you will skip the setup help and you ".
|
|
|
|
"will not be able to access it later.");
|
2014-06-09 20:36:49 +02:00
|
|
|
if (!phutil_console_confirm(pht('Skip easy setup and create account?'))) {
|
|
|
|
echo pht('Cancelled.')."\n";
|
2013-12-02 20:25:42 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-09 20:36:49 +02:00
|
|
|
echo 'Enter a username to create a new account or edit an existing account.';
|
2011-05-12 20:02:59 +02:00
|
|
|
|
2014-06-09 20:36:49 +02:00
|
|
|
$username = phutil_console_prompt('Enter a username:');
|
2011-05-12 20:02:59 +02:00
|
|
|
if (!strlen($username)) {
|
|
|
|
echo "Cancelled.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-01-16 16:30:28 +01:00
|
|
|
if (!PhabricatorUser::validateUsername($username)) {
|
2012-06-06 16:09:05 +02:00
|
|
|
$valid = PhabricatorUser::describeValidUsername();
|
|
|
|
echo "The username '{$username}' is invalid. {$valid}\n";
|
2012-01-16 16:30:28 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
$user = id(new PhabricatorUser())->loadOneWhere(
|
|
|
|
'username = %s',
|
|
|
|
$username);
|
|
|
|
|
|
|
|
if (!$user) {
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
$original = new PhabricatorUser();
|
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
echo "There is no existing user account '{$username}'.\n";
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"Do you want to create a new '{$username}' account?",
|
|
|
|
$default_no = false);
|
|
|
|
if (!$ok) {
|
|
|
|
echo "Cancelled.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
$user = new PhabricatorUser();
|
|
|
|
$user->setUsername($username);
|
2012-05-07 19:29:33 +02:00
|
|
|
|
|
|
|
$is_new = true;
|
2011-05-12 20:02:59 +02:00
|
|
|
} else {
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
$original = clone $user;
|
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
echo "There is an existing user account '{$username}'.\n";
|
|
|
|
$ok = phutil_console_confirm(
|
|
|
|
"Do you want to edit the existing '{$username}' account?",
|
|
|
|
$default_no = false);
|
|
|
|
if (!$ok) {
|
|
|
|
echo "Cancelled.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-05-07 19:29:33 +02:00
|
|
|
|
|
|
|
$is_new = false;
|
2011-05-12 20:02:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$user_realname = $user->getRealName();
|
|
|
|
if (strlen($user_realname)) {
|
|
|
|
$realname_prompt = ' ['.$user_realname.']';
|
|
|
|
} else {
|
|
|
|
$realname_prompt = '';
|
|
|
|
}
|
|
|
|
$realname = nonempty(
|
|
|
|
phutil_console_prompt("Enter user real name{$realname_prompt}:"),
|
|
|
|
$user_realname);
|
|
|
|
$user->setRealName($realname);
|
|
|
|
|
2012-05-07 19:29:33 +02:00
|
|
|
// When creating a new user we prompt for an email address; when editing an
|
|
|
|
// existing user we just skip this because it would be quite involved to provide
|
|
|
|
// a reasonable CLI interface for editing multiple addresses and managing email
|
|
|
|
// verification and primary addresses.
|
|
|
|
|
2012-08-29 20:07:29 +02:00
|
|
|
$create_email = null;
|
2012-05-07 19:29:33 +02:00
|
|
|
if ($is_new) {
|
|
|
|
do {
|
2014-06-09 20:36:49 +02:00
|
|
|
$email = phutil_console_prompt('Enter user email address:');
|
2012-05-07 19:29:33 +02:00
|
|
|
$duplicate = id(new PhabricatorUserEmail())->loadOneWhere(
|
|
|
|
'address = %s',
|
|
|
|
$email);
|
|
|
|
if ($duplicate) {
|
|
|
|
echo "ERROR: There is already a user with that email address. ".
|
|
|
|
"Each user must have a unique email address.\n";
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
|
2012-08-29 20:07:29 +02:00
|
|
|
$create_email = $email;
|
2011-05-12 20:02:59 +02:00
|
|
|
}
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
$changed_pass = false;
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
// This disables local echo, so the user's password is not shown as they type
|
|
|
|
// it.
|
|
|
|
phutil_passthru('stty -echo');
|
2011-05-12 20:02:59 +02:00
|
|
|
$password = phutil_console_prompt(
|
2014-06-09 20:36:49 +02:00
|
|
|
'Enter a password for this user [blank to leave unchanged]:');
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
phutil_passthru('stty echo');
|
2011-05-12 20:02:59 +02:00
|
|
|
if (strlen($password)) {
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
$changed_pass = $password;
|
2011-05-12 20:02:59 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 20:07:29 +02:00
|
|
|
$is_system_agent = $user->getIsSystemAgent();
|
|
|
|
$set_system_agent = phutil_console_confirm(
|
2014-04-02 21:06:56 +02:00
|
|
|
'Is this user a bot/script?',
|
2012-08-29 20:07:29 +02:00
|
|
|
$default_no = !$is_system_agent);
|
|
|
|
|
|
|
|
$verify_email = null;
|
|
|
|
$set_verified = false;
|
|
|
|
// Allow administrators to verify primary email addresses at this time in edit
|
|
|
|
// scenarios. (Create will work just fine from here as we auto-verify email
|
|
|
|
// on create.)
|
|
|
|
if (!$is_new) {
|
|
|
|
$verify_email = $user->loadPrimaryEmail();
|
|
|
|
if (!$verify_email->getIsVerified()) {
|
|
|
|
$set_verified = phutil_console_confirm(
|
|
|
|
'Should the primary email address be verified?',
|
2013-06-05 00:28:24 +02:00
|
|
|
$default_no = true);
|
2012-08-29 20:07:29 +02:00
|
|
|
} else {
|
|
|
|
// already verified so let's not make a fuss
|
|
|
|
$verify_email = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
$is_admin = $user->getIsAdmin();
|
|
|
|
$set_admin = phutil_console_confirm(
|
|
|
|
'Should this user be an administrator?',
|
|
|
|
$default_no = !$is_admin);
|
|
|
|
|
|
|
|
echo "\n\nACCOUNT SUMMARY\n\n";
|
|
|
|
$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());
|
2012-08-29 20:07:29 +02:00
|
|
|
if ($is_new) {
|
|
|
|
printf($tpl, 'Email', '', $create_email);
|
2012-05-07 19:29:33 +02:00
|
|
|
}
|
Mask typed passwords as they are entered into 'accountadmin'
Summary:
Currently, we echo the password as the user types it. This turns out to be a bit
of an issue in over-the-shoulder installs. Instead, disable tty echo while the
user is typing their password so nothing is shown (like how 'sudo' works).
Also show a better error message if the user chooses a duplicate email; without
testing for this we just throw a duplicate key exception when saving, which
isn't easy to understand. The other duplicate key exception is duplicate
username, which is impossible (the script updates rather than creating in this
case).
There's currently a bug where creating a user and setting their password at the
same time doesn't work. This is because we hash the PHID into the password hash,
but it's empty if the user hasn't been persisted yet. Make sure the user is
persisted before setting their password.
Finally, fix an issue where $original would have the new username set, creating
a somewhat confusing summary at the end.
I'm also going to improve the password behavior/explanation here once I add
welcome emails ("Hi Joe, epriestley created an account for you on Phabricator,
click here to login...").
Test Plan:
- Typed a password and didn't have it echoed. I also tested this on Ubuntu
without encountering problems.
- Chose a duplicate email, got a useful error message instead of the exception
I'd encountered earlier.
- Created a new user with a password in one pass and logged in as that user,
this worked properly.
- Verified summary table does not contain username for new users.
Reviewed By: jungejason
Reviewers: jungejason, tuomaspelkonen, aran
CC: moskov, jr, aran, jungejason
Differential Revision: 358
2011-05-28 16:17:42 +02:00
|
|
|
printf($tpl, 'Password', null,
|
|
|
|
($changed_pass !== false)
|
|
|
|
? 'Updated'
|
|
|
|
: 'Unchanged');
|
2011-05-12 20:02:59 +02:00
|
|
|
|
2012-08-29 20:07:29 +02:00
|
|
|
printf(
|
|
|
|
$tpl,
|
2014-04-02 21:06:56 +02:00
|
|
|
'Bot/Script',
|
2012-08-29 20:07:29 +02:00
|
|
|
$original->getIsSystemAgent() ? 'Y' : 'N',
|
|
|
|
$set_system_agent ? 'Y' : 'N');
|
|
|
|
|
|
|
|
if ($verify_email) {
|
|
|
|
printf(
|
|
|
|
$tpl,
|
|
|
|
'Verify Email',
|
|
|
|
$verify_email->getIsVerified() ? 'Y' : 'N',
|
|
|
|
$set_verified ? 'Y' : 'N');
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
printf(
|
|
|
|
$tpl,
|
|
|
|
'Admin',
|
|
|
|
$original->getIsAdmin() ? 'Y' : 'N',
|
2012-07-03 00:22:27 +02:00
|
|
|
$set_admin ? 'Y' : 'N');
|
2011-05-12 20:02:59 +02:00
|
|
|
|
|
|
|
echo "\n";
|
|
|
|
|
2014-06-09 20:36:49 +02:00
|
|
|
if (!phutil_console_confirm('Save these changes?', $default_no = false)) {
|
2011-05-12 20:02:59 +02:00
|
|
|
echo "Cancelled.\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-05-25 16:30:44 +02:00
|
|
|
$user->openTransaction();
|
2011-05-12 20:02:59 +02:00
|
|
|
|
2012-05-25 16:30:44 +02:00
|
|
|
$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);
|
|
|
|
|
2012-08-29 20:07:29 +02:00
|
|
|
if ($is_new) {
|
2012-05-25 16:30:44 +02:00
|
|
|
$email = id(new PhabricatorUserEmail())
|
2012-08-29 20:07:29 +02:00
|
|
|
->setAddress($create_email)
|
2012-05-25 16:30:44 +02:00
|
|
|
->setIsVerified(1);
|
|
|
|
|
2013-12-02 15:50:51 +01:00
|
|
|
// Unconditionally approve new accounts created from the CLI.
|
|
|
|
$user->setIsApproved(1);
|
|
|
|
|
2012-05-25 16:30:44 +02:00
|
|
|
$editor->createNewUser($user, $email);
|
|
|
|
} else {
|
2012-08-29 20:07:29 +02:00
|
|
|
if ($verify_email) {
|
2013-11-13 20:24:56 +01:00
|
|
|
$user->setIsEmailVerified(1);
|
2012-08-29 20:07:29 +02:00
|
|
|
$verify_email->setIsVerified($set_verified ? 1 : 0);
|
|
|
|
}
|
|
|
|
$editor->updateUser($user, $verify_email);
|
2012-05-25 16:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$editor->makeAdminUser($user, $set_admin);
|
2012-08-29 20:07:29 +02:00
|
|
|
$editor->makeSystemAgentUser($user, $set_system_agent);
|
2012-05-25 16:30:44 +02:00
|
|
|
|
|
|
|
if ($changed_pass !== false) {
|
2012-07-17 21:06:33 +02:00
|
|
|
$envelope = new PhutilOpaqueEnvelope($changed_pass);
|
|
|
|
$editor->changePassword($user, $envelope);
|
2012-05-25 16:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$user->saveTransaction();
|
2012-05-07 19:29:33 +02:00
|
|
|
|
2011-05-12 20:02:59 +02:00
|
|
|
echo "Saved changes.\n";
|