diff --git a/scripts/user/add_user.php b/scripts/user/add_user.php new file mode 100755 index 0000000000..af00b6b6b4 --- /dev/null +++ b/scripts/user/add_user.php @@ -0,0 +1,69 @@ +#!/usr/bin/env php + \n"; + exit(1); +} + +$username = $argv[1]; +$email = $argv[2]; +$realname = $argv[3]; +$admin = $argv[4]; + +$admin = id(new PhabricatorUser())->loadOneWhere( + 'username = %s', + $argv[4]); +if (!$admin) { + throw new Exception( + "Admin user must be the username of a valid Phabricator account, used ". + "to send the new user a welcome email."); +} + +$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_user = id(new PhabricatorUser())->loadOneWhere( + 'email = %s', + $email); +if ($existing_user) { + throw new Exception( + "There is already a user with the email '{$email}'!"); +} + +$user = new PhabricatorUser(); +$user->setUsername($username); +$user->setEmail($email); +$user->setRealname($realname); +$user->save(); + +$user->sendWelcomeEmail($admin); + +echo "Created user '{$username}' (realname='{$realname}', email='{$email}').\n"; diff --git a/src/applications/people/controller/edit/PhabricatorPeopleEditController.php b/src/applications/people/controller/edit/PhabricatorPeopleEditController.php index 3642677633..1a940d92a7 100644 --- a/src/applications/people/controller/edit/PhabricatorPeopleEditController.php +++ b/src/applications/people/controller/edit/PhabricatorPeopleEditController.php @@ -1,7 +1,7 @@ getRequest(); if ($request->isFormPost()) { @@ -175,44 +174,7 @@ class PhabricatorPeopleEditController extends PhabricatorPeopleController { $log->save(); if ($welcome_checked) { - $admin_username = $admin->getUserName(); - $admin_realname = $admin->getRealName(); - $user_username = $user->getUserName(); - - $base_uri = PhabricatorEnv::getProductionURI('/'); - - $uri = $user->getEmailLoginURI(); - $body = <<addTos(array($user->getPHID())) - ->setSubject('[Phabricator] Welcome to Phabricator') - ->setBody($body) - ->setFrom($admin->getPHID()) - ->saveAndSend(); + $user->sendWelcomeEmail($admin); } } diff --git a/src/applications/people/controller/edit/__init__.php b/src/applications/people/controller/edit/__init__.php index b64ccccd5c..1cb7290bc0 100644 --- a/src/applications/people/controller/edit/__init__.php +++ b/src/applications/people/controller/edit/__init__.php @@ -8,11 +8,9 @@ phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/redirect'); -phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'applications/people/controller/base'); phutil_require_module('phabricator', 'applications/people/storage/log'); phutil_require_module('phabricator', 'applications/people/storage/user'); -phutil_require_module('phabricator', 'infrastructure/env'); phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/control/checkbox'); phutil_require_module('phabricator', 'view/form/control/select'); diff --git a/src/applications/people/storage/user/PhabricatorUser.php b/src/applications/people/storage/user/PhabricatorUser.php index bfc50ecede..26b3d3dd0d 100644 --- a/src/applications/people/storage/user/PhabricatorUser.php +++ b/src/applications/people/storage/user/PhabricatorUser.php @@ -457,4 +457,47 @@ class PhabricatorUser extends PhabricatorUserDAO { } } + public function sendWelcomeEmail(PhabricatorUser $admin) { + $admin_username = $admin->getUserName(); + $admin_realname = $admin->getRealName(); + $user_username = $this->getUserName(); + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + + $base_uri = PhabricatorEnv::getProductionURI('/'); + + $uri = $this->getEmailLoginURI(); + $body = <<addTos(array($this->getPHID())) + ->setSubject('[Phabricator] Welcome to Phabricator') + ->setBody($body) + ->setFrom($admin->getPHID()) + ->saveAndSend(); + } + } diff --git a/src/applications/people/storage/user/__init__.php b/src/applications/people/storage/user/__init__.php index 8cdfe8db6e..29e3e21402 100644 --- a/src/applications/people/storage/user/__init__.php +++ b/src/applications/people/storage/user/__init__.php @@ -7,6 +7,7 @@ phutil_require_module('phabricator', 'aphront/writeguard'); +phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'applications/people/storage/base'); phutil_require_module('phabricator', 'applications/people/storage/log'); phutil_require_module('phabricator', 'applications/people/storage/preferences'); diff --git a/src/docs/configuration/configuring_accounts_and_registration.diviner b/src/docs/configuration/configuring_accounts_and_registration.diviner index a6b4096b2e..d2d933b861 100644 --- a/src/docs/configuration/configuring_accounts_and_registration.diviner +++ b/src/docs/configuration/configuring_accounts_and_registration.diviner @@ -38,6 +38,21 @@ To manage accounts from the web, login as an administrator account and go to ##/people/## or click "People" on the homepage. Provided you're an admin, you'll see options to create or edit accounts. += Managing Accounts from the Command Line = + +You can use ##scripts/user/add_user.php## to batch create accounts. Run it +like: + + $ ./add_user.php + +For example: + + $ ./add_user.php alincoln alincoln@logcabin.com 'Abraham Lincoln' tjefferson + +This will create a new ##alincoln## user and send them a "Welcome to +Phabricator" email from ##tjefferson## with instructions on how to log in and +set a password. + = Configuring Facebook OAuth = You can configure Facebook OAuth to allow login, login and registration, or