コード例 #1
0
 protected function buildUserInformationDictionary(PhabricatorUser $user, PhabricatorUserStatus $current_status = null)
 {
     $roles = array();
     if ($user->getIsDisabled()) {
         $roles[] = 'disabled';
     }
     if ($user->getIsSystemAgent()) {
         $roles[] = 'agent';
     }
     if ($user->getIsAdmin()) {
         $roles[] = 'admin';
     }
     $primary = $user->loadPrimaryEmail();
     if ($primary && $primary->getIsVerified()) {
         $roles[] = 'verified';
     } else {
         $roles[] = 'unverified';
     }
     $return = array('phid' => $user->getPHID(), 'userName' => $user->getUserName(), 'realName' => $user->getRealName(), 'image' => $user->loadProfileImageURI(), 'uri' => PhabricatorEnv::getURI('/p/' . $user->getUsername() . '/'), 'roles' => $roles);
     if ($current_status) {
         $return['currentStatus'] = $current_status->getTextStatus();
         $return['currentStatusUntil'] = $current_status->getDateTo();
     }
     return $return;
 }
コード例 #2
0
 public function processRequest()
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $is_admin = $viewer->getIsAdmin();
     $user = new PhabricatorUser();
     $count = queryfx_one($user->establishConnection('r'), 'SELECT COUNT(*) N FROM %T', $user->getTableName());
     $count = idx($count, 'N', 0);
     $pager = new AphrontPagerView();
     $pager->setOffset($request->getInt('page', 0));
     $pager->setCount($count);
     $pager->setURI($request->getRequestURI(), 'page');
     $users = id(new PhabricatorPeopleQuery())->needPrimaryEmail(true)->executeWithOffsetPager($pager);
     $rows = array();
     foreach ($users as $user) {
         $primary_email = $user->loadPrimaryEmail();
         if ($primary_email && $primary_email->getIsVerified()) {
             $email = 'Verified';
         } else {
             $email = 'Unverified';
         }
         $status = array();
         if ($user->getIsDisabled()) {
             $status[] = 'Disabled';
         }
         if ($user->getIsAdmin()) {
             $status[] = 'Admin';
         }
         if ($user->getIsSystemAgent()) {
             $status[] = 'System Agent';
         }
         $status = implode(', ', $status);
         $rows[] = array(phabricator_date($user->getDateCreated(), $viewer), phabricator_time($user->getDateCreated(), $viewer), phutil_render_tag('a', array('href' => '/p/' . $user->getUsername() . '/'), phutil_escape_html($user->getUserName())), phutil_escape_html($user->getRealName()), $status, $email, phutil_render_tag('a', array('class' => 'button grey small', 'href' => '/people/edit/' . $user->getID() . '/'), 'Administrate User'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Join Date', 'Time', 'Username', 'Real Name', 'Roles', 'Email', ''));
     $table->setColumnClasses(array(null, 'right', 'pri', 'wide', null, null, 'action'));
     $table->setColumnVisibility(array(true, true, true, true, $is_admin, $is_admin, $is_admin));
     $panel = new AphrontPanelView();
     $panel->setHeader('People (' . number_format($count) . ')');
     $panel->appendChild($table);
     $panel->appendChild($pager);
     if ($is_admin) {
         $panel->addButton(phutil_render_tag('a', array('href' => '/people/edit/', 'class' => 'button green'), 'Create New Account'));
         if (PhabricatorEnv::getEnvConfig('ldap.auth-enabled')) {
             $panel->addButton(phutil_render_tag('a', array('href' => '/people/ldap/', 'class' => 'button green'), 'Import from LDAP'));
         }
     }
     $nav = $this->buildSideNavView();
     $nav->selectFilter('people');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'People'));
 }
コード例 #3
0
 protected function buildUserInformationDictionary(PhabricatorUser $user, $with_email = false, $with_availability = false)
 {
     $roles = array();
     if ($user->getIsDisabled()) {
         $roles[] = 'disabled';
     }
     if ($user->getIsSystemAgent()) {
         $roles[] = 'agent';
     }
     if ($user->getIsMailingList()) {
         $roles[] = 'list';
     }
     if ($user->getIsAdmin()) {
         $roles[] = 'admin';
     }
     $primary = $user->loadPrimaryEmail();
     if ($primary && $primary->getIsVerified()) {
         $email = $primary->getAddress();
         $roles[] = 'verified';
     } else {
         $email = null;
         $roles[] = 'unverified';
     }
     if ($user->getIsApproved()) {
         $roles[] = 'approved';
     }
     if ($user->isUserActivated()) {
         $roles[] = 'activated';
     }
     $return = array('phid' => $user->getPHID(), 'userName' => $user->getUserName(), 'realName' => $user->getRealName(), 'image' => $user->getProfileImageURI(), 'uri' => PhabricatorEnv::getURI('/p/' . $user->getUsername() . '/'), 'roles' => $roles);
     if ($with_email) {
         $return['primaryEmail'] = $email;
     }
     if ($with_availability) {
         // TODO: Modernize this once we have a more long-term view of what the
         // data looks like.
         $until = $user->getAwayUntil();
         if ($until) {
             $return['currentStatus'] = 'away';
             $return['currentStatusUntil'] = $until;
         }
     }
     return $return;
 }
コード例 #4
0
 private function validateAuthenticatedUser(ConduitAPIRequest $request, PhabricatorUser $user)
 {
     if ($user->getIsDisabled()) {
         return array('ERR-USER-DISABLED', 'User is disabled.');
     }
     if (PhabricatorUserEmail::isEmailVerificationRequired()) {
         $email = $user->loadPrimaryEmail();
         if (!$email) {
             return array('ERR-USER-NOEMAIL', 'User has no primary email address.');
         }
         if (!$email->getIsVerified()) {
             return array('ERR-USER-UNVERIFIED', 'User has unverified email address.');
         }
     }
     $request->setUser($user);
     return null;
 }
コード例 #5
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;
 }
コード例 #6
0
// it.
phutil_passthru('stty -echo');
$password = phutil_console_prompt(pht('Enter a password for this user [blank to leave unchanged]:'));
phutil_passthru('stty echo');
if (strlen($password)) {
    $changed_pass = $password;
}
$is_system_agent = $user->getIsSystemAgent();
$set_system_agent = phutil_console_confirm(pht('Is this user a bot?'), $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(pht('Should the primary email address be verified?'), $default_no = true);
    } else {
        // Already verified so let's not make a fuss.
        $verify_email = null;
    }
}
$is_admin = $user->getIsAdmin();
$set_admin = phutil_console_confirm(pht('Should this user be an administrator?'), $default_no = !$is_admin);
echo "\n\n" . pht('ACCOUNT SUMMARY') . "\n\n";
$tpl = "%12s   %-30s   %-30s\n";
printf($tpl, null, pht('OLD VALUE'), pht('NEW VALUE'));
printf($tpl, pht('Username'), $original->getUsername(), $user->getUsername());
printf($tpl, pht('Real Name'), $original->getRealName(), $user->getRealName());
if ($is_new) {
コード例 #7
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();
 }