mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-29 00:40:57 +01:00
70fd96037b
Summary: - We currently have some bugs in account creation due to nontransactional user/email editing. - We save $user, then try to save $email. This may fail for various reasons, commonly because the email isn't unique. - This leaves us with a $user with no email. - Also, logging of edits is somewhat inconsistent across various edit mechanisms. - Move all editing to a `PhabricatorUserEditor` class. - Handle some broken-data cases more gracefully. Test Plan: - Created and edited a user with `accountadmin`. - Created a user with `add_user.php` - Created and edited a user with People editor. - Created a user with OAuth. - Edited user information via Settings. - Tried to create an OAuth user with a duplicate email address, got a proper error. - Tried to create a user via People with a duplicate email address, got a proper error. Reviewers: btrahan, vrana, jungejason Reviewed By: btrahan CC: tberman, aran Maniphest Tasks: T1184 Differential Revision: https://secure.phabricator.com/D2569
75 lines
2 KiB
PHP
Executable file
75 lines
2 KiB
PHP
Executable file
#!/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_email = id(new PhabricatorUserEmail())->loadOneWhere(
|
|
'address = %s',
|
|
$email);
|
|
if ($existing_email) {
|
|
throw new Exception(
|
|
"There is already a user with the email '{$email}'!");
|
|
}
|
|
|
|
$user = new PhabricatorUser();
|
|
$user->setUsername($username);
|
|
$user->setRealname($realname);
|
|
|
|
$email_object = id(new PhabricatorUserEmail())
|
|
->setAddress($email)
|
|
->setIsVerified(1);
|
|
|
|
id(new PhabricatorUserEditor())
|
|
->setActor($admin)
|
|
->createNewUser($user, $email_object);
|
|
|
|
$user->sendWelcomeEmail($admin);
|
|
|
|
echo "Created user '{$username}' (realname='{$realname}', email='{$email}').\n";
|