/**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return array to be rendered in the controller
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 27.06.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $emailAddress = $formData['emailaddress'];
     $password = $formData['password'];
     // get customers data
     $user = Member::get()->filter('Email', $formData['emailaddress'])->first();
     if ($user) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) {
                     //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();
             if ($this->Controller()->redirectedTo() == '') {
                 $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder");
                 $this->Controller()->redirect($myAccountHolder->RelativeLink());
             }
         } else {
             $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.'));
             Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });');
             return $this->submitFailure($data, $form);
         }
     } else {
         $this->addMessage(_t('SilvercartPage.CREDENTIALS_WRONG'));
         Requirements::customScript('jQuery(document).ready(function(){ $("#silvercart-quicklogin-form").slideDown(); });');
         return $this->submitFailure($data, $form);
     }
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return array to be rendered in the controller
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 27.06.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $emailAddress = $formData['emailaddress'];
     $password = $formData['password'];
     // get customers data
     $user = Member::get()->filter('Email', $formData['emailaddress'])->first();
     if ($user) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) {
                     //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();
             $myAccountHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartMyAccountHolder");
             $this->controller->redirect($myAccountHolder->RelativeLink());
         } else {
             $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG', 'Your credentials are incorrect.')));
             return $this->submitFailure($data, $form);
         }
     } else {
         $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.EMAIL_NOT_FOUND', 'This Email address could not be found.')));
         return $this->messages = array('Authentication' => array('message' => _t('SilvercartPage.CREDENTIALS_WRONG')));
     }
 }
 /**
  * We register the common forms for SilvercartPages here.
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>,
  *         Patrick Schneider <*****@*****.**>
  * @since 08.07.2014
  */
 public function onBeforeInit()
 {
     SilvercartTools::initSession();
     i18n::set_default_locale(Translatable::get_current_locale());
     i18n::set_locale(Translatable::get_current_locale());
     $controllerParams = Controller::curr()->getURLParams();
     $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
     if ($anonymousCustomer) {
         Session::set('MemberLoginForm.force_message', true);
         if ($controllerParams['Action'] == 'changepassword') {
             $anonymousCustomer->logOut();
         }
     } else {
         Session::set('MemberLoginForm.force_message', false);
         // used to redirect the logged in user to my-account page
         $backURL = SilvercartTools::PageByIdentifierCodeLink(self::$newPasswordBackURLIdentifierCode);
         $this->owner->extend('updateNewPasswordBackURL', $backURL);
         Session::set('BackURL', $backURL);
         Session::save();
     }
     $this->owner->registerCustomHtmlForm('SilvercartQuickSearchForm', new SilvercartQuickSearchForm($this->owner));
     $this->owner->registerCustomHtmlForm('SilvercartQuickLoginForm', new SilvercartQuickLoginForm($this->owner));
     SilvercartPlugin::call($this->owner, 'init', array($this->owner));
 }
 /**
  * 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 <*****@*****.**>
  * @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']);
 }
 /**
  * processor method
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function process()
 {
     $checkoutData = $this->controller->getCombinedStepData();
     $member = SilvercartCustomer::currentUser();
     if ($member instanceof Member) {
         // Vorbereitung der Parameter zur Erzeugung der Bestellung
         if (isset($checkoutData['Email'])) {
             $customerEmail = $checkoutData['Email'];
         } else {
             $customerEmail = '';
         }
         if (isset($checkoutData['Note'])) {
             $customerNote = $checkoutData['Note'];
         } else {
             $customerNote = '';
         }
         $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
         if ($anonymousCustomer) {
             // add a customer number to anonymous customer when ordering
             $anonymousCustomer->CustomerNumber = SilvercartNumberRange::useReservedNumberByIdentifier('CustomerNumber');
             $anonymousCustomer->write();
         }
         $shippingData = SilvercartTools::extractAddressDataFrom('Shipping', $checkoutData);
         $invoiceData = SilvercartTools::extractAddressDataFrom('Invoice', $checkoutData);
         $order = $this->createOrder($customerEmail, $checkoutData, $customerNote);
         $this->extend('onAfterCreateOrder', $order);
         $order->createShippingAddress($shippingData);
         $order->createInvoiceAddress($invoiceData);
         $order->convertShoppingCartPositionsToOrderPositions();
         // send order confirmation mail
         if ($this->sendConfirmationMail) {
             $order->sendConfirmationMail();
         }
         $this->controller->setStepData(array('orderId' => $order->ID));
         $this->controller->addCompletedStep();
         $this->controller->NextStep(false);
     }
     return false;
 }
 /**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 27.06.2014
  */
 public function submitSuccess($data, $form, $formData)
 {
     $emailAddress = $formData['Email'];
     $password = $formData['Password'];
     // get customers data
     $user = Member::get()->filter('Email', $emailAddress)->first();
     if ($user) {
         $customer = MemberAuthenticator::authenticate(array('Email' => $emailAddress, 'Password' => $password));
         if ($customer) {
             //transfer cart positions from an anonymous user to the one logging in
             $anonymousCustomer = SilvercartCustomer::currentAnonymousCustomer();
             if ($anonymousCustomer) {
                 if ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions()->exists()) {
                     //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();
             $this->getController()->redirect($this->getController()->Link());
         } else {
             $this->addErrorMessage('Password', _t('SilvercartPage.PASSWORD_WRONG', 'This user does not exist.'));
             return $this->submitFailure($data, $form);
         }
     } else {
         $this->addErrorMessage('Email', _t('SilvercartPage.USER_NOT_EXISTING', 'This user does not exist.'));
         return $this->submitFailure($data, $form);
     }
 }