当前位置: 首页>>代码示例>>PHP>>正文


PHP SS_HTTPRequest::postVars方法代码示例

本文整理汇总了PHP中SS_HTTPRequest::postVars方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_HTTPRequest::postVars方法的具体用法?PHP SS_HTTPRequest::postVars怎么用?PHP SS_HTTPRequest::postVars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SS_HTTPRequest的用法示例。


在下文中一共展示了SS_HTTPRequest::postVars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ipn

 /**
  * Process IPN request from ClickBank. Only process POST request
  * 
  * @param	object	$_POST
  * @return	int		HTTP code 
  */
 public function ipn(SS_HTTPRequest $request)
 {
     if ($request->isPost()) {
         if (ClickBankManager::validate_ipn_request($request->postVars())) {
             ClickBankManager::process_ipn_request($request->postVars());
             return Director::get_status_code();
         }
     }
     return ErrorPage::response_for(404);
 }
开发者ID:rixrix,项目名称:silverstripe-clickbank,代码行数:16,代码来源:ClickBankController.php

示例2: webhook

 public function webhook(SS_HTTPRequest $request)
 {
     $mandrill_events = $request->postVars();
     foreach (json_decode($mandrill_events['mandrill_events']) as $event) {
         $MandrillEvent = new MandrillEvent();
         $MandrillEvent->ts = $event->ts;
         $MandrillEvent->event = $event->event;
         $MandrillEvent->url = $event->url;
         $MandrillEvent->user_agent = $event->user_agent;
         $MandrillEvent->MessageID = $event->_id;
         $MandrillEvent->write();
     }
 }
开发者ID:helpfulrobot,项目名称:cslweb-silverstripe-mandrill-mailer,代码行数:13,代码来源:MandrillEventController.php

示例3: update

 public function update(SS_HTTPRequest $request)
 {
     $member = Customer::currentUser();
     if (!$member->canEdit()) {
         return $this()->httpError(401);
     }
     $updateData = $request->postVars();
     $updateData = ProfiledMemberForm::update_models('update', $updateData, $member);
     $member->write();
     /** @noinspection PhpParamsInspection */
     ProfiledMemberForm::set_form_message("ProfileUpdated", CrackerjackForm::Good);
     $this->sendEmail('Update', $member, $updateData);
     return $this()->redirectBack();
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-profiled,代码行数:14,代码来源:Controller.php

示例4: dorequest

 /**
  * This method passes through an HTTP request to another webserver. 
  * This proxy is used to avoid any cross domain issues. The proxy
  * uses a white-list of domains to minimize security risks. 
  *
  * @param SS_HTTPRequest $data array of parameters
  *
  * $data['u']:         URL (complete request string)
  * $data['no_header']: set to '1' to avoid sending header information 
  *                     directly. 
  * @return the CURL response
  */
 public function dorequest($data)
 {
     $headers = array();
     $vars = $data->requestVars();
     $no_header = false;
     if (!isset($vars['u'])) {
         return "Invalid request: unknown proxy destination.";
     }
     $url = $vars['u'];
     if (isset($vars['no_header']) && $vars['no_header'] == '1') {
         $no_header = true;
     }
     $checkUrl = explode("/", $url);
     if (!in_array($checkUrl[2], self::get_allowed_host())) {
         return "Access denied to ({$url}).";
     }
     // Open the Curl session
     $session = curl_init($url);
     // If it's a POST, put the POST data in the body
     $isPost = $data->isPOST();
     if ($isPost) {
         $postvars = '';
         $vars = $data->getBody();
         if ($vars) {
             $postvars = "body=" . $vars;
         } else {
             $vars = $data->postVars();
             if ($vars) {
                 foreach ($vars as $k => $v) {
                     $postvars .= $k . '=' . $v . '&';
                 }
             }
         }
         $headers[] = 'Content-type: text/xml';
         curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($session, CURLOPT_POST, true);
         curl_setopt($session, CURLOPT_POSTFIELDS, $postvars);
     }
     // Don't return HTTP headers. Do return the contents of the call
     curl_setopt($session, CURLOPT_HEADER, false);
     curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
     // Make the call
     $xml = curl_exec($session);
     // The web service returns XML. Set the Content-Type appropriately
     if ($no_header == false) {
         header("Content-Type: text/xml");
     }
     curl_close($session);
     return $xml;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-openlayers,代码行数:62,代码来源:Proxy.php

示例5: upload

 /**
  * Action to handle upload of a single file
  *
  * @param SS_HTTPRequest $request
  * @return SS_HTTPResponse
  * @return SS_HTTPResponse
  */
 public function upload(SS_HTTPRequest $request)
 {
     // Find the first set of upload data that looks like it came from an
     // UploadField.
     // NOTE(Jake): There is only the SecurityID and the 'upload' data as this is done
     //             in it's own AJAX request, not sent along with all the other data.
     foreach ($request->postVars() as $key => $value) {
         // todo(Jake): Test SS 3.1 compatibility
         // NOTE(Jake): Only tested in SS 3.2, UploadField::upload data may not look like this in 3.1...
         if ($value && isset($value['name']) && isset($value['type']) && isset($value['tmp_name'])) {
             // NOTE(Jake): UploadField requires this FormField to be the correct name so it can retrieve
             //             the file information from postVar. So detect the first set of data that seems
             //             like upload info and use it.
             $this->setName($key);
             break;
         }
     }
     return parent::upload($request);
 }
开发者ID:silbinarywolf,项目名称:multirecordfield,代码行数:26,代码来源:MultiRecordUploadField.php

示例6: handleRequest

 public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
 {
     self::$is_at_root = true;
     $this->setDataModel($model);
     $this->pushCurrent();
     $this->init();
     if (!($site = Multisites::inst()->getCurrentSiteId())) {
         return $this->httpError(404);
     }
     $page = SiteTree::get()->filter(array('ParentID' => $site, 'URLSegment' => 'home'));
     if (!($page = $page->first())) {
         return $this->httpError(404);
     }
     $request = new SS_HTTPRequest($request->httpMethod(), $page->RelativeLink(), $request->getVars(), $request->postVars());
     $request->match('$URLSegment//$Action', true);
     $front = new MultisitesFrontController();
     $response = $front->handleRequest($request, $model);
     $this->popCurrent();
     return $response;
 }
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:20,代码来源:MultisitesRootController.php

示例7: generateLinks

 /**
  * Renders the CheckfrontLinkGenerator template with filled in
  *  -   Package
  *  -   Posted array info
  *  -   AccessKey encoded so can copy/paste
  *  -   Link to copy paste to email
  *
  * @param SS_HTTPRequest $request
  *
  * @return HTMLText
  */
 protected function generateLinks(SS_HTTPRequest $request)
 {
     $postVars = $request->postVars();
     $packageID = $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName];
     $packageResponse = CheckfrontModule::api()->fetchPackage($packageID);
     if (!($package = $packageResponse->getPackage())) {
         throw new CheckfrontException(_t('Package.NoSuchPackageMessage', "Package {id}not found", array('id' => $packageID)), CheckfrontException::TypeError);
     }
     /*
             if (!$organiserEvent = $packageResponse->getEvent($postVars[CheckfrontLinkGeneratorForm::OrganiserEventFieldName])) {
                 throw new CheckfrontException(_t('Package.NoSuchEventMessage', "{type}event not found", array('type' => 'Organiser ')));
             }
             if (!$individualEvent = $packageResponse->getEvent($postVars[CheckfrontLinkGeneratorForm::IndividualEventFieldName])) {
                 throw new CheckfrontException(_t('Package.NoSuchEventMessage', "{type}event not found", array('type' => 'Individual ')));
             }
     */
     $accessKey = CheckfrontModule::crypto()->generate_key();
     $organiserLink = $this->makeLink($accessKey, $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName], $postVars[CheckfrontLinkGeneratorForm::OrganiserStartDate], $postVars[CheckfrontLinkGeneratorForm::OrganiserEndDate], $postVars[CheckfrontLinkGeneratorForm::LinkTypeFieldName], CheckfrontModule::UserTypeOrganiser, $postVars[CheckfrontLinkGeneratorForm::PaymentTypeFieldName]);
     $individualLink = $this->makeLink($accessKey, $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName], $postVars[CheckfrontLinkGeneratorForm::IndividualStartDate], $postVars[CheckfrontLinkGeneratorForm::IndividualEndDate], $postVars[CheckfrontLinkGeneratorForm::LinkTypeFieldName], CheckfrontModule::UserTypeIndividual, $postVars[CheckfrontLinkGeneratorForm::PaymentTypeFieldName]);
     $form = $this->buildLinkGeneratorForm();
     return $this->renderWith(array('CheckfrontLinkGenerator', 'Page'), array('ShowOutput' => true, 'Package' => $package, 'Posted' => new ArrayData($postVars), 'OrganiserLink' => $organiserLink, 'IndividualLink' => $individualLink, 'AccessKey' => $accessKey, 'CheckfrontForm' => $form));
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-checkfront,代码行数:33,代码来源:LinkGenerator.php

示例8: httpSubmission

 /**
  * Handle a form submission.  GET and POST requests behave identically.
  * Populates the form with {@link loadDataFrom()}, calls {@link validate()},
  * and only triggers the requested form action/method
  * if the form is valid.
  *
  * @param SS_HTTPRequest $request
  * @throws SS_HTTPResponse_Exception
  */
 public function httpSubmission($request)
 {
     // Strict method check
     if ($this->strictFormMethodCheck) {
         // Throws an error if the method is bad...
         if ($this->formMethod != $request->httpMethod()) {
             $response = Controller::curr()->getResponse();
             $response->addHeader('Allow', $this->formMethod);
             $this->httpError(405, _t("Form.BAD_METHOD", "This form requires a " . $this->formMethod . " submission"));
         }
         // ...and only uses the variables corresponding to that method type
         $vars = $this->formMethod == 'GET' ? $request->getVars() : $request->postVars();
     } else {
         $vars = $request->requestVars();
     }
     // Populate the form
     $this->loadDataFrom($vars, true);
     // Protection against CSRF attacks
     $token = $this->getSecurityToken();
     if (!$token->checkRequest($request)) {
         $securityID = $token->getName();
         if (empty($vars[$securityID])) {
             $this->httpError(400, _t("Form.CSRF_FAILED_MESSAGE", "There seems to have been a technical problem. Please click the back button, " . "refresh your browser, and try again."));
         } else {
             // Clear invalid token on refresh
             $data = $this->getData();
             unset($data[$securityID]);
             Session::set("FormInfo.{$this->FormName()}.data", $data);
             Session::set("FormInfo.{$this->FormName()}.errors", array());
             $this->sessionMessage(_t("Form.CSRF_EXPIRED_MESSAGE", "Your session has expired. Please re-submit the form."), "warning");
             return $this->controller->redirectBack();
         }
     }
     // Determine the action button clicked
     $funcName = null;
     foreach ($vars as $paramName => $paramVal) {
         if (substr($paramName, 0, 7) == 'action_') {
             // Break off querystring arguments included in the action
             if (strpos($paramName, '?') !== false) {
                 list($paramName, $paramVars) = explode('?', $paramName, 2);
                 $newRequestParams = array();
                 parse_str($paramVars, $newRequestParams);
                 $vars = array_merge((array) $vars, (array) $newRequestParams);
             }
             // Cleanup action_, _x and _y from image fields
             $funcName = preg_replace(array('/^action_/', '/_x$|_y$/'), '', $paramName);
             break;
         }
     }
     // If the action wasn't set, choose the default on the form.
     if (!isset($funcName) && ($defaultAction = $this->defaultAction())) {
         $funcName = $defaultAction->actionName();
     }
     if (isset($funcName)) {
         Form::set_current_action($funcName);
         $this->setButtonClicked($funcName);
     }
     // Permission checks (first on controller, then falling back to form)
     if ($this->controller->hasMethod($funcName) && !$this->controller->checkAccessAction($funcName) && !$this->actions->dataFieldByName('action_' . $funcName)) {
         return $this->httpError(403, sprintf('Action "%s" not allowed on controller (Class: %s)', $funcName, get_class($this->controller)));
     } elseif ($this->hasMethod($funcName) && !$this->checkAccessAction($funcName)) {
         return $this->httpError(403, sprintf('Action "%s" not allowed on form (Name: "%s")', $funcName, $this->name));
     }
     // TODO : Once we switch to a stricter policy regarding allowed_actions (meaning actions must be set
     // explicitly in allowed_actions in order to run)
     // Uncomment the following for checking security against running actions on form fields
     /* else {
     			// Try to find a field that has the action, and allows it
     			$fieldsHaveMethod = false;
     			foreach ($this->Fields() as $field){
     				if ($field->hasMethod($funcName) && $field->checkAccessAction($funcName)) {
     					$fieldsHaveMethod = true;
     				}
     			}
     			if (!$fieldsHaveMethod) {
     				return $this->httpError(
     					403,
     					sprintf('Action "%s" not allowed on any fields of form (Name: "%s")', $funcName, $this->Name())
     				);
     			}
     		}*/
     // Validate the form
     if (!$this->validate()) {
         return $this->getValidationErrorResponse();
     }
     // First, try a handler method on the controller (has been checked for allowed_actions above already)
     if ($this->controller->hasMethod($funcName)) {
         return $this->controller->{$funcName}($vars, $this, $request);
         // Otherwise, try a handler method on the form object.
     } elseif ($this->hasMethod($funcName)) {
         return $this->{$funcName}($vars, $this, $request);
//.........这里部分代码省略.........
开发者ID:rasstislav,项目名称:silverstripe-framework,代码行数:101,代码来源:Form.php

示例9: updateOrderFormCart

 /**
  * Update the order form cart, called via AJAX with current order form data.
  * Renders the cart and sends that back for displaying on the order form page.
  * 
  * @param SS_HTTPRequest $data Form data sent via AJAX POST.
  * @return String Rendered cart for the order form, template include 'CheckoutFormOrder'.
  */
 function updateOrderFormCart(SS_HTTPRequest $data)
 {
     if ($data->isPOST()) {
         $fields = array();
         $validator = new OrderFormValidator();
         $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
         $order = CartControllerExtension::get_current_order();
         //Update the Order
         $order->addAddressesAtCheckout($data->postVars());
         $order->addModifiersAtCheckout($data->postVars());
         //TODO update personal details, notes and payment type?
         //Create the part of the form that displays the Order
         $this->addItemFields($fields, $validator, $order);
         $this->addModifierFields($fields, $validator, $order);
         //This is going to go through and add modifiers based on current Form DATA
         //TODO This should be constructed for non-dropdown fields as well
         //Update modifier form fields so that the dropdown values are correct
         $newModifierData = array();
         $subTotalModifiers = isset($fields['SubTotalModifiers']) ? $fields['SubTotalModifiers'] : array();
         $totalModifiers = isset($fields['Modifiers']) ? $fields['Modifiers'] : array();
         $modifierFields = array_merge($subTotalModifiers, $totalModifiers);
         foreach ($modifierFields as $field) {
             if (method_exists($field, 'updateValue')) {
                 $field->updateValue($order);
             }
             $modifierClassName = get_class($field->getModifier());
             $newModifierData['Modifiers'][$modifierClassName] = $field->Value();
         }
         //Add modifiers to the order again so that the new values are used
         $order->addModifiersAtCheckout($newModifierData);
         $actions = new FieldSet(new FormAction('ProcessOrder', _t('CheckoutPage.PROCEED_TO_PAY', "Proceed to pay")));
         $form = new CheckoutForm($this, 'OrderForm', $fields, $actions, $validator, $order);
         $form->disableSecurityToken();
         $form->validate();
         return $form->renderWith('CheckoutFormOrder');
     }
 }
开发者ID:helpfulrobot,项目名称:swipestripe-swipestripe,代码行数:44,代码来源:CheckoutPage.php

示例10: submit

 /**
  * We intercept the submit handler since we have to alter some field
  * checks depending on the status of the field "InvoiceAddressAsShippingAddress".
  *
  * @param SS_HTTPRequest $data submit data
  * @param Form           $form form object
  *
  * @return ViewableData
  *
  * @author Sascha Koehler <skoehler@pixeltricks.de>,
  *         Sebastian Diel <sdiel@pixeltricks.de>
  * @since 20.01.2014
  */
 public function submit($data, $form)
 {
     // Disable the check instructions if the shipping address shall be
     // the same as the invoice address.
     if ($data['InvoiceAddressAsShippingAddress'] == '1') {
         $this->deactivateValidationFor('Shipping_Salutation');
         $this->deactivateValidationFor('Shipping_AcademicTitle');
         $this->deactivateValidationFor('Shipping_FirstName');
         $this->deactivateValidationFor('Shipping_Surname');
         $this->deactivateValidationFor('Shipping_Addition');
         $this->deactivateValidationFor('Shipping_Street');
         $this->deactivateValidationFor('Shipping_StreetNumber');
         $this->deactivateValidationFor('Shipping_Postcode');
         $this->deactivateValidationFor('Shipping_City');
         $this->deactivateValidationFor('Shipping_PhoneAreaCode');
         $this->deactivateValidationFor('Shipping_Phone');
         $this->deactivateValidationFor('Shipping_Country');
     }
     $formData = $data->postVars();
     if ($this->UseMinimumAgeToOrder()) {
         $formData['Birthday'] = $formData['BirthdayYear'] . '-' . $formData['BirthdayMonth'] . '-' . $formData['BirthdayDay'];
         if (!SilvercartConfig::CheckMinimumAgeToOrder($formData['Birthday'])) {
             $this->errorMessages['BirthdayDay'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY') . ' - ' . _t('SilvercartPage.DAY'), 'BirthdayDay' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
             $this->errorMessages['BirthdayMonth'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY') . ' - ' . _t('SilvercartPage.MONTH'), 'BirthdayMonth' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
             $this->errorMessages['BirthdayYear'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY') . ' - ' . _t('SilvercartPage.YEAR'), 'BirthdayYear' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
             $this->setSubmitSuccess(false);
             return $this->submitFailure($data, $form);
         }
     }
     parent::submit($data, $form);
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:44,代码来源:SilvercartCheckoutFormStep2Anonymous.php

示例11: getFakeRequest

 /**
  * Generates a fake request for the field
  * @param {SS_HTTPRequest} $request Source Request to base the fake request off of
  * @param {Widget} $sourceWidget Source widget
  * @param {string} $baseLink Base URL to be truncated off of the form
  * @return {SS_HTTPRequest} Fake HTTP Request used to fool the form field into thinking the request was made to it directly
  */
 protected function getFakeRequest(SS_HTTPRequest $request, Widget $sourceWidget, $baseLink)
 {
     $fieldName = rawurldecode($request->param('FieldName'));
     $objID = preg_replace('/Widget\\[(.*?)\\]\\[(.*?)\\]\\[(.*?)\\]$/', '$2', $fieldName);
     $finalPostVars = array();
     if ($request->isPOST()) {
         $postVars = $request->postVars();
         //Pull the post data for the widget
         if (isset($postVars['Widget'][$this->getName()][$objID])) {
             $finalPostVars = $postVars['Widget'][$this->getName()][$objID];
         } else {
             $finalPostVars = array();
         }
         $finalPostVars = array_merge($finalPostVars, $postVars);
         unset($finalPostVars['Widget']);
         //Workaround for UploadField's and GridFields confusing the request
         $fields = $sourceWidget->getCMSFields();
         $uploadFields = array();
         $gridFields = array();
         foreach ($fields as $field) {
             if ($field instanceof UploadField) {
                 $uploadFields[] = $field->getName();
             } else {
                 if ($field instanceof GridField) {
                     $gridFields[] = $field->getName();
                 }
             }
         }
         //Re-orgazine the upload field data
         if (count($uploadFields)) {
             foreach ($uploadFields as $field) {
                 $formFieldName = 'Widget[' . $this->getName() . '][' . $objID . '][' . $field . ']';
                 $fieldData = array($formFieldName => array('name' => array('Uploads' => array()), 'type' => array('Uploads' => array()), 'tmp_name' => array('Uploads' => array()), 'error' => array('Uploads' => array()), 'size' => array('Uploads' => array())));
                 if (isset($postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads'])) {
                     for ($i = 0; $i < count($postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads']); $i++) {
                         $fieldData[$formFieldName]['name']['Uploads'][] = $postVars['Widget']['name'][$this->getName()][$objID][$field]['Uploads'][$i];
                         $fieldData[$formFieldName]['type']['Uploads'][] = $postVars['Widget']['type'][$this->getName()][$objID][$field]['Uploads'][$i];
                         $fieldData[$formFieldName]['tmp_name']['Uploads'][] = $postVars['Widget']['tmp_name'][$this->getName()][$objID][$field]['Uploads'][$i];
                         $fieldData[$formFieldName]['error']['Uploads'][] = $postVars['Widget']['error'][$this->getName()][$objID][$field]['Uploads'][$i];
                         $fieldData[$formFieldName]['size']['Uploads'][] = $postVars['Widget']['size'][$this->getName()][$objID][$field]['Uploads'][$i];
                     }
                 }
                 $finalPostVars = array_merge_recursive($finalPostVars, $fieldData);
             }
         }
         //Reorganize the gridfield data
         if (count($gridFields) && isset($postVars['Widget'][$this->getName()][$objID])) {
             foreach ($gridFields as $field) {
                 $formFieldName = 'Widget[' . $this->getName() . '][' . $objID . '][' . $field . ']';
                 $fieldData = array($formFieldName => $postVars['Widget'][$this->getName()][$objID][$field]);
             }
             $finalPostVars = array_merge_recursive($finalPostVars, $fieldData);
         }
     }
     $headers = $request->getHeaders();
     $request = new SS_HTTPRequest($_SERVER['REQUEST_METHOD'], str_replace(rtrim($baseLink, '/'), '', rtrim($request->getURL(), '/')) . '/', $request->getVars(), $finalPostVars, $request->getBody());
     $request->match('$Action/$ID/$OtherID');
     //Merge in the headers
     foreach ($headers as $header => $value) {
         $request->addHeader($header, $value);
     }
     return $request;
 }
开发者ID:helpfulrobot,项目名称:undefinedoffset-silverstripe-advancedwidgeteditor,代码行数:70,代码来源:AdvancedWidgetAreaEditor.php

示例12: doLogin

 /**
  * Action to do a login
  * 
  * @param SS_HTTPRequest $request    Request to check for product data
  * @param bool           $doRedirect Redirect after setting search settings?
  * 
  * @return void
  *
  * @author Sebastian Diel <sdiel@pixeltricks.de>
  * @since 30.06.2014
  */
 public function doLogin(SS_HTTPRequest $request, $doRedirect = true)
 {
     $postVars = $request->postVars();
     $emailAddress = $postVars['emailaddress'];
     $password = $postVars['password'];
     $member = Member::get()->filter('Email', $emailAddress)->first();
     if ($member instanceof Member && $member->exists()) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer instanceof Member && $customer->exists()) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->count() > 0) {
                     //delete registered customers cart positions
                     if ($customer->getCart()->SilvercartShoppingCartPositions()) {
                         foreach ($customer->getCart()->SilvercartShoppingCartPositions() as $position) {
                             $position->delete();
                         }
                     }
                     //add anonymous positions to the registered user
                     foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $position) {
                         $customer->getCart()->SilvercartShoppingCartPositions()->add($position);
                     }
                 }
                 $anonymousCustomer->logOut();
                 $anonymousCustomer->delete();
             }
             $customer->logIn();
             $customer->write();
         } else {
             $messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG')));
         }
     } else {
         $messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG')));
     }
     $this->redirectBack($postVars['redirect_to']);
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:48,代码来源:SilvercartActionHandler.php

示例13: populateFromSources

 /**
  * Populates the form somewhat intelligently
  * @param SS_HTTPRequest $request Any request
  * @param Member $member Any member
  * @param array $required Any validation messages
  * @return $this
  */
 public function populateFromSources(SS_HTTPRequest $request = null, Member $member = null, array $required = null)
 {
     $dataPath = "FormInfo.{$this->FormName()}.data";
     if (isset($member)) {
         $this->loadDataFrom($member);
     } else {
         if (isset($request)) {
             $this->loadDataFrom($request->postVars());
         } else {
             if (Session::get($dataPath)) {
                 $this->loadDataFrom(Session::get($dataPath));
             } else {
                 if ($failover = $this->getSessionData()) {
                     $this->loadDataFrom($failover);
                 }
             }
         }
     }
     if (!empty($required)) {
         $this->setRequiredFields($required);
     }
     return $this;
 }
开发者ID:helpfulrobot,项目名称:betterbrief-silverstripe-opauth,代码行数:30,代码来源:OpauthRegisterForm.php

示例14: book

 /**
  * -    setup session in checkfront
  * -    add package to session
  * -    add items to session
  * -    call the 'book' endpoint to make the booking
  *
  * @param SS_HTTPRequest $request
  *
  * @return CheckfrontForm
  */
 protected function book(SS_HTTPRequest $request)
 {
     $message = '';
     $messageType = '';
     $result = array();
     // only post request should route here
     $postVars = $request->postVars();
     try {
         $this->clearCheckfrontSession();
         $packageID = $this->getTokenInfo(CheckfrontModule::TokenItemIDIndex, $postVars[CheckfrontForm::AccessKeyFieldName]);
         if ($request->isPOST()) {
             $startDate = $request->postVar('StartDate');
             $endDate = $request->postVar('EndDate');
             $ratedPackageResponse = $this->api()->fetchPackage($packageID, $startDate, $endDate);
             if ($ratedPackageResponse->isValid()) {
                 $package = $ratedPackageResponse->getPackage();
                 $this->api()->addPackageToSession($package);
                 foreach ($postVars['ItemID'] as $index => $itemID) {
                     if (isset($postVars['Quantity'][$index])) {
                         if ($quantity = $postVars['Quantity'][$index]) {
                             /**
                              * CheckfrontAPIItemResponse
                              */
                             $response = $this->api()->fetchItem($itemID, $quantity, $startDate, $endDate);
                             if ($response->isValid()) {
                                 if ($item = $response->getItem()) {
                                     $this->api()->addItemToSession($item);
                                 }
                             } else {
                                 throw new CheckfrontBookingException($response->getMessage(), CheckfrontException::TypeError);
                             }
                         }
                     }
                 }
                 $bookingResponse = $this->api()->makeBooking(CheckfrontBookingModel::create_from_checkfront($postVars, 'from-form'));
                 if ($bookingResponse->isValid()) {
                     $paymentMethod = $this->getTokenInfo(CheckfrontModule::TokenPaymentTypeIndex, $postVars[CheckfrontForm::AccessKeyFieldName]);
                     if ($paymentMethod == CheckfrontModule::PaymentPayNow) {
                         $message = 'Thanks for booking, please click the link below to complete payment on your booking';
                         $messageType = CheckfrontException::TypeOK;
                         if ($paymentURL = $bookingResponse->getPaymentURL()) {
                             $result = array('PaymentURL' => $paymentURL);
                             $this()->redirect($paymentURL);
                         }
                     } else {
                         $message = 'Thanks for booking, you will receive email confirmation shortly';
                         $messageType = CheckfrontException::TypeOK;
                         $result = array('CurrentPackage' => $package, 'Booking' => $bookingResponse->getBooking(), 'Items' => $bookingResponse->getItems());
                     }
                 } else {
                     throw new CheckfrontBookingException($bookingResponse->getMessage(), CheckfrontException::TypeError);
                 }
             }
         }
     } catch (CheckfrontException $e) {
         $message = $e->getMessage();
         $messageType = $e->getType();
         $this->api()->clearSession();
         Session::setFormMessage(CheckfrontPackageBookingForm::FormName, $message, 'bad');
         $result = $this->buildBookingForm($request);
     }
     return array_merge(array(self::MessageKey => $message, self::MessageTypeKey => $messageType), $result);
 }
开发者ID:CrackerjackDigital,项目名称:silverstripe-checkfront,代码行数:73,代码来源:Package.php

示例15: handleGatewayResponse

 /**
  * handleGatewayResponse
  * This action should be used when a gateway submits a POST/GET response
  * for which we need to action. In this case, the PayPal IPN. We shall
  * return void as nothing is returned from this method. It is not public
  * facing and is present to handle system to system communications over 
  * HTTP communications only. If the gateway doesn't support POST/GET type
  * responses, implement the back office order updating within the
  * newPaymentSuccess() method instead.
  *
  * ATTRIBUTION
  * Snippets of IPN code were used from PayPal's GitHub samples on 15-10-2015.
  * https://github.com/paypal/ipn-code-samples/blob/master/paypal_ipn.php
  * @author PayPal 
  * 
  * @param SS_HTTPRequest $request The GET/POST variables and URL parameters.
  * @return Void
  */
 public function handleGatewayResponse($request)
 {
     /**
      * Only proceed if we have postVars set
      */
     if ($request->postVars()) {
         $gateway = DataObject::get_one("Gateway_PayPal");
         $debug = $gateway->Debug;
         /**
          * STEP ONE 
          * Prepend cmd=_notify-validate to the POST request from PayPal.
          * Reading posted data direction from $request->postVars() may
          * cause serialization isusues with array data. We therefore
          * will read directly from the input stream instead.
          */
         $raw_post_data = file_get_contents('php://input');
         $raw_post_array = explode('&', $raw_post_data);
         $myPost = array();
         foreach ($raw_post_array as $keyval) {
             $keyval = explode('=', $keyval);
             if (count($keyval) == 2) {
                 $myPost[$keyval[0]] = urldecode($keyval[1]);
             }
         }
         $req = 'cmd=_notify-validate';
         if (function_exists('get_magic_quotes_gpc')) {
             $get_magic_quotes_exists = true;
         }
         foreach ($myPost as $key => $value) {
             if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                 $value = urlencode(stripslashes($value));
             } else {
                 $value = urlencode($value);
             }
             $req .= "&{$key}={$value}";
         }
         /**
          * STEP TWO
          * Which PayPal URL are we dealing with?
          */
         if (DataObject::get_one("Gateway_PayPal")->Sandbox) {
             $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
         } else {
             $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
         }
         /**
          * STEP THREE
          * Initiate curl IPN callback to post IPN data back to PayPal
          * to validate the IPN data is genuine. Without this step anyone
          * can fake IPN data and mess with your order system.
          */
         $ch = curl_init($paypal_url);
         if ($ch == FALSE) {
             return FALSE;
         }
         /* Set curl Options */
         curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
         /* Set TCP timeout to 30 seconds */
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
         /* Execute Curl and Store Response in $res */
         $res = curl_exec($ch);
         /* Are there curl errors? If yes, log them if Debug is enabled. */
         if (curl_errno($ch) != 0) {
             if ($debug == 1) {
                 $this->newLogEntry("Can't connect to PayPal to validate IPN message: " . curl_error($ch));
             }
             curl_close($ch);
             exit;
             /* No errors */
         } else {
             /* If Debug is enabled, save to the log. */
             if ($debug == 1) {
                 $this->newLogEntry("HTTP request of validation request" . curl_getinfo($ch, CURLINFO_HEADER_OUT) . " for IPN payload: {$req}");
                 $this->newLogEntry("HTTP response of validation request: {$res}");
             }
//.........这里部分代码省略.........
开发者ID:micschk,项目名称:torindul-silverstripe-shop,代码行数:101,代码来源:Gateway_PayPal.php


注:本文中的SS_HTTPRequest::postVars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。