public function processRequest() { if ($this->id) { $item = id(new PhabricatorDirectoryItem())->load($this->id); if (!$item) { return new Aphront404Response(); } } else { $item = new PhabricatorDirectoryItem(); } $e_name = true; $e_href = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $item->setName($request->getStr('name')); $item->setHref($request->getStr('href')); $item->setDescription($request->getStr('description')); $item->setCategoryID($request->getStr('categoryID')); $item->setSequence($request->getStr('sequence')); if (!strlen($item->getName())) { $errors[] = 'Item name is required.'; $e_name = 'Required'; } if (!strlen($item->getHref())) { $errors[] = 'Item link is required.'; $e_href = 'Required'; } if (!$errors) { $item->save(); return id(new AphrontRedirectResponse())->setURI('/directory/item/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($item->getID()) { $form->setAction('/directory/item/edit/' . $item->getID() . '/'); } else { $form->setAction('/directory/item/edit/'); } $categories = id(new PhabricatorDirectoryCategory())->loadAll(); $category_map = mpull($categories, 'getName', 'getID'); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($item->getName())->setError($e_name))->appendChild(id(new AphrontFormSelectControl())->setLabel('Category')->setName('categoryID')->setOptions($category_map)->setValue($item->getCategoryID()))->appendChild(id(new AphrontFormTextControl())->setLabel('Link')->setName('href')->setValue($item->getHref())->setError($e_href))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Description')->setName('description')->setValue($item->getDescription()))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setCaption('Items in a category are sorted by "order", then by name.')->setValue((int) $item->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/item/')); $panel = new AphrontPanelView(); if ($item->getID()) { $panel->setHeader('Edit Directory Item'); } else { $panel->setHeader('Create New Directory Item'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Item')); }
public function processRequest() { if ($this->id) { $category = id(new PhabricatorDirectoryCategory())->load($this->id); if (!$category) { return new Aphront404Response(); } } else { $category = new PhabricatorDirectoryCategory(); } $e_name = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $category->setName($request->getStr('name')); $category->setSequence($request->getStr('sequence')); if (!strlen($category->getName())) { $errors[] = 'Category name is required.'; $e_name = 'Required'; } if (!$errors) { $category->save(); return id(new AphrontRedirectResponse())->setURI('/directory/category/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($category->getID()) { $form->setAction('/directory/category/edit/' . $category->getID() . '/'); } else { $form->setAction('/directory/category/edit/'); } $categories = id(new PhabricatorDirectoryCategory())->loadAll(); $category_map = mpull($categories, 'getName', 'getID'); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($category->getName())->setError($e_name))->appendChild(id(new AphrontFormTextControl())->setLabel('Order')->setName('sequence')->setValue((int) $category->getSequence()))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/directory/category/')); $panel = new AphrontPanelView(); if ($category->getID()) { $panel->setHeader('Edit Directory Category'); } else { $panel->setHeader('Create New Directory Category'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Directory Category')); }
public function processRequest() { if ($this->id) { $list = id(new PhabricatorMetaMTAMailingList())->load($this->id); if (!$list) { return new Aphront404Response(); } } else { $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); if (!strlen($list->getEmail())) { $e_email = 'Required'; $errors[] = 'Email is required.'; } if (!$errors) { $list->save(); return id(new AphrontRedirectResponse())->setURI('/mail/lists/'); } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction('/mail/lists/edit/' . $list->getID() . '/'); } else { $form->setAction('/mail/lists/edit/'); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/')); $panel = new AphrontPanelView(); if ($list->getID()) { $panel->setHeader('Edit Mailing List'); } else { $panel->setHeader('Create New Mailing List'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List')); }
public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $parser = new ArcanistDiffParser(); $diff = null; try { $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']); } catch (Exception $ex) { $diff = $request->getStr('diff'); } $changes = $parser->parseDiff($diff); $diff = DifferentialDiff::newFromRawChanges($changes); $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); $diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP); $diff->setAuthorPHID($request->getUser()->getPHID()); $diff->setCreationMethod('web'); $diff->save(); return id(new AphrontRedirectResponse())->setURI('/differential/diff/' . $diff->getID() . '/'); } $form = new AphrontFormView(); $arcanist_href = PhabricatorEnv::getDoclink('article/Arcanist_User_Guide.html'); $arcanist_link = phutil_render_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), 'Arcanist'); $form->setAction('/differential/diff/create/')->setEncType('multipart/form-data')->setUser($request->getUser())->appendChild('<p class="aphront-form-instructions">The best way to create a ' . "Differential diff is by using {$arcanist_link}, but you " . 'can also just paste a diff (e.g., from <tt>svn diff</tt> or ' . '<tt>git diff</tt>) into this box or upload it as a file if you ' . 'really want.</p>')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Raw Diff')->setName('diff')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))->appendChild(id(new AphrontFormFileControl())->setLabel('Raw Diff from file')->setName('diff-file'))->appendChild(id(new AphrontFormSubmitControl())->setValue("Create Diff »")); $panel = new AphrontPanelView(); $panel->setHeader('Create New Diff'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse($panel, array('title' => 'Create Diff', 'tab' => 'create')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $receiver = PhabricatorMetaMTAReceivedMail::loadReceiverObject($request->getStr('obj')); if (!$receiver) { throw new Exception("No such task or revision!"); } $hash = PhabricatorMetaMTAReceivedMail::computeMailHash($receiver->getMailKey(), $user->getPHID()); $received = new PhabricatorMetaMTAReceivedMail(); $received->setHeaders(array('to' => $request->getStr('obj') . '+' . $user->getID() . '+' . $hash . '@')); $received->setBodies(array('text' => $request->getStr('body'))); $received->save(); $received->processReceivedMail(); $phid = $receiver->getPHID(); $handles = $this->loadViewerHandles(array($phid)); $uri = $handles[$phid]->getURI(); return id(new AphrontRedirectResponse())->setURI($uri); } $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction($this->getApplicationURI('/receive/')); $form->appendChild('<p class="aphront-form-instructions">This form will simulate ' . 'sending mail to an object.</p>')->appendChild(id(new AphrontFormTextControl())->setLabel('To')->setName('obj')->setCaption('e.g. <tt>D1234</tt> or <tt>T1234</tt>'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Receive Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Receive Email'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $nav = $this->buildSideNavView(); $nav->selectFilter('receive'); $nav->appendChild($panel); return $this->buildApplicationPage($nav, array('title' => 'Receive Test')); }
public function processRequest() { $request = $this->getRequest(); $phids = $request->getStrList('phids'); if ($phids) { $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $rows = array(); foreach ($handles as $handle) { if ($handle->getURI()) { $link = phutil_render_tag('a', array('href' => $handle->getURI()), phutil_escape_html($handle->getURI())); } else { $link = null; } $rows[] = array(phutil_escape_html($handle->getPHID()), phutil_escape_html($handle->getType()), phutil_escape_html($handle->getName()), $link); } $table = new AphrontTableView($rows); $table->setHeaders(array('PHID', 'Type', 'Name', 'URI')); $table->setColumnClasses(array(null, null, null, 'wide')); $panel = new AphrontPanelView(); $panel->setHeader('PHID Handles'); $panel->appendChild($table); return $this->buildStandardPageResponse($panel, array('title' => 'PHID Lookup Results')); } $lookup_form = new AphrontFormView(); $lookup_form->setUser($request->getUser()); $lookup_form->setAction('/phid/')->appendChild(id(new AphrontFormTextAreaControl())->setName('phids')->setCaption('Enter PHIDs separated by spaces or commas.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Lookup PHIDs')); $lookup_panel = new AphrontPanelView(); $lookup_panel->setHeader('Lookup PHIDs'); $lookup_panel->appendChild($lookup_form); $lookup_panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse(array($lookup_panel), array('title' => 'PHID Lookup')); }
public function processRequest() { if ($this->id) { $macro = id(new PhabricatorFileImageMacro())->load($this->id); if (!$macro) { return new Aphront404Response(); } } else { $macro = new PhabricatorFileImageMacro(); } $errors = array(); $e_name = true; $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $macro->setName($request->getStr('name')); if (!strlen($macro->getName())) { $errors[] = 'Macro name is required.'; $e_name = 'Required'; } else { if (!preg_match('/^[a-z0-9_-]{3,}$/', $macro->getName())) { $errors[] = 'Macro must be at least three characters long and contain ' . 'only lowercase letters, digits, hyphen and underscore.'; $e_name = 'Invalid'; } else { $e_name = null; } } if (!$errors) { $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID())); $macro->setFilePHID($file->getPHID()); try { $macro->save(); return id(new AphrontRedirectResponse())->setURI('/file/macro/'); } catch (AphrontQueryDuplicateKeyException $ex) { $errors[] = 'Macro name is not unique!'; $e_name = 'Duplicate'; } } } if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Form Errors'); $error_view->setErrors($errors); } else { $error_view = null; } $form = new AphrontFormView(); $form->setAction('/file/macro/edit/'); $form->setUser($request->getUser()); $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setValue($macro->getName())->setCaption('This word or phrase will be replaced with the image.')->setError($e_name))->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save Image Macro')->addCancelButton('/file/macro/')); $panel = new AphrontPanelView(); if ($macro->getID()) { $panel->setHeader('Edit Image Macro'); } else { $panel->setHeader('Create Image Macro'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Image Macro')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid); if (!$file) { return new Aphront404Response(); } $author_child = null; if ($file->getAuthorPHID()) { $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $file->getAuthorPHID()); if ($author) { $author_child = id(new AphrontFormStaticControl())->setLabel('Author')->setName('author')->setValue($author->getUserName()); } } $form = new AphrontFormView(); $submit = new AphrontFormSubmitControl(); $form->setAction($file->getViewURI()); if ($file->isViewableInBrowser()) { $submit->setValue('View File'); } else { $submit->setValue('Download File'); } if ($user->getPHID() == $file->getAuthorPHID() || $user->getIsAdmin()) { $submit->addCancelButton('/file/delete/' . $file->getID() . '/', 'Delete File'); } $file_id = 'F' . $file->getID(); $form->setUser($user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setName('name')->setValue($file->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setName('id')->setValue($file_id)->setCaption('Download this file with: <tt>arc download ' . phutil_escape_html($file_id) . '</tt>'))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setName('phid')->setValue($file->getPHID()))->appendChild($author_child)->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setName('created')->setValue(phabricator_datetime($file->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Mime Type')->setName('mime')->setValue($file->getMimeType()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Size')->setName('size')->setValue($file->getByteSize() . ' bytes'))->appendChild(id(new AphrontFormStaticControl())->setLabel('Engine')->setName('storageEngine')->setValue($file->getStorageEngine()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Format')->setName('storageFormat')->setValue($file->getStorageFormat()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Handle')->setName('storageHandle')->setValue($file->getStorageHandle()))->appendChild(id($submit)); $panel = new AphrontPanelView(); $panel->setHeader('File Info - ' . $file->getName()); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel = null; $transformations = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID()); if ($transformations) { $transformed_phids = mpull($transformations, 'getTransformedPHID'); $transformed_files = id(new PhabricatorFile())->loadAllWhere('phid in (%Ls)', $transformed_phids); $transformed_map = mpull($transformed_files, null, 'getPHID'); $rows = array(); foreach ($transformations as $transformed) { $phid = $transformed->getTransformedPHID(); $rows[] = array(phutil_escape_html($transformed->getTransform()), phutil_render_tag('a', array('href' => $transformed_map[$phid]->getBestURI()), $phid)); } $table = new AphrontTableView($rows); $table->setHeaders(array('Transform', 'File')); $xform_panel = new AphrontPanelView(); $xform_panel->appendChild($table); $xform_panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel->setHeader('Transformations'); } return $this->buildStandardPageResponse(array($panel, $xform_panel), array('title' => 'File Info - ' . $file->getName())); }
private function prepareAuthForm(AphrontFormView $form) { $provider = $this->provider; $auth_uri = $provider->getAuthURI(); $client_id = $provider->getClientID(); $redirect_uri = $provider->getRedirectURI(); $minimum_scope = $provider->getMinimumScope(); $form->setAction($auth_uri)->setMethod('GET')->addHiddenInput('redirect_uri', $redirect_uri)->addHiddenInput('client_id', $client_id)->addHiddenInput('scope', $minimum_scope); foreach ($provider->getExtraAuthParameters() as $key => $value) { $form->addHiddenInput($key, $value); } return $form; }
public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $mail = new PhabricatorMetaMTAMail(); $mail->addTos($request->getArr('to')); $mail->addCCs($request->getArr('cc')); $mail->setSubject($request->getStr('subject')); $mail->setBody($request->getStr('body')); $files = $request->getArr('files'); if ($files) { foreach ($files as $phid) { $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid); $mail->addAttachment(new PhabricatorMetaMTAAttachment($file->loadFileData(), $file->getName(), $file->getMimeType())); } } $mail->setFrom($request->getUser()->getPHID()); $mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setIsHTML($request->getInt('html')); $mail->setIsBulk($request->getInt('bulk')); $mail->setMailTags($request->getStrList('mailtags')); $mail->save(); if ($request->getInt('immediately')) { $mail->sendNow(); } return id(new AphrontRedirectResponse())->setURI('/mail/view/' . $mail->getID() . '/'); } $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA."; $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html'); $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email'); $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>'; $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); $warning = null; if ($adapter == 'PhabricatorMailImplementationTestAdapter') { $warning = new AphrontErrorView(); $warning->setTitle('Email is Disabled'); $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING); $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>'); } $panel_id = celerity_generate_unique_node_id(); $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction('/mail/send/'); $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Configured Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Mail Tags')->setName('mailtags')->setCaption('Example: <tt>differential-cc, differential-comment</tt>'))->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Attach Files')->setName('files')->setDragAndDropTarget($panel_id)->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Bulk')->addCheckbox('bulk', '1', 'Send with bulk email headers.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately, not via MetaMTA background script.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Send Email'); $panel->appendChild($form); $panel->setID($panel_id); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse(array($warning, $panel), array('title' => 'Send Mail')); }
public function render() { $user = $this->getUser(); if (!$user) { throw new Exception("Call setUser() before render()!"); } $form = new AphrontFormView(); $form->setAction('/file/upload/'); $form->setUser($user); $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setCaption('Optional file display name.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Upload')->addCancelButton('/file/')); $panel = new AphrontPanelView(); $panel->setHeader('Upload File'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FULL); return $panel->render(); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $file = PhabricatorFile::newFromPHPUpload(idx($_FILES, 'file'), array('name' => $request->getStr('name'), 'authorPHID' => $user->getPHID())); return id(new AphrontRedirectResponse())->setURI($file->getBestURI()); } $form = new AphrontFormView(); $form->setAction('/file/upload/'); $form->setUser($request->getUser()); $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormFileControl())->setLabel('File')->setName('file')->setError(true))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setCaption('Optional file display name.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Upload')->addCancelButton('/file/')); $panel = new AphrontPanelView(); $panel->setHeader('Upload File'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($panel), array('title' => 'Upload File')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $mail = id(new PhabricatorMetaMTAMail())->load($this->id); if (!$mail) { return new Aphront404Response(); } $status = PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()); $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction('/mail/send/'); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Subject')->setValue($mail->getSubject()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setValue(phabricator_datetime($mail->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Status')->setValue($status))->appendChild(id(new AphrontFormStaticControl())->setLabel('Message')->setValue($mail->getMessage()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Related PHID')->setValue($mail->getRelatedPHID()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Parameters')->setValue(json_encode($mail->getParameters())))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/mail/', 'Done')); $panel = new AphrontPanelView(); $panel->setHeader('View Email'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse($panel, array('title' => 'View Mail')); }
private function showForm($errors = null, $title = "", $content = "", $id = null) { require_celerity_resource('ponder-core-view-css'); require_celerity_resource('phabricator-remarkup-css'); require_celerity_resource('ponder-post-css'); $request = $this->getRequest(); $user = $request->getUser(); $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($user); $form->setAction('/ponder/question/ask/'); $form->appendChild(id(new AphrontFormTextControl())->setLabel('Title')->setName('title')->setValue($title))->appendChild(id(new AphrontFormTextAreaControl())->setName('content')->setID('content')->setValue($content)->setLabel("Question")->setCaption(phutil_render_tag('a', array('href' => PhabricatorEnv::getDoclink('article/Remarkup_Reference.html'), 'tabindex' => '-1', 'target' => '_blank'), "Formatting Reference")))->appendChild(id(new AphrontFormSubmitControl())->setValue('Ask Away!')); $panel = id(new AphrontPanelView())->addClass("ponder-panel")->setHeader("Your Question:")->appendChild($error_view)->appendChild($form); $panel->appendChild('<div class="aphront-panel-flush">' . '<div id="question-preview">' . '<span class="aphront-panel-preview-loading-text">' . 'Loading question preview...' . '</span>' . '</div>' . '</div>'); Javelin::initBehavior('ponder-feedback-preview', array('uri' => '/ponder/question/preview/', 'content' => 'content', 'preview' => 'question-preview', 'question_id' => null)); return $this->buildStandardPageResponse(array($panel), array('title' => 'Ask a Question')); }
public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $parser = new ArcanistDiffParser(); $diff = $request->getStr('diff'); $changes = $parser->parseDiff($diff); $diff = DifferentialDiff::newFromRawChanges($changes); $diff->setLintStatus(DifferentialLintStatus::LINT_SKIP); $diff->setUnitStatus(DifferentialLintStatus::LINT_SKIP); $diff->setAuthorPHID($request->getUser()->getPHID()); $diff->setCreationMethod('web'); $diff->save(); return id(new AphrontRedirectResponse())->setURI('/differential/diff/' . $diff->getID() . '/'); } $form = new AphrontFormView(); $form->setAction('/differential/diff/create/')->setUser($request->getUser())->appendChild('<p class="aphront-form-instructions">The best way to create a ' . 'Differential diff is by using <strong>Arcanist</strong>, but you ' . 'can also just paste a diff (e.g., from <tt>svn diff</tt> or ' . '<tt>git diff</tt>) into this box if you really want.</p>')->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Raw Diff')->setName('diff')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL))->appendChild(id(new AphrontFormSubmitControl())->setValue("Create Diff »")); $panel = new AphrontPanelView(); $panel->setHeader('Create New Diff'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse($panel, array('title' => 'Create Diff', 'tab' => 'create')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); if ($request->isFormPost()) { $files = $request->getArr('file'); if (count($files) > 1) { return id(new AphrontRedirectResponse())->setURI('/file/?author=' . phutil_escape_uri($user->getUserName())); } else { return id(new AphrontRedirectResponse())->setURI('/file/info/' . end($files) . '/'); } } $panel_id = celerity_generate_unique_node_id(); $form = new AphrontFormView(); $form->setAction('/file/upload/'); $form->setUser($request->getUser()); $form->setEncType('multipart/form-data')->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Files')->setName('file')->setError(true)->setDragAndDropTarget($panel_id)->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Done here!')); $panel = new AphrontPanelView(); $panel->setHeader('Upload File'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->setID($panel_id); return $this->buildStandardPageResponse(array($panel), array('title' => 'Upload File')); }
public function processRequest() { $request = $this->getRequest(); $errors = array(); $e_diff = null; $e_file = null; if ($request->isFormPost()) { $diff = null; if ($request->getFileExists('diff-file')) { $diff = PhabricatorFile::readUploadedFileData($_FILES['diff-file']); } else { $diff = $request->getStr('diff'); } if (!strlen($diff)) { $errors[] = pht('You can not create an empty diff. Copy/paste a diff, or upload a ' . 'diff file.'); $e_diff = pht('Required'); $e_file = pht('Required'); } if (!$errors) { $call = new ConduitCall('differential.createrawdiff', array('diff' => $diff)); $call->setUser($request->getUser()); $result = $call->execute(); $path = id(new PhutilURI($result['uri']))->getPath(); return id(new AphrontRedirectResponse())->setURI($path); } } $form = new AphrontFormView(); $arcanist_href = PhabricatorEnv::getDoclink('Arcanist User Guide'); $arcanist_link = phutil_tag('a', array('href' => $arcanist_href, 'target' => '_blank'), 'Arcanist'); $cancel_uri = $this->getApplicationURI(); $form->setAction('/differential/diff/create/')->setEncType('multipart/form-data')->setUser($request->getUser())->appendInstructions(pht('The best way to create a Differential diff is by using %s, but you ' . 'can also just paste a diff (for example, from %s, %s or %s) into ' . 'this box, or upload a diff file.', $arcanist_link, phutil_tag('tt', array(), 'svn diff'), phutil_tag('tt', array(), 'git diff'), phutil_tag('tt', array(), 'hg diff --git')))->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Raw Diff'))->setName('diff')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)->setError($e_diff))->appendChild(id(new AphrontFormFileControl())->setLabel(pht('Raw Diff From File'))->setName('diff-file')->setError($e_file))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($cancel_uri)->setValue(pht('Create Diff'))); $form_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Create New Diff'))->setForm($form)->setFormErrors($errors); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Create Diff')); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => pht('Create Diff'))); }
public function processRequest() { $request = $this->getRequest(); if (!PhabricatorEnv::getEnvConfig('auth.password-auth-enabled')) { return new Aphront400Response(); } $e_email = true; $e_captcha = true; $errors = array(); if ($request->isFormPost()) { $e_email = null; $e_captcha = 'Again'; $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request); if (!$captcha_ok) { $errors[] = "Captcha response is incorrect, try again."; $e_captcha = 'Invalid'; } $email = $request->getStr('email'); if (!strlen($email)) { $errors[] = "You must provide an email address."; $e_email = 'Required'; } if (!$errors) { // NOTE: Don't validate the email unless the captcha is good; this makes // it expensive to fish for valid email addresses while giving the user // a better error if they goof their email. $target_user = id(new PhabricatorUser())->loadOneWhere('email = %s', $email); if (!$target_user) { $errors[] = "There is no account associated with that email address."; $e_email = "Invalid"; } if (!$errors) { $uri = $target_user->getEmailLoginURI(); $body = <<<EOBODY Condolences on forgetting your password. You can use this link to reset it: {$uri} After you set a new password, consider writing it down on a sticky note and attaching it to your monitor so you don't forget again! Choosing a very short, easy-to-remember password like "cat" or "1234" might also help. Best Wishes, Phabricator EOBODY; $mail = new PhabricatorMetaMTAMail(); $mail->setSubject('[Phabricator] Password Reset'); $mail->setFrom($target_user->getPHID()); $mail->addTos(array($target_user->getPHID())); $mail->setBody($body); $mail->saveAndSend(); $view = new AphrontRequestFailureView(); $view->setHeader('Check Your Email'); $view->appendChild('<p>An email has been sent with a link you can use to login.</p>'); return $this->buildStandardPageResponse($view, array('title' => 'Email Sent')); } } } $email_auth = new AphrontFormView(); $email_auth->setAction('/login/email/')->setUser($request->getUser())->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($request->getStr('email'))->setError($e_email))->appendChild(id(new AphrontFormRecaptchaControl())->setLabel('Captcha')->setError($e_captcha))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Email')); $error_view = null; if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Login Error'); $error_view->setErrors($errors); } $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $panel->appendChild('<h1>Forgot Password / Email Login</h1>'); $panel->appendChild($email_auth); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Create New Account')); }
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; $new_email = null; $request = $this->getRequest(); if ($request->isFormPost()) { $welcome_checked = $request->getInt('welcome'); if (!$user->getID()) { $user->setUsername($request->getStr('username')); $new_email = $request->getStr('email'); if (!strlen($new_email)) { $errors[] = 'Email is required.'; $e_email = 'Required'; } else { if (!PhabricatorUserEmail::isAllowedAddress($new_email)) { $e_email = 'Invalid'; $errors[] = PhabricatorUserEmail::describeAllowedAddresses(); } else { $e_email = null; } } if ($request->getStr('role') == 'agent') { $user->setIsSystemAgent(true); } } $user->setRealName($request->getStr('realname')); if (!strlen($user->getUsername())) { $errors[] = "Username is required."; $e_username = '******'; } else { if (!PhabricatorUser::validateUsername($user->getUsername())) { $errors[] = PhabricatorUser::describeValidUsername(); $e_username = '******'; } else { $e_username = null; } } if (!strlen($user->getRealName())) { $errors[] = 'Real name is required.'; $e_realname = 'Required'; } else { $e_realname = null; } if (!$errors) { try { $is_new = !$user->getID(); if (!$is_new) { id(new PhabricatorUserEditor())->setActor($admin)->updateUser($user); } else { $email = id(new PhabricatorUserEmail())->setAddress($new_email)->setIsVerified(0); id(new PhabricatorUserEditor())->setActor($admin)->createNewUser($user, $email); } if ($welcome_checked) { $user->sendWelcomeEmail($admin); } $response = id(new AphrontRedirectResponse())->setURI('/people/edit/' . $user->getID() . '/?saved=true'); return $response; } catch (AphrontQueryDuplicateKeyException $ex) { $errors[] = 'Username and email must be unique.'; $same_username = id(new PhabricatorUser())->loadOneWhere('username = %s', $user->getUsername()); $same_email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $new_email); if ($same_username) { $e_username = '******'; } if ($same_email) { $e_email = 'Duplicate'; } } } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($admin); if ($user->getID()) { $form->setAction('/people/edit/' . $user->getID() . '/'); } else { $form->setAction('/people/edit/'); } if ($user->getID()) { $is_immutable = true; } else { $is_immutable = false; } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Username')->setName('username')->setValue($user->getUsername())->setError($e_username)->setDisabled($is_immutable))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setValue($user->getRealName())->setError($e_realname)); if (!$user->getID()) { $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setDisabled($is_immutable)->setValue($new_email)->setCaption(PhabricatorUserEmail::describeAllowedAddresses())->setError($e_email)); } else { $email = $user->loadPrimaryEmail(); if ($email) { $status = $email->getIsVerified() ? 'Verified' : 'Unverified'; } else { $status = 'No Email Address'; } $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Email')->setValue($status)); $form->appendChild(id(new AphrontFormCheckboxControl())->addCheckbox('welcome', 1, 'Re-send "Welcome to Phabricator" email.', false)); } $form->appendChild($this->getRoleInstructions()); if (!$user->getID()) { $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Role')->setName('role')->setValue('user')->setOptions(array('user' => 'Normal User', 'agent' => 'System Agent'))->setCaption('You can create a "system agent" account for bots, scripts, ' . 'etc.'))->appendChild(id(new AphrontFormCheckboxControl())->addCheckbox('welcome', 1, 'Send "Welcome to Phabricator" email.', $welcome_checked)); } else { $roles = array(); if ($user->getIsSystemAgent()) { $roles[] = 'System Agent'; } if ($user->getIsAdmin()) { $roles[] = 'Admin'; } if ($user->getIsDisabled()) { $roles[] = 'Disabled'; } if (!$roles) { $roles[] = 'Normal User'; } $roles = implode(', ', $roles); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Roles')->setValue($roles)); } $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')); $panel = new AphrontPanelView(); if ($user->getID()) { $panel->setHeader('Edit User'); } else { $panel->setHeader('Create New User'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return array($error_view, $panel); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); if ($this->id) { $page_title = pht('Edit Mailing List'); $list = id(new PhabricatorMailingListQuery())->setViewer($viewer)->withIDs(array($this->id))->executeOne(); if (!$list) { return new Aphront404Response(); } } else { $page_title = pht('Create Mailing List'); $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $e_uri = null; $e_name = true; $errors = array(); $crumbs = $this->buildApplicationCrumbs(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); $e_email = null; $e_name = null; if (!strlen($list->getEmail())) { $e_email = pht('Required'); $errors[] = pht('Email is required.'); } if (!strlen($list->getName())) { $e_name = pht('Required'); $errors[] = pht('Name is required.'); } else { if (preg_match('/[ ,]/', $list->getName())) { $e_name = pht('Invalid'); $errors[] = pht('Name must not contain spaces or commas.'); } } if ($list->getURI()) { if (!PhabricatorEnv::isValidWebResource($list->getURI())) { $e_uri = pht('Invalid'); $errors[] = pht('Mailing list URI must point to a valid web page.'); } } if (!$errors) { try { $list->save(); return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI()); } catch (AphrontDuplicateKeyQueryException $ex) { $e_email = pht('Duplicate'); $errors[] = pht('Another mailing list already uses that address.'); } } } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction($this->getApplicationURI('/edit/' . $list->getID() . '/')); } else { $form->setAction($this->getApplicationURI('/edit/')); } $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($list->getEmail())->setCaption(pht('Email will be delivered to this address.'))->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setError($e_name)->setCaption(pht('Human-readable display and autocomplete name.'))->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel(pht('URI'))->setName('uri')->setError($e_uri)->setCaption(pht('Optional link to mailing list archives or info.'))->setValue($list->getURI()))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save'))->addCancelButton($this->getApplicationURI())); if ($list->getID()) { $crumbs->addTextCrumb(pht('Edit Mailing List')); } else { $crumbs->addTextCrumb(pht('Create Mailing List')); } $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setFormErrors($errors)->setForm($form); return $this->buildApplicationPage(array($crumbs, $form_box), array('title' => $page_title)); }
public function processRequest() { if ($this->id) { $list = id(new PhabricatorMetaMTAMailingList())->load($this->id); if (!$list) { return new Aphront404Response(); } } else { $list = new PhabricatorMetaMTAMailingList(); } $e_email = true; $e_uri = null; $e_name = true; $errors = array(); $request = $this->getRequest(); if ($request->isFormPost()) { $list->setName($request->getStr('name')); $list->setEmail($request->getStr('email')); $list->setURI($request->getStr('uri')); $e_email = null; $e_name = null; if (!strlen($list->getEmail())) { $e_email = 'Required'; $errors[] = 'Email is required.'; } if (!strlen($list->getName())) { $e_name = 'Required'; $errors[] = 'Name is required.'; } else { if (preg_match('/[ ,]/', $list->getName())) { $e_name = 'Invalid'; $errors[] = 'Name must not contain spaces or commas.'; } } if ($list->getURI()) { if (!PhabricatorEnv::isValidWebResource($list->getURI())) { $e_uri = 'Invalid'; $errors[] = 'Mailing list URI must point to a valid web page.'; } } if (!$errors) { try { $list->save(); return id(new AphrontRedirectResponse())->setURI('/mail/lists/'); } catch (AphrontQueryDuplicateKeyException $ex) { $e_email = 'Duplicate'; $errors[] = 'Another mailing list already uses that address.'; } } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($list->getID()) { $form->setAction('/mail/lists/edit/' . $list->getID() . '/'); } else { $form->setAction('/mail/lists/edit/'); } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setValue($list->getEmail())->setCaption('Email will be delivered to this address.')->setError($e_email))->appendChild(id(new AphrontFormTextControl())->setLabel('Name')->setName('name')->setError($e_name)->setCaption('Human-readable display and autocomplete name.')->setValue($list->getName()))->appendChild(id(new AphrontFormTextControl())->setLabel('URI')->setName('uri')->setError($e_uri)->setCaption('Optional link to mailing list archives or info.')->setValue($list->getURI()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setValue(nonempty($list->getID(), '-')))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setValue(nonempty($list->getPHID(), '-')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')->addCancelButton('/mail/lists/')); $panel = new AphrontPanelView(); if ($list->getID()) { $panel->setHeader('Edit Mailing List'); } else { $panel->setHeader('Create New Mailing List'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Mailing List')); }
public function handleRequest(AphrontRequest $request) { $viewer = $this->getViewer(); $id = $request->getURIData('id'); if (!$id) { $id = $request->getInt('revisionID'); } if ($id) { $revision = id(new DifferentialRevisionQuery())->setViewer($viewer)->withIDs(array($id))->needRelationships(true)->needReviewerStatus(true)->needActiveDiffs(true)->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$revision) { return new Aphront404Response(); } } else { $revision = DifferentialRevision::initializeNewRevision($viewer); $revision->attachReviewerStatus(array()); } $diff_id = $request->getInt('diffID'); if ($diff_id) { $diff = id(new DifferentialDiffQuery())->setViewer($viewer)->withIDs(array($diff_id))->executeOne(); if (!$diff) { return new Aphront404Response(); } if ($diff->getRevisionID()) { // TODO: Redirect? throw new Exception(pht('This diff is already attached to a revision!')); } } else { $diff = null; } if (!$diff) { if (!$revision->getID()) { throw new Exception(pht('You can not create a new revision without a diff!')); } } else { // TODO: It would be nice to show the diff being attached in the UI. } $field_list = PhabricatorCustomField::getObjectFields($revision, PhabricatorCustomField::ROLE_EDIT); $field_list->setViewer($viewer)->readFieldsFromStorage($revision); if ($request->getStr('viaDiffView') && $diff) { $repo_key = id(new DifferentialRepositoryField())->getFieldKey(); $repository_field = idx($field_list->getFields(), $repo_key); if ($repository_field) { $repository_field->setValue($request->getStr($repo_key)); } $view_policy_key = id(new DifferentialViewPolicyField())->getFieldKey(); $view_policy_field = idx($field_list->getFields(), $view_policy_key); if ($view_policy_field) { $view_policy_field->setValue($diff->getViewPolicy()); } } $validation_exception = null; if ($request->isFormPost() && !$request->getStr('viaDiffView')) { $editor = id(new DifferentialTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnNoEffect(true); $xactions = $field_list->buildFieldTransactionsFromRequest(new DifferentialTransaction(), $request); if ($diff) { $repository_phid = null; $repository_tokenizer = $request->getArr(id(new DifferentialRepositoryField())->getFieldKey()); if ($repository_tokenizer) { $repository_phid = reset($repository_tokenizer); } $xactions[] = id(new DifferentialTransaction())->setTransactionType(DifferentialTransaction::TYPE_UPDATE)->setNewValue($diff->getPHID()); $editor->setRepositoryPHIDOverride($repository_phid); } $comments = $request->getStr('comments'); if (strlen($comments)) { $xactions[] = id(new DifferentialTransaction())->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)->attachComment(id(new DifferentialTransactionComment())->setContent($comments)); } try { $editor->applyTransactions($revision, $xactions); $revision_uri = '/D' . $revision->getID(); return id(new AphrontRedirectResponse())->setURI($revision_uri); } catch (PhabricatorApplicationTransactionValidationException $ex) { $validation_exception = $ex; } } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($diff) { $form->addHiddenInput('diffID', $diff->getID()); } if ($revision->getID()) { $form->setAction('/differential/revision/edit/' . $revision->getID() . '/'); } else { $form->setAction('/differential/revision/edit/'); } if ($diff && $revision->getID()) { $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel(pht('Comments'))->setName('comments')->setCaption(pht("Explain what's new in this diff."))->setValue($request->getStr('comments')))->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Save')))->appendChild(id(new AphrontFormDividerControl())); } $field_list->appendFieldsToForm($form); $submit = id(new AphrontFormSubmitControl())->setValue('Save'); if ($diff) { $submit->addCancelButton('/differential/diff/' . $diff->getID() . '/'); } else { $submit->addCancelButton('/D' . $revision->getID()); } $form->appendChild($submit); $crumbs = $this->buildApplicationCrumbs(); if ($revision->getID()) { if ($diff) { $header_icon = 'fa-upload'; $title = pht('Update Revision'); $crumbs->addTextCrumb('D' . $revision->getID(), '/differential/diff/' . $diff->getID() . '/'); } else { $header_icon = 'fa-pencil'; $title = pht('Edit Revision: %s', $revision->getTitle()); $crumbs->addTextCrumb('D' . $revision->getID(), '/D' . $revision->getID()); } } else { $header_icon = 'fa-plus-square'; $title = pht('Create New Differential Revision'); } $form_box = id(new PHUIObjectBoxView())->setHeaderText('Revision')->setValidationException($validation_exception)->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setForm($form); $crumbs->addTextCrumb($title); $crumbs->setBorder(true); $header = id(new PHUIHeaderView())->setHeader($title)->setHeaderIcon($header_icon); $view = id(new PHUITwoColumnView())->setHeader($header)->setFooter($form_box); return $this->newPage()->setTitle($title)->setCrumbs($crumbs)->appendChild($view); }
public function processRequest() { $request = $this->getRequest(); if ($request->getUser()->getPHID()) { // Kick the user out if they're already logged in. return id(new AphrontRedirectResponse())->setURI('/'); } if ($request->isConduit()) { // A common source of errors in Conduit client configuration is getting // the request path wrong. The client will end up here, so make some // effort to give them a comprehensible error message. $request_path = $this->getRequest()->getPath(); $conduit_path = '/api/<method>'; $example_path = '/api/conduit.ping'; $message = "ERROR: You are making a Conduit API request to '{$request_path}', " . "but the correct HTTP request path to use in order to access a " . "Conduit method is '{$conduit_path}' (for example, " . "'{$example_path}'). Check your configuration."; return id(new AphrontPlainTextResponse())->setContent($message); } $error_view = null; if ($request->getCookie('phusr') && $request->getCookie('phsid')) { // The session cookie is invalid, so clear it. $request->clearCookie('phusr'); $request->clearCookie('phsid'); $error_view = new AphrontErrorView(); $error_view->setTitle('Invalid Session'); $error_view->setErrors(array("Your login session is invalid. Try logging in again. If that " . "doesn't work, clear your browser cookies.")); } $next_uri = $this->getRequest()->getPath(); if ($next_uri == '/login/') { $next_uri = '/'; } if (!$request->isFormPost()) { $request->setCookie('next_uri', $next_uri); } $password_auth = PhabricatorEnv::getEnvConfig('auth.password-auth-enabled'); $forms = array(); $errors = array(); if ($password_auth) { $require_captcha = false; $e_captcha = true; $username_or_email = $request->getCookie('phusr'); if ($request->isFormPost()) { if (AphrontFormRecaptchaControl::isRecaptchaEnabled()) { $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP(PhabricatorUserLog::ACTION_LOGIN_FAILURE, 60 * 15); if (count($failed_attempts) > 5) { $require_captcha = true; if (!AphrontFormRecaptchaControl::processCaptcha($request)) { if (AphrontFormRecaptchaControl::hasCaptchaResponse($request)) { $e_captcha = 'Invalid'; $errors[] = 'CAPTCHA was not entered correctly.'; } else { $e_captcha = 'Required'; $errors[] = 'Too many login failures recently. You must ' . 'submit a CAPTCHA with your login request.'; } } } } $username_or_email = $request->getStr('username_or_email'); $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username_or_email); if (!$user) { $user = id(new PhabricatorUser())->loadOneWhere('email = %s', $username_or_email); } if (!$errors) { // Perform username/password tests only if we didn't get rate limited // by the CAPTCHA. if (!$user || !$user->comparePassword($request->getStr('password'))) { $errors[] = 'Bad username/password.'; } } if (!$errors) { $session_key = $user->establishSession('web'); $request->setCookie('phusr', $user->getUsername()); $request->setCookie('phsid', $session_key); $uri = new PhutilURI('/login/validate/'); $uri->setQueryParams(array('phusr' => $user->getUsername())); return id(new AphrontRedirectResponse())->setURI((string) $uri); } else { $log = PhabricatorUserLog::newLog(null, $user, PhabricatorUserLog::ACTION_LOGIN_FAILURE); $log->save(); $request->clearCookie('phusr'); $request->clearCookie('phsid'); } } if ($errors) { $error_view = new AphrontErrorView(); $error_view->setTitle('Login Failed'); $error_view->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($request->getUser())->setAction('/login/')->appendChild(id(new AphrontFormTextControl())->setLabel('Username/Email')->setName('username_or_email')->setValue($username_or_email))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password')->setCaption('<a href="/login/email/">' . 'Forgot your password? / Email Login</a>')); if ($require_captcha) { $form->appendChild(id(new AphrontFormRecaptchaControl())->setError($e_captcha)); } $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Login')); // $panel->setCreateButton('Register New Account', '/login/register/'); $forms['Phabricator Login'] = $form; } $providers = PhabricatorOAuthProvider::getAllProviders(); foreach ($providers as $provider) { $enabled = $provider->isProviderEnabled(); if (!$enabled) { continue; } $auth_uri = $provider->getAuthURI(); $redirect_uri = $provider->getRedirectURI(); $client_id = $provider->getClientID(); $provider_name = $provider->getProviderName(); $minimum_scope = $provider->getMinimumScope(); $extra_auth = $provider->getExtraAuthParameters(); // TODO: In theory we should use 'state' to prevent CSRF, but the total // effect of the CSRF attack is that an attacker can cause a user to login // to Phabricator if they're already logged into some OAuth provider. This // does not seem like the most severe threat in the world, and generating // CSRF for logged-out users is vaugely tricky. if ($provider->isProviderRegistrationEnabled()) { $title = "Login or Register with {$provider_name}"; $body = 'Login or register for Phabricator using your ' . phutil_escape_html($provider_name) . ' account.'; $button = "Login or Register with {$provider_name}"; } else { $title = "Login with {$provider_name}"; $body = 'Login to your existing Phabricator account using your ' . phutil_escape_html($provider_name) . ' account.<br /><br />' . '<strong>You can not use ' . phutil_escape_html($provider_name) . ' to register a new ' . 'account.</strong>'; $button = "Login with {$provider_name}"; } $auth_form = new AphrontFormView(); $auth_form->setAction($auth_uri)->addHiddenInput('client_id', $client_id)->addHiddenInput('redirect_uri', $redirect_uri)->addHiddenInput('scope', $minimum_scope); foreach ($extra_auth as $key => $value) { $auth_form->addHiddenInput($key, $value); } $auth_form->setUser($request->getUser())->setMethod('GET')->appendChild('<p class="aphront-form-instructions">' . $body . '</p>')->appendChild(id(new AphrontFormSubmitControl())->setValue("{$button} »")); $forms[$title] = $auth_form; } $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); foreach ($forms as $name => $form) { $panel->appendChild('<h1>' . $name . '</h1>'); $panel->appendChild($form); $panel->appendChild('<br />'); } return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Login')); }
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 = '******'; } else { if (!PhabricatorUser::validateUsername($user->getUsername())) { $errors[] = "Username must consist of only numbers and letters."; $e_username = '******'; } 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) { $user->sendWelcomeEmail($admin); } } $response = id(new AphrontRedirectResponse())->setURI('/people/edit/' . $user->getID() . '/?saved=true'); return $response; } catch (AphrontQueryDuplicateKeyException $ex) { $errors[] = 'Username and email must be unique.'; $same_username = id(new PhabricatorUser())->loadOneWhere('username = %s', $user->getUsername()); $same_email = id(new PhabricatorUser())->loadOneWhere('email = %s', $user->getEmail()); if ($same_username) { $e_username = '******'; } if ($same_email) { $e_email = 'Duplicate'; } } } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } $form = new AphrontFormView(); $form->setUser($admin); if ($user->getID()) { $form->setAction('/people/edit/' . $user->getID() . '/'); } else { $form->setAction('/people/edit/'); } if ($user->getID()) { $is_immutable = true; } else { $is_immutable = false; } $form->appendChild(id(new AphrontFormTextControl())->setLabel('Username')->setName('username')->setValue($user->getUsername())->setError($e_username)->setDisabled($is_immutable)->setCaption('Usernames are permanent and can not be changed later!'))->appendChild(id(new AphrontFormTextControl())->setLabel('Real Name')->setName('realname')->setValue($user->getRealName())->setError($e_realname))->appendChild(id(new AphrontFormTextControl())->setLabel('Email')->setName('email')->setDisabled($is_immutable)->setValue($user->getEmail())->setError($e_email))->appendChild($this->getRoleInstructions()); if (!$user->getID()) { $form->appendChild(id(new AphrontFormSelectControl())->setLabel('Role')->setName('role')->setValue('user')->setOptions(array('user' => 'Normal User', 'agent' => 'System Agent'))->setCaption('You can create a "system agent" account for bots, scripts, ' . 'etc.'))->appendChild(id(new AphrontFormCheckboxControl())->addCheckbox('welcome', 1, 'Send "Welcome to Phabricator" email.', $welcome_checked)); } else { $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Role')->setValue($user->getIsSystemAgent() ? 'System Agent' : 'Normal User')); } $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Save')); $panel = new AphrontPanelView(); if ($user->getID()) { $panel->setHeader('Edit User'); } else { $panel->setHeader('Create New User'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return array($error_view, $panel); }
public function processRequest() { $request = $this->getRequest(); if (!$this->id) { $this->id = $request->getInt('revisionID'); } if ($this->id) { $revision = id(new DifferentialRevision())->load($this->id); if (!$revision) { return new Aphront404Response(); } } else { $revision = new DifferentialRevision(); } $revision->loadRelationships(); $aux_fields = $this->loadAuxiliaryFields($revision); $diff_id = $request->getInt('diffID'); if ($diff_id) { $diff = id(new DifferentialDiff())->load($diff_id); if (!$diff) { return new Aphront404Response(); } if ($diff->getRevisionID()) { // TODO: Redirect? throw new Exception("This diff is already attached to a revision!"); } } else { $diff = null; } $errors = array(); if ($request->isFormPost() && !$request->getStr('viaDiffView')) { $user_phid = $request->getUser()->getPHID(); foreach ($aux_fields as $aux_field) { $aux_field->setValueFromRequest($request); try { $aux_field->validateField(); } catch (DifferentialFieldValidationException $ex) { $errors[] = $ex->getMessage(); } } if (!$errors) { $editor = new DifferentialRevisionEditor($revision, $user_phid); if ($diff) { $editor->addDiff($diff, $request->getStr('comments')); } $editor->setAuxiliaryFields($aux_fields); $editor->save(); return id(new AphrontRedirectResponse())->setURI('/D' . $revision->getID()); } } $aux_phids = array(); foreach ($aux_fields as $key => $aux_field) { $aux_phids[$key] = $aux_field->getRequiredHandlePHIDsForRevisionEdit(); } $phids = array_mergev($aux_phids); $phids = array_unique($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); foreach ($aux_fields as $key => $aux_field) { $aux_field->setHandles(array_select_keys($handles, $aux_phids[$key])); } $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($diff) { $form->addHiddenInput('diffID', $diff->getID()); } if ($revision->getID()) { $form->setAction('/differential/revision/edit/' . $revision->getID() . '/'); } else { $form->setAction('/differential/revision/edit/'); } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } if ($diff && $revision->getID()) { $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Comments')->setName('comments')->setCaption("Explain what's new in this diff.")->setValue($request->getStr('comments')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'))->appendChild(id(new AphrontFormDividerControl())); } foreach ($aux_fields as $aux_field) { $control = $aux_field->renderEditControl(); if ($control) { $form->appendChild($control); } } $submit = id(new AphrontFormSubmitControl())->setValue('Save'); if ($diff) { $submit->addCancelButton('/differential/diff/' . $diff->getID() . '/'); } else { $submit->addCancelButton('/D' . $revision->getID()); } $form->appendChild($submit); $panel = new AphrontPanelView(); if ($revision->getID()) { if ($diff) { $panel->setHeader('Update Differential Revision'); } else { $panel->setHeader('Edit Differential Revision'); } } else { $panel->setHeader('Create New Differential Revision'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Differential Revision')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $provider = $this->provider; $notice = null; $provider_name = $provider->getProviderName(); $provider_key = $provider->getProviderKey(); $oauth_info = id(new PhabricatorUserOAuthInfo())->loadOneWhere('userID = %d AND oauthProvider = %s', $user->getID(), $provider->getProviderKey()); $form = new AphrontFormView(); $form->setUser($user); $forms = array(); $forms[] = $form; if (!$oauth_info) { $form->appendChild('<p class="aphront-form-instructions">There is currently no ' . $provider_name . ' account linked to your Phabricator account. You ' . 'can link an account, which will allow you to use it to log into ' . 'Phabricator.</p>'); switch ($provider_key) { case PhabricatorOAuthProvider::PROVIDER_GITHUB: $form->appendChild('<p class="aphront-form-instructions">Additionally, you must ' . 'link your Github account before Phabricator can access any ' . 'information about hosted repositories.</p>'); break; } $auth_uri = $provider->getAuthURI(); $client_id = $provider->getClientID(); $redirect_uri = $provider->getRedirectURI(); $minimum_scope = $provider->getMinimumScope(); $form->setAction($auth_uri)->setMethod('GET')->addHiddenInput('redirect_uri', $redirect_uri)->addHiddenInput('client_id', $client_id)->addHiddenInput('scope', $minimum_scope); foreach ($provider->getExtraAuthParameters() as $key => $value) { $form->addHiddenInput($key, $value); } $form->appendChild(id(new AphrontFormSubmitControl())->setValue('Link ' . $provider_name . " Account »")); } else { $form->appendChild('<p class="aphront-form-instructions">Your account is linked with ' . 'a ' . $provider_name . ' account. You may use your ' . $provider_name . ' ' . 'credentials to log into Phabricator.</p>')->appendChild(id(new AphrontFormStaticControl())->setLabel($provider_name . ' ID')->setValue($oauth_info->getOAuthUID()))->appendChild(id(new AphrontFormStaticControl())->setLabel($provider_name . ' Name')->setValue($oauth_info->getAccountName()))->appendChild(id(new AphrontFormStaticControl())->setLabel($provider_name . ' URI')->setValue($oauth_info->getAccountURI())); if (!$provider->isProviderLinkPermanent()) { $unlink = 'Unlink ' . $provider_name . ' Account'; $unlink_form = new AphrontFormView(); $unlink_form->setUser($user)->appendChild('<p class="aphront-form-instructions">You may unlink this account ' . 'from your ' . $provider_name . ' account. This will prevent you from ' . 'logging in with your ' . $provider_name . ' credentials.</p>')->appendChild(id(new AphrontFormSubmitControl())->addCancelButton('/oauth/' . $provider_key . '/unlink/', $unlink)); $forms['Unlink Account'] = $unlink_form; } $expires = $oauth_info->getTokenExpires(); if ($expires) { if ($expires <= time()) { $expires = "Expired"; } else { $expires = phabricator_datetime($expires, $user); } } else { $expires = 'No Information Available'; } $scope = $oauth_info->getTokenScope(); if (!$scope) { $scope = 'No Information Available'; } $status = $oauth_info->getTokenStatus(); $status = PhabricatorUserOAuthInfo::getReadableTokenStatus($status); $token_form = new AphrontFormView(); $token_form->setUser($user)->appendChild('<p class="aphront-from-instructions">insert rap about tokens</p>')->appendChild(id(new AphrontFormStaticControl())->setLabel('Token Status')->setValue($status))->appendChild(id(new AphrontFormStaticControl())->setLabel('Expires')->setValue($expires))->appendChild(id(new AphrontFormStaticControl())->setLabel('Scope')->setValue($scope)); $forms['Account Token Information'] = $token_form; } $panel = new AphrontPanelView(); $panel->setHeader($provider_name . ' Account Settings'); $panel->setWidth(AphrontPanelView::WIDTH_FORM); foreach ($forms as $name => $form) { if ($name) { $panel->appendChild('<br /><br /><h1>' . $name . '</h1>'); } $panel->appendChild($form); } return id(new AphrontNullView())->appendChild(array($notice, $panel)); }
public function processRequest() { $request = $this->getRequest(); if (!$this->id) { $this->id = $request->getInt('revisionID'); } if ($this->id) { $revision = id(new DifferentialRevision())->load($this->id); if (!$revision) { return new Aphront404Response(); } } else { $revision = new DifferentialRevision(); } $diff_id = $request->getInt('diffID'); if ($diff_id) { $diff = id(new DifferentialDiff())->load($diff_id); if (!$diff) { return new Aphront404Response(); } if ($diff->getRevisionID()) { // TODO: Redirect? throw new Exception("This diff is already attached to a revision!"); } } else { $diff = null; } $e_title = true; $e_testplan = true; $e_reviewers = null; $errors = array(); $revision->loadRelationships(); if ($request->isFormPost() && !$request->getStr('viaDiffView')) { $revision->setTitle($request->getStr('title')); $revision->setSummary($request->getStr('summary')); $revision->setTestPlan($request->getStr('testplan')); $revision->setBlameRevision($request->getStr('blame')); $revision->setRevertPlan($request->getStr('revert')); if (!strlen(trim($revision->getTitle()))) { $errors[] = 'You must provide a title.'; $e_title = 'Required'; } else { $e_title = null; } if (!strlen(trim($revision->getTestPlan()))) { $errors[] = 'You must provide a test plan.'; $e_testplan = 'Required'; } else { $e_testplan = null; } $user_phid = $request->getUser()->getPHID(); if (in_array($user_phid, $request->getArr('reviewers'))) { $errors[] = 'You may not review your own revision.'; $e_reviewers = 'Invalid'; } if (!$errors) { $editor = new DifferentialRevisionEditor($revision, $user_phid); if ($diff) { $editor->addDiff($diff, $request->getStr('comments')); } $editor->setCCPHIDs($request->getArr('cc')); $editor->setReviewers($request->getArr('reviewers')); $editor->save(); return id(new AphrontRedirectResponse())->setURI('/D' . $revision->getID()); } $reviewer_phids = $request->getArr('reviewers'); $cc_phids = $request->getArr('cc'); } else { $reviewer_phids = $revision->getReviewers(); $cc_phids = $revision->getCCPHIDs(); } $phids = array_merge($reviewer_phids, $cc_phids); $phids = array_unique($phids); $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); $handles = mpull($handles, 'getFullName', 'getPHID'); $reviewer_map = array_select_keys($handles, $reviewer_phids); $cc_map = array_select_keys($handles, $cc_phids); $form = new AphrontFormView(); $form->setUser($request->getUser()); if ($diff) { $form->addHiddenInput('diffID', $diff->getID()); } if ($revision->getID()) { $form->setAction('/differential/revision/edit/' . $revision->getID() . '/'); } else { $form->setAction('/differential/revision/edit/'); } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle('Form Errors')->setErrors($errors); } if ($diff && $revision->getID()) { $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Comments')->setName('comments')->setCaption("Explain what's new in this diff.")->setValue($request->getStr('comments')))->appendChild(id(new AphrontFormSubmitControl())->setValue('Save'))->appendChild(id(new AphrontFormDividerControl())); } $form->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Title')->setName('title')->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setValue($revision->getTitle())->setError($e_title))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Summary')->setName('summary')->setValue($revision->getSummary()))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Test Plan')->setName('testplan')->setValue($revision->getTestPlan())->setError($e_testplan))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('Reviewers')->setName('reviewers')->setDatasource('/typeahead/common/users/')->setError($e_reviewers)->setValue($reviewer_map))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/')->setValue($cc_map))->appendChild(id(new AphrontFormTextControl())->setLabel('Blame Revision')->setName('blame')->setValue($revision->getBlameRevision())->setCaption('Revision which broke the stuff which this ' . 'change fixes.'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Revert Plan')->setName('revert')->setValue($revision->getRevertPlan())->setCaption('Special steps required to safely revert this change.')); $submit = id(new AphrontFormSubmitControl())->setValue('Save'); if ($diff) { $submit->addCancelButton('/differential/diff/' . $diff->getID() . '/'); } else { $submit->addCancelButton('/D' . $revision->getID()); } $form->appendChild($submit); $panel = new AphrontPanelView(); if ($revision->getID()) { if ($diff) { $panel->setHeader('Update Differential Revision'); } else { $panel->setHeader('Edit Differential Revision'); } } else { $panel->setHeader('Create New Differential Revision'); } $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Edit Differential Revision')); }
public function processRequest() { $request = $this->getRequest(); if ($request->getUser()->getPHID()) { // Kick the user out if they're already logged in. return id(new AphrontRedirectResponse())->setURI('/'); } $next_uri = $this->getRequest()->getPath(); $request->setCookie('next_uri', $next_uri); if ($next_uri == '/login/' && !$request->isFormPost()) { // The user went straight to /login/, so presumably they want to go // to the dashboard upon logging in. Because, you know, that's logical. // And people are logical. Sometimes... Fine, no they're not. // We check for POST here because getPath() would get reset to /login/. $request->setCookie('next_uri', '/'); } // Always use $request->getCookie('next_uri', '/') after the above. $password_auth = PhabricatorEnv::getEnvConfig('auth.password-auth-enabled'); $forms = array(); $error_view = null; if ($password_auth) { $error = false; $username_or_email = $request->getCookie('phusr'); if ($request->isFormPost()) { $username_or_email = $request->getStr('username_or_email'); $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username_or_email); if (!$user) { $user = id(new PhabricatorUser())->loadOneWhere('email = %s', $username_or_email); } $okay = false; if ($user) { if ($user->comparePassword($request->getStr('password'))) { $session_key = $user->establishSession('web'); $request->setCookie('phusr', $user->getUsername()); $request->setCookie('phsid', $session_key); return id(new AphrontRedirectResponse())->setURI($request->getCookie('next_uri', '/')); } else { $log = PhabricatorUserLog::newLog(null, $user, PhabricatorUserLog::ACTION_LOGIN_FAILURE); $log->save(); } } if (!$okay) { $request->clearCookie('phusr'); $request->clearCookie('phsid'); } $error = true; } if ($error) { $error_view = new AphrontErrorView(); $error_view->setTitle('Bad username/password.'); } $form = new AphrontFormView(); $form->setUser($request->getUser())->setAction('/login/')->appendChild(id(new AphrontFormTextControl())->setLabel('Username/Email')->setName('username_or_email')->setValue($username_or_email))->appendChild(id(new AphrontFormPasswordControl())->setLabel('Password')->setName('password')->setCaption('<a href="/login/email/">' . 'Forgot your password? / Email Login</a>'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Login')); // $panel->setCreateButton('Register New Account', '/login/register/'); $forms['Phabricator Login'] = $form; } $providers = PhabricatorOAuthProvider::getAllProviders(); foreach ($providers as $provider) { $enabled = $provider->isProviderEnabled(); if (!$enabled) { continue; } $auth_uri = $provider->getAuthURI(); $redirect_uri = $provider->getRedirectURI(); $client_id = $provider->getClientID(); $provider_name = $provider->getProviderName(); $minimum_scope = $provider->getMinimumScope(); $extra_auth = $provider->getExtraAuthParameters(); // TODO: In theory we should use 'state' to prevent CSRF, but the total // effect of the CSRF attack is that an attacker can cause a user to login // to Phabricator if they're already logged into some OAuth provider. This // does not seem like the most severe threat in the world, and generating // CSRF for logged-out users is vaugely tricky. if ($provider->isProviderRegistrationEnabled()) { $title = "Login or Register with {$provider_name}"; $body = "Login or register for Phabricator using your " . "{$provider_name} account."; $button = "Login or Register with {$provider_name}"; } else { $title = "Login with {$provider_name}"; $body = "Login to your existing Phabricator account using your " . "{$provider_name} account.<br /><br /><strong>You can not use " . "{$provider_name} to register a new account.</strong>"; $button = "Login with {$provider_name}"; } $auth_form = new AphrontFormView(); $auth_form->setAction($auth_uri)->addHiddenInput('client_id', $client_id)->addHiddenInput('redirect_uri', $redirect_uri)->addHiddenInput('scope', $minimum_scope); foreach ($extra_auth as $key => $value) { $auth_form->addHiddenInput($key, $value); } $auth_form->setUser($request->getUser())->setMethod('GET')->appendChild('<p class="aphront-form-instructions">' . $body . '</p>')->appendChild(id(new AphrontFormSubmitControl())->setValue("{$button} »")); $forms[$title] = $auth_form; } $panel = new AphrontPanelView(); $panel->setWidth(AphrontPanelView::WIDTH_FORM); foreach ($forms as $name => $form) { $panel->appendChild('<h1>' . $name . '</h1>'); $panel->appendChild($form); $panel->appendChild('<br />'); } return $this->buildStandardPageResponse(array($error_view, $panel), array('title' => 'Login')); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid); if (!$file) { return new Aphront404Response(); } switch ($this->view) { case 'download': case 'view': $data = $file->loadFileData(); $response = new AphrontFileResponse(); $response->setContent($data); $response->setCacheDurationInSeconds(60 * 60 * 24 * 30); if ($this->view == 'view') { if (!$file->isViewableInBrowser()) { return new Aphront400Response(); } $download = false; } else { $download = true; } if ($download) { if (!$request->isFormPost()) { // Require a POST to download files to hinder attacks where you // <applet src="http://phabricator.example.com/file/..." /> on some // other domain. return id(new AphrontRedirectResponse())->setURI($file->getInfoURI()); } } if ($download) { $mime_type = $file->getMimeType(); } else { $mime_type = $file->getViewableMimeType(); } // If an alternate file domain is configured, forbid all views which // don't originate from it. if (!$download) { $alt = PhabricatorEnv::getEnvConfig('security.alternate-file-domain'); if ($alt) { $domain = id(new PhutilURI($alt))->getDomain(); if ($domain != $request->getHost()) { return new Aphront400Response(); } } } $response->setMimeType($mime_type); if ($download) { $response->setDownload($file->getName()); } return $response; default: break; } $author_child = null; if ($file->getAuthorPHID()) { $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $file->getAuthorPHID()); if ($author) { $author_child = id(new AphrontFormStaticControl())->setLabel('Author')->setName('author')->setValue($author->getUserName()); } } $form = new AphrontFormView(); if ($file->isViewableInBrowser()) { $form->setAction($file->getViewURI()); $button_name = 'View File'; } else { $form->setAction('/file/download/' . $file->getPHID() . '/'); $button_name = 'Download File'; } $file_id = 'F' . $file->getID(); $form->setUser($user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setName('name')->setValue($file->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setName('id')->setValue($file_id)->setCaption('Download this file with: <tt>arc download ' . phutil_escape_html($file_id) . '</tt>'))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setName('phid')->setValue($file->getPHID()))->appendChild($author_child)->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setName('created')->setValue(phabricator_datetime($file->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Mime Type')->setName('mime')->setValue($file->getMimeType()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Size')->setName('size')->setValue($file->getByteSize() . ' bytes'))->appendChild(id(new AphrontFormStaticControl())->setLabel('Engine')->setName('storageEngine')->setValue($file->getStorageEngine()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Format')->setName('storageFormat')->setValue($file->getStorageFormat()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Handle')->setName('storageHandle')->setValue($file->getStorageHandle()))->appendChild(id(new AphrontFormSubmitControl())->setValue($button_name)); $panel = new AphrontPanelView(); $panel->setHeader('File Info - ' . $file->getName()); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $transformations = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID()); $rows = array(); foreach ($transformations as $transformed) { $phid = $transformed->getTransformedPHID(); $rows[] = array(phutil_escape_html($transformed->getTransform()), phutil_render_tag('a', array('href' => PhabricatorFileURI::getViewURIForPHID($phid)), $phid)); } $table = new AphrontTableView($rows); $table->setHeaders(array('Transform', 'File')); $xform_panel = new AphrontPanelView(); $xform_panel->appendChild($table); $xform_panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel->setHeader('Transformations'); return $this->buildStandardPageResponse(array($panel, $xform_panel), array('title' => 'File Info - ' . $file->getName())); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $this->phid); if (!$file) { return new Aphront404Response(); } switch ($this->view) { case 'download': case 'view': $data = $file->loadFileData(); $response = new AphrontFileResponse(); $response->setContent($data); $response->setCacheDurationInSeconds(60 * 60 * 24 * 30); if ($this->view == 'view') { if (!$file->isViewableInBrowser()) { return new Aphront400Response(); } $download = false; } else { $download = true; } if ($download) { $mime_type = $file->getMimeType(); } else { $mime_type = $file->getViewableMimeType(); } $response->setMimeType($mime_type); if ($download) { $response->setDownload($file->getName()); } return $response; default: break; } $author_child = null; if ($file->getAuthorPHID()) { $author = id(new PhabricatorUser())->loadOneWhere('phid = %s', $file->getAuthorPHID()); if ($author) { $author_child = id(new AphrontFormStaticControl())->setLabel('Author')->setName('author')->setValue($author->getUserName()); } } $form = new AphrontFormView(); if ($file->isViewableInBrowser()) { $form->setAction('/file/view/' . $file->getPHID() . '/'); $button_name = 'View File'; } else { $form->setAction('/file/download/' . $file->getPHID() . '/'); $button_name = 'Download File'; } $file_id = 'F' . $file->getID(); $form->setUser($user); $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Name')->setName('name')->setValue($file->getName()))->appendChild(id(new AphrontFormStaticControl())->setLabel('ID')->setName('id')->setValue($file_id)->setCaption('Download this file with: <tt>arc download ' . phutil_escape_html($file_id) . '</tt>'))->appendChild(id(new AphrontFormStaticControl())->setLabel('PHID')->setName('phid')->setValue($file->getPHID()))->appendChild($author_child)->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setName('created')->setValue(phabricator_datetime($file->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Mime Type')->setName('mime')->setValue($file->getMimeType()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Size')->setName('size')->setValue($file->getByteSize() . ' bytes'))->appendChild(id(new AphrontFormStaticControl())->setLabel('Engine')->setName('storageEngine')->setValue($file->getStorageEngine()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Format')->setName('storageFormat')->setValue($file->getStorageFormat()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Handle')->setName('storageHandle')->setValue($file->getStorageHandle()))->appendChild(id(new AphrontFormSubmitControl())->setValue($button_name)); $panel = new AphrontPanelView(); $panel->setHeader('File Info - ' . $file->getName()); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $transformations = id(new PhabricatorTransformedFile())->loadAllWhere('originalPHID = %s', $file->getPHID()); $rows = array(); foreach ($transformations as $transformed) { $phid = $transformed->getTransformedPHID(); $rows[] = array(phutil_escape_html($transformed->getTransform()), phutil_render_tag('a', array('href' => PhabricatorFileURI::getViewURIForPHID($phid)), $phid)); } $table = new AphrontTableView($rows); $table->setHeaders(array('Transform', 'File')); $xform_panel = new AphrontPanelView(); $xform_panel->appendChild($table); $xform_panel->setWidth(AphrontPanelView::WIDTH_FORM); $xform_panel->setHeader('Transformations'); return $this->buildStandardPageResponse(array($panel, $xform_panel), array('title' => 'File Info - ' . $file->getName())); }