コード例 #1
0
ファイル: emailtableport.php プロジェクト: denghp/phabricator
<?php

echo "Migrating user emails...\n";
$table = new PhabricatorUser();
$table->openTransaction();
$conn = $table->establishConnection('w');
$emails = queryfx_all($conn, 'SELECT phid, email FROM %T LOCK IN SHARE MODE', $table->getTableName());
$emails = ipull($emails, 'email', 'phid');
$etable = new PhabricatorUserEmail();
foreach ($emails as $phid => $email) {
    // NOTE: Grandfather all existing email in as primary / verified. We generate
    // verification codes because they are used for password resets, etc.
    echo "Migrating '{$phid}'...\n";
    queryfx($conn, 'INSERT INTO %T (userPHID, address, verificationCode, isVerified, isPrimary)
      VALUES (%s, %s, %s, 1, 1)', $etable->getTableName(), $phid, $email, Filesystem::readRandomCharacters(24));
}
$table->saveTransaction();
echo "Done.\n";
コード例 #2
0
 /**
  * @task email
  */
 public function changePrimaryEmail(PhabricatorUser $user, PhabricatorUserEmail $email)
 {
     $actor = $this->requireActor();
     if (!$user->getID()) {
         throw new Exception("User has not been created yet!");
     }
     if (!$email->getID()) {
         throw new Exception("Email has not been created yet!");
     }
     $user->openTransaction();
     $user->beginWriteLocking();
     $user->reload();
     $email->reload();
     if ($email->getUserPHID() != $user->getPHID()) {
         throw new Exception("User does not own email!");
     }
     if ($email->getIsPrimary()) {
         throw new Exception("Email is already primary!");
     }
     if (!$email->getIsVerified()) {
         throw new Exception("Email is not verified!");
     }
     $old_primary = $user->loadPrimaryEmail();
     if ($old_primary) {
         $old_primary->setIsPrimary(0);
         $old_primary->save();
     }
     $email->setIsPrimary(1);
     $email->save();
     $log = PhabricatorUserLog::newLog($actor, $user, PhabricatorUserLog::ACTION_EMAIL_PRIMARY);
     $log->setOldValue($old_primary ? $old_primary->getAddress() : null);
     $log->setNewValue($email->getAddress());
     $log->save();
     $user->endWriteLocking();
     $user->saveTransaction();
     if ($old_primary) {
         $old_primary->sendOldPrimaryEmail($user, $email);
     }
     $email->sendNewPrimaryEmail($user);
     return $this;
 }
コード例 #3
0
printf($tpl, pht('Real Name'), $original->getRealName(), $user->getRealName());
if ($is_new) {
    printf($tpl, pht('Email'), '', $create_email);
}
printf($tpl, pht('Password'), null, $changed_pass !== false ? pht('Updated') : pht('Unchanged'));
printf($tpl, pht('Bot'), $original->getIsSystemAgent() ? 'Y' : 'N', $set_system_agent ? 'Y' : 'N');
if ($verify_email) {
    printf($tpl, pht('Verify Email'), $verify_email->getIsVerified() ? 'Y' : 'N', $set_verified ? 'Y' : 'N');
}
printf($tpl, pht('Admin'), $original->getIsAdmin() ? 'Y' : 'N', $set_admin ? 'Y' : 'N');
echo "\n";
if (!phutil_console_confirm(pht('Save these changes?'), $default_no = false)) {
    echo pht('Cancelled.') . "\n";
    exit(1);
}
$user->openTransaction();
$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);
if ($is_new) {
    $email = id(new PhabricatorUserEmail())->setAddress($create_email)->setIsVerified(1);
    // Unconditionally approve new accounts created from the CLI.
    $user->setIsApproved(1);
    $editor->createNewUser($user, $email);
} else {
    if ($verify_email) {
        $user->setIsEmailVerified(1);
        $verify_email->setIsVerified($set_verified ? 1 : 0);
    }
    $editor->updateUser($user, $verify_email);
コード例 #4
0
if ($is_first_user) {
    echo "You must first create an admin user before being able to create a system agent.\n";
    exit(1);
}
$username = $argv[1];
$email = $argv[2];
$realname = $argv[3];
if (!PhabricatorUser::validateUsername($username)) {
    $valid = PhabricatorUser::describeValidUsername();
    echo "The username '{$username}' is invalid. {$valid}\n";
    exit(1);
}
$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_object = new PhabricatorUser();
$user_object->setUsername($username);
$user_object->setRealname($realname);
$user_object->setIsApproved(1);
$user_object->openTransaction();
$email_object = id(new PhabricatorUserEmail())->setAddress($email)->setIsVerified(1);
$editor = new PhabricatorUserEditor();
$editor->setActor($user_object);
$editor->createNewUser($user_object, $email_object);
$editor->makeSystemAgentUser($user_object, true);
$user_object->saveTransaction();
コード例 #5
0
 /**
  * Verify a user's email address.
  *
  * This verifies an individual email address. If the address is the user's
  * primary address and their account was not previously verified, their
  * account is marked as email verified.
  *
  * @task email
  */
 public function verifyEmail(PhabricatorUser $user, PhabricatorUserEmail $email)
 {
     $actor = $this->requireActor();
     if (!$user->getID()) {
         throw new Exception('User has not been created yet!');
     }
     if (!$email->getID()) {
         throw new Exception('Email has not been created yet!');
     }
     $user->openTransaction();
     $user->beginWriteLocking();
     $user->reload();
     $email->reload();
     if ($email->getUserPHID() != $user->getPHID()) {
         throw new Exception(pht('User does not own email!'));
     }
     if (!$email->getIsVerified()) {
         $email->setIsVerified(1);
         $email->save();
         $log = PhabricatorUserLog::initializeNewLog($actor, $user->getPHID(), PhabricatorUserLog::ACTION_EMAIL_VERIFY);
         $log->setNewValue($email->getAddress());
         $log->save();
     }
     if (!$user->getIsEmailVerified()) {
         // If the user just verified their primary email address, mark their
         // account as email verified.
         $user_primary = $user->loadPrimaryEmail();
         if ($user_primary->getID() == $email->getID()) {
             $user->setIsEmailVerified(1);
             $user->save();
         }
     }
     $user->endWriteLocking();
     $user->saveTransaction();
 }
コード例 #6
0
 /**
  * Reassign an unverified email address.
  */
 public function reassignEmail(PhabricatorUser $user, PhabricatorUserEmail $email)
 {
     $actor = $this->requireActor();
     if (!$user->getID()) {
         throw new Exception(pht('User has not been created yet!'));
     }
     if (!$email->getID()) {
         throw new Exception(pht('Email has not been created yet!'));
     }
     $user->openTransaction();
     $user->beginWriteLocking();
     $user->reload();
     $email->reload();
     $old_user = $email->getUserPHID();
     if ($old_user != $user->getPHID()) {
         if ($email->getIsVerified()) {
             throw new Exception(pht('Verified email addresses can not be reassigned.'));
         }
         if ($email->getIsPrimary()) {
             throw new Exception(pht('Primary email addresses can not be reassigned.'));
         }
         $email->setUserPHID($user->getPHID());
         $email->save();
         $log = PhabricatorUserLog::initializeNewLog($actor, $user->getPHID(), PhabricatorUserLog::ACTION_EMAIL_REASSIGN);
         $log->setNewValue($email->getAddress());
         $log->save();
     }
     $user->endWriteLocking();
     $user->saveTransaction();
 }