mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Provide a script for batch creating user accounts
Summary: Make it a little easier to create a bunch of accounts if your company has more than like 5 employees. Test Plan: Ran "add_user.php" to create new users. Created new users from the web console. Reviewers: btrahan, jungejason, rguerin Reviewed By: btrahan CC: aran, btrahan, rguerin Differential Revision: https://secure.phabricator.com/D1336
This commit is contained in:
parent
d16454d45d
commit
58f2cb2509
6 changed files with 130 additions and 42 deletions
69
scripts/user/add_user.php
Executable file
69
scripts/user/add_user.php
Executable file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
require_once $root.'/scripts/__init_script__.php';
|
||||
|
||||
phutil_require_module('phutil', 'console');
|
||||
phutil_require_module('phutil', 'future/exec');
|
||||
|
||||
if ($argc !== 5) {
|
||||
echo "usage: add_user.php <username> <email> <realname> <admin_user>\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";
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -121,7 +121,6 @@ class PhabricatorPeopleEditController extends PhabricatorPeopleController {
|
|||
$errors = array();
|
||||
|
||||
$welcome_checked = true;
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
|
||||
$request = $this->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 = <<<EOBODY
|
||||
Welcome to Phabricator!
|
||||
|
||||
{$admin_username} ({$admin_realname}) has created an account for you.
|
||||
|
||||
Username: {$user_username}
|
||||
|
||||
To login to Phabricator, follow this link and set a password:
|
||||
|
||||
{$uri}
|
||||
|
||||
After you have set a password, you can login in the future by going here:
|
||||
|
||||
{$base_uri}
|
||||
|
||||
EOBODY;
|
||||
|
||||
if (!$is_serious) {
|
||||
$body .= <<<EOBODY
|
||||
Love,
|
||||
Phabricator
|
||||
|
||||
EOBODY;
|
||||
}
|
||||
|
||||
$mail = id(new PhabricatorMetaMTAMail())
|
||||
->addTos(array($user->getPHID()))
|
||||
->setSubject('[Phabricator] Welcome to Phabricator')
|
||||
->setBody($body)
|
||||
->setFrom($admin->getPHID())
|
||||
->saveAndSend();
|
||||
$user->sendWelcomeEmail($admin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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 = <<<EOBODY
|
||||
Welcome to Phabricator!
|
||||
|
||||
{$admin_username} ({$admin_realname}) has created an account for you.
|
||||
|
||||
Username: {$user_username}
|
||||
|
||||
To login to Phabricator, follow this link and set a password:
|
||||
|
||||
{$uri}
|
||||
|
||||
After you have set a password, you can login in the future by going here:
|
||||
|
||||
{$base_uri}
|
||||
|
||||
EOBODY;
|
||||
|
||||
if (!$is_serious) {
|
||||
$body .= <<<EOBODY
|
||||
|
||||
Love,
|
||||
Phabricator
|
||||
|
||||
EOBODY;
|
||||
}
|
||||
|
||||
$mail = id(new PhabricatorMetaMTAMail())
|
||||
->addTos(array($this->getPHID()))
|
||||
->setSubject('[Phabricator] Welcome to Phabricator')
|
||||
->setBody($body)
|
||||
->setFrom($admin->getPHID())
|
||||
->saveAndSend();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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 <username> <email> <realname> <admin>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue