id = idx($data, 'id'); $this->view = idx($data, 'view'); } public function processRequest() { $request = $this->getRequest(); $admin = $request->getUser(); if ($this->id) { $user = id(new PhabricatorUser())->load($this->id); if (!$user) { return new Aphront404Response(); } } else { $user = new PhabricatorUser(); } $views = array( 'basic' => 'Basic Information', 'role' => 'Edit Role', 'cert' => 'Conduit Certificate', ); if (!$user->getID()) { $view = 'basic'; } else if (isset($views[$this->view])) { $view = $this->view; } else { $view = 'basic'; } $content = array(); if ($request->getStr('saved')) { $notice = new AphrontErrorView(); $notice->setSeverity(AphrontErrorView::SEVERITY_NOTICE); $notice->setTitle('Changes Saved'); $notice->appendChild('
Your changes were saved.
'); $content[] = $notice; } switch ($view) { case 'basic': $response = $this->processBasicRequest($user); break; case 'role': $response = $this->processRoleRequest($user); break; case 'cert': $response = $this->processCertificateRequest($user); break; } if ($response instanceof AphrontResponse) { return $response; } $content[] = $response; if ($user->getID()) { $side_nav = new AphrontSideNavView(); $side_nav->appendChild($content); foreach ($views as $key => $name) { $side_nav->addNavItem( phutil_render_tag( 'a', array( 'href' => '/people/edit/'.$user->getID().'/'.$key.'/', 'class' => ($key == $view) ? 'aphront-side-nav-selected' : null, ), phutil_escape_html($name))); } $content = $side_nav; } return $this->buildStandardPageResponse( $content, array( 'title' => 'Edit User', )); } private function processBasicRequest(PhabricatorUser $user) { $request = $this->getRequest(); $admin = $request->getUser(); $e_username = true; $e_realname = true; $e_email = true; $errors = array(); $welcome_checked = true; $request = $this->getRequest(); if ($request->isFormPost()) { $welcome_checked = $request->getInt('welcome'); if (!$user->getID()) { $user->setUsername($request->getStr('username')); $user->setEmail($request->getStr('email')); if ($request->getStr('role') == 'agent') { $user->setIsSystemAgent(true); } } $user->setRealName($request->getStr('realname')); if (!strlen($user->getUsername())) { $errors[] = "Username is required."; $e_username = 'Required'; } else if (!preg_match('/^[a-z0-9]+$/', $user->getUsername())) { $errors[] = "Username must consist of only numbers and letters."; $e_username = 'Invalid'; } else { $e_username = null; } if (!strlen($user->getRealName())) { $errors[] = 'Real name is required.'; $e_realname = 'Required'; } else { $e_realname = null; } if (!strlen($user->getEmail())) { $errors[] = 'Email is required.'; $e_email = 'Required'; } else { $e_email = null; } if (!$errors) { try { $is_new = !$user->getID(); $user->save(); if ($is_new) { $log = PhabricatorUserLog::newLog( $admin, $user, PhabricatorUserLog::ACTION_CREATE); $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 = <<NOTE: You can not edit your own '. 'role.
'); } $form ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'is_admin', 1, 'Admin: wields absolute power.', $user->getIsAdmin()) ->setDisabled($is_self)) ->appendChild( id(new AphrontFormCheckboxControl()) ->addCheckbox( 'is_disabled', 1, 'Disabled: can not login.', $user->getIsDisabled()) ->setDisabled($is_self)); if (!$is_self) { $form ->appendChild( id(new AphrontFormSubmitControl()) ->setValue('Edit Role')); } $panel = new AphrontPanelView(); $panel->setHeader('Edit Role'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); return array($error_view, $panel); } private function processCertificateRequest($user) { $request = $this->getRequest(); $admin = $request->getUser(); $form = new AphrontFormView(); $form ->setUser($admin) ->setAction($request->getRequestURI()) ->appendChild( 'You can use this certificate '. 'to write scripts or bots which interface with Phabricator over '. 'Conduit.
'); if ($user->getIsSystemAgent()) { $form ->appendChild( id(new AphrontFormTextControl()) ->setLabel('Username') ->setValue($user->getUsername())) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel('Certificate') ->setValue($user->getConduitCertificate())); } else { $form->appendChild( id(new AphrontFormStaticControl()) ->setLabel('Certificate') ->setValue( 'You may only view the certificates of System Agents.')); } $panel = new AphrontPanelView(); $panel->setHeader('Conduit Certificate'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild($form); return array($panel); } }