public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $phid = $this->phid; $handle = id(new PhabricatorHandleQuery())->setViewer($user)->withPHIDs(array($phid))->executeOne(); if (!$handle->isComplete()) { return new Aphront404Response(); } $flag = PhabricatorFlagQuery::loadUserFlag($user, $phid); if (!$flag) { $flag = new PhabricatorFlag(); $flag->setOwnerPHID($user->getPHID()); $flag->setType($handle->getType()); $flag->setObjectPHID($handle->getPHID()); $flag->setReasonPHID($user->getPHID()); } if ($request->isDialogFormPost()) { $flag->setColor($request->getInt('color')); $flag->setNote($request->getStr('note')); $flag->save(); return id(new AphrontReloadResponse())->setURI('/flag/'); } $type_name = $handle->getTypeName(); $dialog = new AphrontDialogView(); $dialog->setUser($user); $dialog->setTitle(pht('Flag %s', $type_name)); require_celerity_resource('phabricator-flag-css'); $form = new PHUIFormLayoutView(); $is_new = !$flag->getID(); if ($is_new) { $form->appendChild(hsprintf('<p>%s</p><br />', pht('You can flag this %s if you want to remember to look ' . 'at it later.', $type_name))); } $radio = new AphrontFormRadioButtonControl(); foreach (PhabricatorFlagColor::getColorNameMap() as $color => $text) { $class = 'phabricator-flag-radio phabricator-flag-color-' . $color; $radio->addButton($color, $text, '', $class); } $form->appendChild($radio->setName('color')->setLabel(pht('Flag Color'))->setValue($flag->getColor()))->appendChild(id(new AphrontFormTextAreaControl())->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_SHORT)->setName('note')->setLabel(pht('Note'))->setValue($flag->getNote())); $dialog->appendChild($form); $dialog->addCancelButton($handle->getURI()); $dialog->addSubmitButton($is_new ? pht('Create Flag') : pht('Save')); return id(new AphrontDialogResponse())->setDialog($dialog); }
public function handleRequest(AphrontRequest $request) { if (!PhabricatorPasswordAuthProvider::getPasswordProvider()) { return new Aphront400Response(); } $e_email = true; $e_captcha = true; $errors = array(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); if ($request->isFormPost()) { $e_email = null; $e_captcha = pht('Again'); $captcha_ok = AphrontFormRecaptchaControl::processCaptcha($request); if (!$captcha_ok) { $errors[] = pht('Captcha response is incorrect, try again.'); $e_captcha = pht('Invalid'); } $email = $request->getStr('email'); if (!strlen($email)) { $errors[] = pht('You must provide an email address.'); $e_email = pht('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_email = id(new PhabricatorUserEmail())->loadOneWhere('address = %s', $email); $target_user = null; if ($target_email) { $target_user = id(new PhabricatorUser())->loadOneWhere('phid = %s', $target_email->getUserPHID()); } if (!$target_user) { $errors[] = pht('There is no account associated with that email address.'); $e_email = pht('Invalid'); } // If this address is unverified, only send a reset link to it if // the account has no verified addresses. This prevents an opportunistic // attacker from compromising an account if a user adds an email // address but mistypes it and doesn't notice. // (For a newly created account, all the addresses may be unverified, // which is why we'll send to an unverified address in that case.) if ($target_email && !$target_email->getIsVerified()) { $verified_addresses = id(new PhabricatorUserEmail())->loadAllWhere('userPHID = %s AND isVerified = 1', $target_email->getUserPHID()); if ($verified_addresses) { $errors[] = pht('That email address is not verified. You can only send ' . 'password reset links to a verified address.'); $e_email = pht('Unverified'); } } if (!$errors) { $engine = new PhabricatorAuthSessionEngine(); $uri = $engine->getOneTimeLoginURI($target_user, null, PhabricatorAuthSessionEngine::ONETIME_RESET); if ($is_serious) { $body = pht("You can use this link to reset your Phabricator password:"******"\n\n %s\n", $uri); } else { $body = pht("Condolences on forgetting your password. You can use this " . "link to reset it:\n\n" . " %s\n\n" . "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.\n\n" . "Best Wishes,\nPhabricator\n", $uri); } $mail = id(new PhabricatorMetaMTAMail())->setSubject(pht('[Phabricator] Password Reset'))->setForceDelivery(true)->addRawTos(array($target_email->getAddress()))->setBody($body)->saveAndSend(); return $this->newDialog()->setTitle(pht('Check Your Email'))->setShortTitle(pht('Email Sent'))->appendParagraph(pht('An email has been sent with a link you can use to login.'))->addCancelButton('/', pht('Done')); } } } $error_view = null; if ($errors) { $error_view = new PHUIInfoView(); $error_view->setErrors($errors); } $email_auth = new PHUIFormLayoutView(); $email_auth->appendChild($error_view); $email_auth->setUser($request->getUser())->setFullWidth(true)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Email'))->setName('email')->setValue($request->getStr('email'))->setError($e_email))->appendChild(id(new AphrontFormRecaptchaControl())->setLabel(pht('Captcha'))->setError($e_captcha)); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Reset Password')); $dialog = new AphrontDialogView(); $dialog->setUser($request->getUser()); $dialog->setTitle(pht('Forgot Password / Email Login')); $dialog->appendChild($email_auth); $dialog->addSubmitButton(pht('Send Email')); $dialog->setSubmitURI('/login/email/'); return $this->buildApplicationPage(array($crumbs, $dialog), array('title' => pht('Forgot Password'))); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $phid = $this->phid; $handle = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($phid))->executeOne(); $done_uri = $handle->getURI(); $current_timer = null; switch ($this->verb) { case 'start': $button_text = pht('Start Tracking'); $title_text = pht('Start Tracking Time'); $inner_text = pht('What time did you start working?'); $action_text = pht('Start Timer'); $label_text = pht('Start Time'); break; case 'stop': $button_text = pht('Stop Tracking'); $title_text = pht('Stop Tracking Time'); $inner_text = pht('What time did you stop working?'); $action_text = pht('Stop Timer'); $label_text = pht('Stop Time'); $current_timer = id(new PhrequentUserTimeQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->withObjectPHIDs(array($phid))->withEnded(PhrequentUserTimeQuery::ENDED_NO)->executeOne(); if (!$current_timer) { return $this->newDialog()->setTitle(pht('Not Tracking Time'))->appendParagraph(pht('You are not currently tracking time on this object.'))->addCancelButton($done_uri); } break; default: return new Aphront404Response(); } $errors = array(); $v_note = null; $e_date = null; $timestamp = AphrontFormDateControlValue::newFromEpoch($viewer, time()); if ($request->isDialogFormPost()) { $v_note = $request->getStr('note'); $timestamp = AphrontFormDateControlValue::newFromRequest($request, 'epoch'); if (!$timestamp->isValid()) { $errors[] = pht('Please choose a valid date.'); $e_date = pht('Invalid'); } else { $max_time = PhabricatorTime::getNow(); if ($timestamp->getEpoch() > $max_time) { if ($this->isStoppingTracking()) { $errors[] = pht('You can not stop tracking time at a future time. Enter the ' . 'current time, or a time in the past.'); } else { $errors[] = pht('You can not start tracking time at a future time. Enter the ' . 'current time, or a time in the past.'); } $e_date = pht('Invalid'); } if ($this->isStoppingTracking()) { $min_time = $current_timer->getDateStarted(); if ($min_time > $timestamp->getEpoch()) { $errors[] = pht('Stop time must be after start time.'); $e_date = pht('Invalid'); } } } if (!$errors) { $editor = new PhrequentTrackingEditor(); if ($this->isStartingTracking()) { $editor->startTracking($viewer, $this->phid, $timestamp->getEpoch()); } else { if ($this->isStoppingTracking()) { $editor->stopTracking($viewer, $this->phid, $timestamp->getEpoch(), $v_note); } } return id(new AphrontRedirectResponse())->setURI($done_uri); } } $dialog = $this->newDialog()->setTitle($title_text)->setWidth(AphrontDialogView::WIDTH_FORM)->setErrors($errors)->appendParagraph($inner_text); $form = new PHUIFormLayoutView(); if ($this->isStoppingTracking()) { $start_time = $current_timer->getDateStarted(); $start_string = pht('%s (%s ago)', phabricator_datetime($start_time, $viewer), phutil_format_relative_time(PhabricatorTime::getNow() - $start_time)); $form->appendChild(id(new AphrontFormStaticControl())->setLabel(pht('Started At'))->setValue($start_string)); } $form->appendChild(id(new AphrontFormDateControl())->setUser($viewer)->setName('epoch')->setLabel($action_text)->setError($e_date)->setValue($timestamp)); if ($this->isStoppingTracking()) { $form->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Note'))->setName('note')->setValue($v_note)); } $dialog->appendChild($form); $dialog->addCancelButton($done_uri); $dialog->addSubmitButton($action_text); return $dialog; }
public function handleRequest(AphrontRequest $request) { $viewer = $request->getViewer(); $id = $request->getURIData('id'); $cart = id(new PhortuneCartQuery())->setViewer($viewer)->withIDs(array($id))->needPurchases(true)->executeOne(); if (!$cart) { return new Aphront404Response(); } $cancel_uri = $cart->getCancelURI(); $merchant = $cart->getMerchant(); switch ($cart->getStatus()) { case PhortuneCart::STATUS_BUILDING: return $this->newDialog()->setTitle(pht('Incomplete Cart'))->appendParagraph(pht('The application that created this cart did not finish putting ' . 'products in it. You can not checkout with an incomplete ' . 'cart.'))->addCancelButton($cancel_uri); case PhortuneCart::STATUS_READY: // This is the expected, normal state for a cart that's ready for // checkout. break; case PhortuneCart::STATUS_CHARGED: case PhortuneCart::STATUS_PURCHASING: case PhortuneCart::STATUS_HOLD: case PhortuneCart::STATUS_REVIEW: case PhortuneCart::STATUS_PURCHASED: // For these states, kick the user to the order page to give them // information and options. return id(new AphrontRedirectResponse())->setURI($cart->getDetailURI()); default: throw new Exception(pht('Unknown cart status "%s"!', $cart->getStatus())); } $account = $cart->getAccount(); $account_uri = $this->getApplicationURI($account->getID() . '/'); $methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->withMerchantPHIDs(array($merchant->getPHID()))->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE))->execute(); $e_method = null; $errors = array(); if ($request->isFormPost()) { // Require CAN_EDIT on the cart to actually make purchases. PhabricatorPolicyFilter::requireCapability($viewer, $cart, PhabricatorPolicyCapability::CAN_EDIT); $method_id = $request->getInt('paymentMethodID'); $method = idx($methods, $method_id); if (!$method) { $e_method = pht('Required'); $errors[] = pht('You must choose a payment method.'); } if (!$errors) { $provider = $method->buildPaymentProvider(); $charge = $cart->willApplyCharge($viewer, $provider, $method); try { $provider->applyCharge($method, $charge); } catch (Exception $ex) { $cart->didFailCharge($charge); return $this->newDialog()->setTitle(pht('Charge Failed'))->appendParagraph(pht('Unable to make payment: %s', $ex->getMessage()))->addCancelButton($cart->getCheckoutURI(), pht('Continue')); } $cart->didApplyCharge($charge); $done_uri = $cart->getCheckoutURI(); return id(new AphrontRedirectResponse())->setURI($done_uri); } } $cart_table = $this->buildCartContentTable($cart); $cart_box = id(new PHUIObjectBoxView())->setFormErrors($errors)->setHeaderText(pht('Cart Contents'))->setTable($cart_table); $title = $cart->getName(); if (!$methods) { $method_control = id(new AphrontFormStaticControl())->setLabel(pht('Payment Method'))->setValue(phutil_tag('em', array(), pht('No payment methods configured.'))); } else { $method_control = id(new AphrontFormRadioButtonControl())->setLabel(pht('Payment Method'))->setName('paymentMethodID')->setValue($request->getInt('paymentMethodID')); foreach ($methods as $method) { $method_control->addButton($method->getID(), $method->getFullDisplayName(), $method->getDescription()); } } $method_control->setError($e_method); $account_id = $account->getID(); $payment_method_uri = $this->getApplicationURI("{$account_id}/card/new/"); $payment_method_uri = new PhutilURI($payment_method_uri); $payment_method_uri->setQueryParams(array('merchantID' => $merchant->getID(), 'cartID' => $cart->getID())); $form = id(new AphrontFormView())->setUser($viewer)->appendChild($method_control); $add_providers = $this->loadCreatePaymentMethodProvidersForMerchant($merchant); if ($add_providers) { $new_method = javelin_tag('a', array('class' => 'button grey', 'href' => $payment_method_uri), pht('Add New Payment Method')); $form->appendChild(id(new AphrontFormMarkupControl())->setValue($new_method)); } if ($methods || $add_providers) { $submit = id(new AphrontFormSubmitControl())->setValue(pht('Submit Payment'))->setDisabled(!$methods); if ($cart->getCancelURI() !== null) { $submit->addCancelButton($cart->getCancelURI()); } $form->appendChild($submit); } $provider_form = null; $pay_providers = $this->loadOneTimePaymentProvidersForMerchant($merchant); if ($pay_providers) { $one_time_options = array(); foreach ($pay_providers as $provider) { $one_time_options[] = $provider->renderOneTimePaymentButton($account, $cart, $viewer); } $one_time_options = phutil_tag('div', array('class' => 'phortune-payment-onetime-list'), $one_time_options); $provider_form = new PHUIFormLayoutView(); $provider_form->appendChild(id(new AphrontFormMarkupControl())->setLabel(pht('Pay With'))->setValue($one_time_options)); } $payment_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Choose Payment Method'))->appendChild($form)->appendChild($provider_form); $description_box = $this->renderCartDescription($cart); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb(pht('Checkout')); $crumbs->addTextCrumb($title); return $this->buildApplicationPage(array($crumbs, $cart_box, $description_box, $payment_box), array('title' => $title)); }
public function processRequest() { $request = $this->getRequest(); $user = $request->getUser(); $start_time = id(new AphrontFormDateControl())->setUser($user)->setName('start')->setLabel(pht('Start'))->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY); $end_time = id(new AphrontFormDateControl())->setUser($user)->setName('end')->setLabel(pht('End'))->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY); if ($this->isCreate()) { $status = new PhabricatorCalendarEvent(); $end_value = $end_time->readValueFromRequest($request); $start_value = $start_time->readValueFromRequest($request); $submit_label = pht('Create'); $filter = 'status/create/'; $page_title = pht('Create Event'); $redirect = 'created'; } else { $status = id(new PhabricatorCalendarEventQuery())->setViewer($user)->withIDs(array($this->id))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->executeOne(); if (!$status) { return new Aphront404Response(); } $end_time->setValue($status->getDateTo()); $start_time->setValue($status->getDateFrom()); $submit_label = pht('Update'); $filter = 'event/edit/' . $status->getID() . '/'; $page_title = pht('Update Event'); $redirect = 'updated'; } $errors = array(); if ($request->isFormPost()) { $type = $request->getInt('status'); $start_value = $start_time->readValueFromRequest($request); $end_value = $end_time->readValueFromRequest($request); $description = $request->getStr('description'); try { $status->setUserPHID($user->getPHID())->setStatus($type)->setDateFrom($start_value)->setDateTo($end_value)->setDescription($description)->save(); } catch (PhabricatorCalendarEventInvalidEpochException $e) { $errors[] = pht('Start must be before end.'); } if (!$errors) { $uri = new PhutilURI($this->getApplicationURI()); $uri->setQueryParams(array('month' => phabricator_format_local_time($status->getDateFrom(), $user, 'm'), 'year' => phabricator_format_local_time($status->getDateFrom(), $user, 'Y'), $redirect => true)); if ($request->isAjax()) { $response = id(new AphrontAjaxResponse())->setContent(array('redirect_uri' => $uri)); } else { $response = id(new AphrontRedirectResponse())->setURI($uri); } return $response; } } $error_view = null; if ($errors) { $error_view = id(new AphrontErrorView())->setTitle(pht('Status can not be set!'))->setErrors($errors); } $status_select = id(new AphrontFormSelectControl())->setLabel(pht('Status'))->setName('status')->setValue($status->getStatus())->setOptions($status->getStatusOptions()); $description = id(new AphrontFormTextAreaControl())->setLabel(pht('Description'))->setName('description')->setValue($status->getDescription()); if ($request->isAjax()) { $dialog = id(new AphrontDialogView())->setUser($user)->setTitle($page_title)->setWidth(AphrontDialogView::WIDTH_FORM); if ($this->isCreate()) { $dialog->setSubmitURI($this->getApplicationURI('event/create/')); } else { $dialog->setSubmitURI($this->getApplicationURI('event/edit/' . $status->getID() . '/')); } $form = new PHUIFormLayoutView(); if ($error_view) { $form->appendChild($error_view); } } else { $form = id(new AphrontFormView())->setUser($user); } $form->appendChild($status_select)->appendChild($start_time)->appendChild($end_time)->appendChild($description); if ($request->isAjax()) { $dialog->addSubmitButton($submit_label); $submit = $dialog; } else { $submit = id(new AphrontFormSubmitControl())->setValue($submit_label); } if ($this->isCreate()) { $submit->addCancelButton($this->getApplicationURI()); } else { $submit->addCancelButton($this->getApplicationURI('event/view/' . $status->getID() . '/')); } if ($request->isAjax()) { $dialog->appendChild($form); return id(new AphrontDialogResponse())->setDialog($dialog); } $form->appendChild($submit); $form_box = id(new PHUIObjectBoxView())->setHeaderText($page_title)->setFormErrors($errors)->setForm($form); $nav = $this->buildSideNavView($status); $nav->selectFilter($filter); $crumbs = $this->buildApplicationCrumbs()->addTextCrumb($page_title); $nav->appendChild(array($crumbs, $form_box)); return $this->buildApplicationPage($nav, array('title' => $page_title)); }
public function processRequest() { $request = $this->getRequest(); $viewer = $request->getUser(); $cart = id(new PhortuneCartQuery())->setViewer($viewer)->withIDs(array($this->id))->needPurchases(true)->executeOne(); if (!$cart) { return new Aphront404Response(); } $account = $cart->getAccount(); $account_uri = $this->getApplicationURI($account->getID() . '/'); $methods = id(new PhortunePaymentMethodQuery())->setViewer($viewer)->withAccountPHIDs(array($account->getPHID()))->withStatuses(array(PhortunePaymentMethod::STATUS_ACTIVE))->execute(); $e_method = null; $errors = array(); if ($request->isFormPost()) { // Require CAN_EDIT on the cart to actually make purchases. PhabricatorPolicyFilter::requireCapability($viewer, $cart, PhabricatorPolicyCapability::CAN_EDIT); $method_id = $request->getInt('paymentMethodID'); $method = idx($methods, $method_id); if (!$method) { $e_method = pht('Required'); $errors[] = pht('You must choose a payment method.'); } if (!$errors) { $provider = $method->buildPaymentProvider(); $charge = id(new PhortuneCharge())->setAccountPHID($account->getPHID())->setCartPHID($cart->getPHID())->setAuthorPHID($viewer->getPHID())->setPaymentProviderKey($provider->getProviderKey())->setPaymentMethodPHID($method->getPHID())->setAmountInCents($cart->getTotalPriceInCents())->setStatus(PhortuneCharge::STATUS_PENDING); $charge->openTransaction(); $charge->save(); $cart->setStatus(PhortuneCart::STATUS_PURCHASING); $cart->save(); $charge->saveTransaction(); $provider->applyCharge($method, $charge); $cart->setStatus(PhortuneCart::STATUS_PURCHASED); $cart->save(); $view_uri = $this->getApplicationURI('cart/' . $cart->getID() . '/'); return id(new AphrontRedirectResponse())->setURI($view_uri); } } $cart_box = $this->buildCartContents($cart); $cart_box->setFormErrors($errors); $title = pht('Buy Stuff'); if (!$methods) { $method_control = id(new AphrontFormStaticControl())->setLabel(pht('Payment Method'))->setValue(phutil_tag('em', array(), pht('No payment methods configured.'))); } else { $method_control = id(new AphrontFormRadioButtonControl())->setLabel(pht('Payment Method'))->setName('paymentMethodID')->setValue($request->getInt('paymentMethodID')); foreach ($methods as $method) { $method_control->addButton($method->getID(), $method->getFullDisplayName(), $method->getDescription()); } } $method_control->setError($e_method); $payment_method_uri = $this->getApplicationURI($account->getID() . '/card/new/'); $form = id(new AphrontFormView())->setUser($viewer)->appendChild($method_control); $add_providers = PhortunePaymentProvider::getProvidersForAddPaymentMethod(); if ($add_providers) { $new_method = phutil_tag('a', array('class' => 'button grey', 'href' => $payment_method_uri, 'sigil' => 'workflow'), pht('Add New Payment Method')); $form->appendChild(id(new AphrontFormMarkupControl())->setValue($new_method)); } if ($methods || $add_providers) { $form->appendChild(id(new AphrontFormSubmitControl())->setValue(pht('Submit Payment'))->setDisabled(!$methods)); } $provider_form = null; $pay_providers = PhortunePaymentProvider::getProvidersForOneTimePayment(); if ($pay_providers) { $one_time_options = array(); foreach ($pay_providers as $provider) { $one_time_options[] = $provider->renderOneTimePaymentButton($account, $cart, $viewer); } $one_time_options = phutil_tag('div', array('class' => 'phortune-payment-onetime-list'), $one_time_options); $provider_form = new PHUIFormLayoutView(); $provider_form->appendChild(id(new AphrontFormMarkupControl())->setLabel('Pay With')->setValue($one_time_options)); } $payment_box = id(new PHUIObjectBoxView())->setHeaderText(pht('Choose Payment Method'))->appendChild($form)->appendChild($provider_form); $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb($title); return $this->buildApplicationPage(array($crumbs, $cart_box, $payment_box), array('title' => $title)); }