Path: blob/master/src/applications/people/controller/PhabricatorPeopleRenameController.php
12262 views
<?php12final class PhabricatorPeopleRenameController3extends PhabricatorPeopleController {45public function shouldRequireAdmin() {6return false;7}89public function handleRequest(AphrontRequest $request) {10$viewer = $this->getViewer();1112$id = $request->getURIData('id');1314$user = id(new PhabricatorPeopleQuery())15->setViewer($viewer)16->withIDs(array($id))17->executeOne();18if (!$user) {19return new Aphront404Response();20}2122$done_uri = $this->getApplicationURI("manage/{$id}/");2324if (!$viewer->getIsAdmin()) {25$dialog = $this->newDialog()26->setTitle(pht('Change Username'))27->appendParagraph(28pht(29'You can not change usernames because you are not an '.30'administrator. Only administrators can change usernames.'))31->addCancelButton($done_uri, pht('Okay'));3233$message_body = PhabricatorAuthMessage::loadMessageText(34$viewer,35PhabricatorAuthChangeUsernameMessageType::MESSAGEKEY);36if (strlen($message_body)) {37$dialog->appendRemarkup($message_body);38}3940return $dialog;41}4243$validation_exception = null;44$username = $user->getUsername();45if ($request->isFormOrHisecPost()) {46$username = $request->getStr('username');47$xactions = array();4849$xactions[] = id(new PhabricatorUserTransaction())50->setTransactionType(51PhabricatorUserUsernameTransaction::TRANSACTIONTYPE)52->setNewValue($username);5354$editor = id(new PhabricatorUserTransactionEditor())55->setActor($viewer)56->setContentSourceFromRequest($request)57->setCancelURI($done_uri)58->setContinueOnMissingFields(true);5960try {61$editor->applyTransactions($user, $xactions);62return id(new AphrontRedirectResponse())->setURI($done_uri);63} catch (PhabricatorApplicationTransactionValidationException $ex) {64$validation_exception = $ex;65}6667}6869$instructions = array();7071$instructions[] = pht(72'If you rename this user, the old username will no longer be tied '.73'to the user account. Anything which uses the old username in raw '.74'text (like old commit messages) may no longer associate correctly.');7576$instructions[] = pht(77'It is generally safe to rename users, but changing usernames may '.78'create occasional minor complications or confusion with text that '.79'contains the old username.');8081$instructions[] = pht(82'The user will receive an email notifying them that you changed their '.83'username.');8485$instructions[] = null;8687$form = id(new AphrontFormView())88->appendChild(89id(new AphrontFormStaticControl())90->setLabel(pht('Old Username'))91->setValue($user->getUsername()))92->appendChild(93id(new AphrontFormTextControl())94->setLabel(pht('New Username'))95->setValue($username)96->setName('username'));9798$dialog = $this->newDialog()99->setTitle(pht('Change Username'))100->setValidationException($validation_exception);101102foreach ($instructions as $instruction) {103$dialog->appendParagraph($instruction);104}105106$dialog107->appendForm($form)108->addSubmitButton(pht('Rename User'))109->addCancelButton($done_uri);110111return $dialog;112}113114}115116117