function saveNewsArticle($data, Form $form)
 {
     try {
         $form->clearMessage();
         $form->resetValidation();
         if ($data['newsID']) {
             $this->manager->updateNews($data);
         } else {
             $this->manager->postNews($data);
         }
         Session::clear("FormInfo.Form_NewsRequestForm.data");
         return Controller::curr()->redirect('/news-add/?saved=1');
     } catch (EntityValidationException $ex1) {
         $messages = $ex1->getMessages();
         $msg = $messages[0];
         $form->addErrorMessage('Headline', $msg['message'], 'bad');
         SS_Log::log($msg['message'], SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_NewsRequestForm.data", $data);
         return $this->redirectBack();
     } catch (Exception $ex) {
         $form->addErrorMessage('Headline', 'Server Error', 'bad');
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_NewsRequestForm.data", $data);
         return $this->redirectBack();
     }
 }
 /**
  * Handles the submission of the contact form. Checks spam and builds and sends the email
  *
  * @param array The form data
  * @param Form The Form object	
  */
 public function doContactFormSubmit($data, $form)
 {
     Session::set("FormData.{$form->FormName()}", $data);
     $proxy = $form->proxy;
     foreach ($proxy->getSpamProtection() as $spam) {
         if ($spam->isSpam($data, $form)) {
             $form->sessionMessage($spam->getMessage(), "bad");
             $spam->logSpamAttempt($this->owner->request);
             return $this->owner->redirectBack();
         }
     }
     if ($func = $proxy->getOnBeforeSend()) {
         $result = $func($data, $form, $proxy);
         if ($result === false) {
             return $this->owner->redirectBack();
         }
     }
     $this->sendEmail($data, $form);
     Session::clear("FormData.{$form->FormName()}");
     if ($func = $proxy->getOnAfterSend()) {
         $func($data, $form, $proxy);
     }
     if ($proxy->getSuccessURL()) {
         return $this->owner->redirect($proxy->getSuccessURL());
     } else {
         if (Director::is_ajax()) {
             return new SS_HTTPResponse($proxy->getSuccessMessage());
         }
         $form->sessionMessage(strip_tags($proxy->getSuccessMessage()), 'good');
         return $this->owner->redirectBack();
     }
 }
 function submit($data, $form)
 {
     // if rewards added and get it button clicked then validate and save to order object
     if (isset($data['action_submit']) && isset($data['Quantity'])) {
         Session::clear($this->controller->RewardsSessionKey());
         foreach ($data['Quantity'] as $ProductID => $quantity) {
             $item = $this->controller->newReward($ProductID, $quantity);
             Session::set($this->controller->RewardsSessionKey($ProductID), serialize($item));
         }
         if ($this->controller->RewardsTotalPoints() > Page_Controller::MemberPointsBalance()) {
             $this->sessionMessage('You do not have enough points to purchase these rewards.', 'error');
             Director::redirectBack();
             return;
         }
         $new_items = $this->controller->RewardItems();
     }
     //delete all existing reward items for this order
     $order_items = $this->controller->Order()->RewardItems();
     foreach ($order_items as $o_item) {
         $o_item->delete();
     }
     // then flush rewards from session
     Session::clear($this->controller->RewardsSessionKey());
     //then link the reward items to the order
     if (isset($new_items)) {
         foreach ($new_items as $item) {
             $item->write();
         }
     }
     // then redirect to next step
     Director::redirect($this->controller->Link() . 'checkoutstep/orderconfirmationandpayment/');
 }
Example #4
0
 /**
  * Login form handler method
  *
  * This method is called when the user clicks on "Log in"
  *
  * @param array $data Submitted data
  */
 public function dologin($data)
 {
     if ($this->performLogin($data)) {
         Session::clear('SessionForms.MemberLoginForm.Email');
         Session::clear('SessionForms.MemberLoginForm.Remember');
         if (isset($_REQUEST['BackURL']) && ($backURL = $_REQUEST['BackURL'])) {
             Session::clear("BackURL");
             Director::redirect($backURL);
         } else {
             Director::redirectBack();
         }
     } else {
         Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
         Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
         if (isset($_REQUEST['BackURL']) && ($backURL = $_REQUEST['BackURL'])) {
             Session::set('BackURL', $backURL);
         }
         if ($badLoginURL = Session::get("BadLoginURL")) {
             Director::redirect($badLoginURL);
         } else {
             // Show the right tab on failed login
             Director::redirect(Director::absoluteURL(Security::Link("login")) . '#' . $this->FormName() . '_tab');
         }
     }
 }
 function getCaptcha()
 {
     $key = TextCaptchaField::config()->ApiKey;
     $url = 'http://api.textcaptcha.com/' . $key;
     //if(Session::get('setCaptcha') == true && Session::get('question') === null && Session::get('captchaFail') != true) {}
     try {
         $xml = @new SimpleXMLElement($url, null, true);
     } catch (Exception $e) {
         // if there is a problem, use static fallback..
         $fallback = '<captcha>' . '<question>Is ice hot or cold?</question>' . '<answer>' . md5('cold') . '</answer></captcha>';
         $xml = new SimpleXMLElement($fallback);
     }
     // display question as part of form
     $question = (string) $xml->question;
     // store answers in session
     $ans = array();
     foreach ($xml->answer as $hash) {
         $ans[] = (string) $hash;
     }
     Session::set('captcha', $ans);
     Session::set('question', $question);
     Session::set('setCaptcha', true);
     Session::clear('captchaFail');
     return true;
 }
 /**
  * @param array $data
  * @return SS_HTTPResponse|void
  */
 function doChangePassword(array $data)
 {
     try {
         $token = Session::get('AutoLoginHash');
         $member = $this->password_manager->changePassword($token, @$data['NewPassword1'], @$data['NewPassword2']);
         Session::clear('AutoLoginHash');
         $back_url = isset($_REQUEST['BackURL']) ? $_REQUEST['BackURL'] : '/';
         return OpenStackIdCommon::loginMember($member, $back_url);
     } catch (InvalidResetPasswordTokenException $ex1) {
         Session::clear('AutoLoginHash');
         Controller::curr()->redirect('login');
     } catch (EmptyPasswordException $ex2) {
         $this->clearMessage();
         $this->sessionMessage(_t('Member.EMPTYNEWPASSWORD', "The new password can't be empty, please try again"), "bad");
         Controller::curr()->redirectBack();
     } catch (PasswordMismatchException $ex3) {
         $this->clearMessage();
         $this->sessionMessage(_t('Member.ERRORNEWPASSWORD', "You have entered your new password differently, try again"), "bad");
         Controller::curr()->redirectBack();
     } catch (InvalidPasswordException $ex4) {
         $this->clearMessage();
         $this->sessionMessage(sprintf(_t('Member.INVALIDNEWPASSWORD', "We couldn't accept that password: %s"), nl2br("\n" . $ex4->getMessage())), "bad");
         Controller::curr()->redirectBack();
     }
 }
 /**
  * Performs the login, but will also create and sync the Member record on-the-fly, if not found.
  *
  * @param array $data
  * @param Form $form
  * @return bool|Member|void
  * @throws SS_HTTPResponse_Exception
  */
 public static function authenticate($data, Form $form = null)
 {
     $service = Injector::inst()->get('LDAPService');
     $result = $service->authenticate($data['Username'], $data['Password']);
     $success = $result['success'] === true;
     if (!$success) {
         if ($form) {
             $form->sessionMessage($result['message'], 'bad');
         }
         return;
     }
     $data = $service->getUserByUsername($result['identity']);
     if (!$data) {
         if ($form) {
             $form->sessionMessage(_t('LDAPAuthenticator.PROBLEMFINDINGDATA', 'There was a problem retrieving your user data'), 'bad');
         }
         return;
     }
     // LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields
     $member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
     if (!($member && $member->exists())) {
         $member = new Member();
         $member->GUID = $data['objectguid'];
         $member->write();
     }
     Session::clear('BackURL');
     return $member;
 }
 function StartSurvey($data, $form)
 {
     try {
         $data = SQLDataCleaner::clean($data);
         $data['MembershipType'] = 'community';
         Session::set("FormInfo.{$form->FormName()}.data", $data);
         $profile_page = EditProfilePage::get()->first();
         $member = $this->member_manager->registerMobile($data, new MemberRegistrationSenderService());
         //Get profile page
         if (!is_null($profile_page)) {
             //Redirect to profile page with success message
             Session::clear("FormInfo.{$form->FormName()}.data");
             $request = Controller::curr()->getRequest();
             $back_url = $request->postVar('BackURL');
             $link = $profile_page->Link('?success=1');
             if (!empty($back_url)) {
                 $link .= "&BackURL=" . $back_url;
             }
             return OpenStackIdCommon::loginMember($member, $link);
         }
     } catch (EntityValidationException $ex1) {
         Form::messageForForm($form->FormName(), $ex1->getMessage(), 'bad');
         //Return back to form
         SS_Log::log($ex1->getMessage(), SS_Log::WARN);
         return Controller::curr()->redirectBack();
     } catch (Exception $ex) {
         Form::messageForForm($form->FormName(), "There was an error with your request, please contact your admin.", 'bad');
         //Return back to form
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         return Controller::curr()->redirectBack();
     }
 }
 public function doAddItemToCart($data)
 {
     $product = Product::get()->byID($data['ProductID']);
     $customisations = array();
     foreach ($data as $key => $value) {
         if (!(strpos($key, 'customise') === false) && $value) {
             $custom_data = explode("_", $key);
             if ($custom_item = ProductCustomisation::get()->byID($custom_data[1])) {
                 $modify_price = 0;
                 // Check if the current selected option has a price modification
                 if ($custom_item->Options()->exists()) {
                     $option = $custom_item->Options()->filter("Title", $value)->first();
                     $modify_price = $option ? $option->ModifyPrice : 0;
                 }
                 $customisations[] = array("Title" => $custom_item->Title, "Value" => $value, "ModifyPrice" => $modify_price);
             }
         }
     }
     if ($product) {
         $cart = ShoppingCart::create();
         $cart->add($product, $data['Quantity'], $customisations);
         $cart->save();
         // Clear any postage data that has been set
         Session::clear("Commerce.PostageID");
         $message = _t('Commerce.AddedItemToCart', 'Added item to your shopping cart');
         $message .= ' <a href="' . $cart->Link() . '">';
         $message .= _t('Commerce.ViewCart', 'View cart');
         $message .= '</a>';
         $this->controller->setSessionMessage("success", $message);
     }
     return $this->controller->redirectBack();
 }
 function onBeforeIndex($controller)
 {
     Session::clear("ViewDeploymentSurveyStatistics_survey_range");
     Session::clear("ViewDeploymentStatistics_survey_range");
     Session::clear("ViewDeploymentsPerRegion_survey_range");
     Session::clear("global_survey_range");
 }
 public function onPlaceOrder()
 {
     if (session_id()) {
         unset($_SESSION['Cart']);
         Session::clear('Cart');
     }
 }
 function saveEventRegistrationRequest($data, Form $form)
 {
     // Check if the honeypot has been filled out
     if (@$data['username']) {
         SS_Log::log(sprintf('EventRegistrationRequestForm honeypot triggered (data: %s)', http_build_query($data)), SS_Log::NOTICE);
         return $this->httpError(403);
     }
     try {
         $this->event_registration_request_manager->registerEventRegistrationRequest($data);
         Session::clear("FormInfo.Form_EventRegistrationRequestForm.data");
         $form->clearMessage();
         return $this->redirect($this->Link('?saved=1'));
     } catch (EntityValidationException $ex1) {
         $messages = $ex1->getMessages();
         $msg = $messages[0];
         $form->addErrorMessage('City', $msg['message'], 'bad');
         SS_Log::log($msg['message'], SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data);
         return $this->redirectBack();
     } catch (Exception $ex) {
         $form->addErrorMessage('Title', 'Server Error', 'bad');
         SS_Log::log($ex->getMessage(), SS_Log::ERR);
         // Load errors into session and post back
         Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data);
         return $this->redirectBack();
     }
 }
 /**
  * Handles validation and saving new Member objects, as well as sending out validation emails.
  */
 public function register($data, Form $form)
 {
     if ($member = $this->addMember($form)) {
         $this->addRegistration($form, $member);
         if (!$this->RequireApproval && $this->EmailType != 'Validation' && !$this->AllowAdding) {
             $member->logIn();
         }
         if ($this->RegistrationRedirect) {
             if ($this->PostRegistrationTargetID) {
                 $this->redirect($this->PostRegistrationTarget()->Link());
                 return;
             }
             if ($sessionTarget = Session::get('MemberProfile.REDIRECT')) {
                 Session::clear('MemberProfile.REDIRECT');
                 if (Director::is_site_url($sessionTarget)) {
                     $this->redirect($sessionTarget);
                     return;
                 }
             }
         }
         return $this->redirect($this->Link('afterregistration'));
     } else {
         return $this->redirectBack();
     }
 }
Example #14
0
 function index()
 {
     Session::clear("loggedInAs");
     Requirements::themedCSS("form");
     // if the email address is given
     $emailAddress = Convert::raw2sql($this->urlParams['Email']);
     $mailingListID = (int) $this->urlParams['MailingList'];
     if ($mailingListID) {
         $mailingList = DataObject::get_by_id("NewsletterType", $mailingListID);
     }
     // try to find the member with the email specified
     if ($emailAddress) {
         $member = DataObject::get_one('Member', "`Email` = '{$emailAddress}'");
     } else {
         $member = false;
     }
     // if the email address and mailing list is given in the URL and both are valid,
     // then unsubscribe the user
     if ($member && $mailingList && $member->inGroup($mailingList->GroupID)) {
         $this->unsubscribeFromList($member, $mailingList);
         $url = '/done/' . $member->Email . '/' . $mailingList->Title;
         Director::redirect(Director::absoluteBaseURL() . $this->RelativeLink() . $url);
         return;
     } elseif ($member) {
         $listForm = $this->MailingListForm($member);
     } else {
         $listForm = $this->EmailAddressForm();
     }
     if ($this->urlParams['Email'] == "done") {
         $listForm->sessionMessage(_t('Unsubscribe.SUCCESS', 'Thank you. You have been removed from the selected groups'), "good");
     }
     return $this->customise(array('Content' => $listForm->forTemplate()))->renderWith('Page');
 }
Example #15
0
 /**
  * When an error page is published, create a static HTML page with its
  * content, so the page can be shown even when SilverStripe is not
  * functioning correctly before publishing this page normally.
  * @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
  * @param string $toStage Place to copy to. Must be a stage name.
  * @param boolean $createNewVersion Set this to true to create a new version number.  By default, the existing version number will be copied over.
  */
 function publish($fromStage, $toStage, $createNewVersion = false)
 {
     // Temporarily log out when producing this page
     $loggedInMember = Member::currentUser();
     Session::clear("loggedInAs");
     $alc_enc = isset($_COOKIE['alc_enc']) ? $_COOKIE['alc_enc'] : null;
     Cookie::set('alc_enc', null);
     $oldStage = Versioned::current_stage();
     // Run the page
     Requirements::clear();
     $controller = new ErrorPage_Controller($this);
     $errorContent = $controller->run(array())->getBody();
     if (!file_exists("../assets")) {
         mkdir("../assets", 02775);
     }
     if ($fh = fopen("../assets/error-{$this->ErrorCode}.html", "w")) {
         fwrite($fh, $errorContent);
         fclose($fh);
     }
     // Restore the version we're currently connected to.
     Versioned::reading_stage($oldStage);
     // Log back in
     if ($loggedInMember) {
         Session::set("loggedInAs", $loggedInMember->ID);
     }
     if (isset($alc_enc)) {
         Cookie::set('alc_enc', $alc_enc);
     }
     return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
 }
 function ShippingEstimates()
 {
     $estimates = Session::get("ShippingEstimates");
     Session::set("ShippingEstimates", null);
     Session::clear("ShippingEstimates");
     return $estimates;
 }
 /**
  * Submit the form
  *
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse
  */
 public function Subscribe($data, $form)
 {
     /** @var Form $form */
     $data = $form->getData();
     /** Set the form state */
     Session::set('FormInfo.Form_' . $this->name . '.data', $data);
     $siteConfig = SiteConfig::current_site_config();
     /** Check if the API key, and List ID have been set. */
     if ($siteConfig->MailChimpAPI && $siteConfig->MailChimpListID) {
         $mailChimp = new \Drewm\MailChimp($siteConfig->MailChimpAPI);
         $result = $mailChimp->call('lists/subscribe', array('id' => $siteConfig->MailChimpListID, 'email' => array('email' => $data['Email'])));
     } else {
         /** If not, redirect back and display a flash error. */
         $this->controller->setFlash('Missing API key, or List ID', 'danger');
         return $this->controller->redirectBack();
     }
     /**
      * If the status of the request returns an error,
      * display the error
      */
     if (isset($result['status'])) {
         if ($result['status'] == 'error') {
             $this->controller->setFlash($result['error'], 'danger');
             return $this->controller->redirectBack();
         }
     }
     /** Clear the form state */
     Session::clear('FormInfo.Form_' . $this->name . '.data');
     if ($siteConfig->MailChimpSuccessMessage) {
         $this->controller->setFlash($siteConfig->MailChimpSuccessMessage, 'success');
     } else {
         $this->controller->setFlash('Your subscription has been received, you will be sent a confirmation email shortly.', 'success');
     }
     return $this->controller->redirect($this->controller->data()->Link());
 }
 public function init()
 {
     parent::init();
     $this->errorCode = Session::get('MAILCHIMP_ERRCODE');
     $this->errorMessage = Session::get('MAILCHIMP_ERRMSG');
     Session::clear('MAILCHIMP_ERRCODE');
     Session::clear('MAILCHIMP_ERRMSG');
 }
Example #19
0
 function logout()
 {
     Session::clear('isLoggedIn');
     Session::clear('username');
     Session::clear('designation');
     Session::clear('time');
     Helper::redirect('user/login');
 }
 public function doLogout()
 {
     //on se deconnecte, on efface tout
     Auth::logout();
     Cache::flush();
     Session::clear();
     return Redirect::to('/');
 }
 /**
  * Get a flash message that is rendered into a template
  *
  * @return String
  */
 public function getFlashMessage()
 {
     if ($message = Session::get('Site.Message')) {
         Session::clear('Site.Message');
         $array = new ArrayData($message);
         return $array->renderWith('FlashMessage');
     }
 }
 /**
  * Adds the user to the database
  */
 public function addUser()
 {
     if ($this->model->insertUser($this->newUser)) {
         Session::clear('register');
         header('Location: ' . URL . 'auth?created=1');
     } else {
         header('Location: ' . URL . 'register/page/4?error=1');
     }
 }
Example #23
0
 /**
  * destroy session aka logout
  */
 public function doLogout()
 {
     Session::clear('my_user');
     //Session::destroy();
     unset($_COOKIE);
     setcookie('rememberBana', '', time() - 3600);
     header('Location: ../auth?logout=1');
     exit;
 }
 function onBeforeInit()
 {
     if (isset($_REQUEST['FAKE_IP'])) {
         Session::set('FAKE_IP', $_REQUEST['FAKE_IP']);
     }
     if (isset($_REQUEST['CLEAR_FAKE_IP'])) {
         Session::clear('FAKE_IP');
     }
 }
Example #25
0
 /**
  * @param $data
  * @param Form $form
  * @return bool|SS_HTTPResponse
  * Handle form submission
  */
 public function Submit($data, Form $form)
 {
     Session::set('Contact', $data);
     if ($this->sendMail($data)) {
         Session::clear('Contact');
     }
     $form->sessionMessage('Your message has been sent', 'good');
     return $this->redirectBack();
 }
Example #26
0
 function testIncViews()
 {
     $thread = $this->objFromFixture("ForumThread", "Thread1");
     // clear session
     Session::clear('ForumViewed-' . $thread->ID);
     $this->assertEquals($thread->NumViews, '10');
     $thread->incNumViews();
     $this->assertEquals($thread->NumViews, '11');
 }
 function FormMessage()
 {
     if (Session::get('MultiFormMessage')) {
         $message = Session::get('MultiFormMessage');
         Session::clear('MultiFormMessage');
         return $message;
     }
     return false;
 }
Example #28
0
 public function logout()
 {
     Session::clear();
     $backurl = $_REQUEST["backurl"];
     if (empty($backurl)) {
         $backurl = "/";
     }
     echo "<script type='text/javascript'>location.href='" . $backurl . "';try{window.event.returnValue=false;}catch(e){}</script>";
 }
 /**
  * @return HTMLText
  */
 public function getFlashMessage()
 {
     if ((string) ($message = Session::get('FlashMessage'))) {
         Session::clear('FlashMessage');
         /** @var ArrayData $array */
         $array = ArrayData::create($message);
         return $array->renderWith('FlashMessage');
     }
     return false;
 }
Example #30
0
 function testClear()
 {
     Session::clear();
     $this->assertFalse(Session::is_set("/prova"), "La variabile prova e' gia' impostata!!");
     Session::set("/prova", "ok");
     $this->assertTrue(Session::is_set("/prova"), "la chiave prova non e' stata trovata.");
     $this->assertTrue(Session::get("/prova"), "ok", "Il valore della chiave non corrisponde!!");
     Session::clear();
     $this->assertFalse(Session::is_set("/prova"), "la chiave prova e' stata trovata.");
 }