Ejemplo n.º 1
0
 /**
  * Send a mail asking the customer, if he actually wants to reset his password
  *
  * @param string $email
  * @return array
  */
 public function sendResetPasswordConfirmationMail($email)
 {
     $snippets = Shopware()->Snippets()->getNamespace('frontend/account/password');
     if (empty($email)) {
         return array('sErrorMessages' => array($snippets->get('ErrorForgotMail')));
     }
     $userID = Shopware()->Modules()->Admin()->sGetUserByMail($email);
     if (empty($userID)) {
         return array('sErrorMessages' => array($snippets->get('ErrorForgotMailUnknown')));
     }
     $hash = \Shopware\Components\Random::getAlphanumericString(32);
     $router = $this->Front()->Router();
     $context = array('sUrlReset' => $router->assemble(array('controller' => 'Password', 'action' => 'resetPassword', 'hash' => $hash)), 'sUrl' => $router->assemble(array('controller' => 'Password', 'action' => 'resetPassword')), 'sKey' => $hash);
     // Send mail
     $mail = Shopware()->TemplateMail()->createMail('sPLUGCONFIRMPASSWORDCHANGE', $context);
     $mail->addTo($email);
     try {
         $mail->send();
     } catch (Exception $e) {
         return array('sErrorMessages' => array($snippets->get('ErrorForgotMailUnknown')));
     }
     // Add the hash to the optin table
     $sql = "INSERT INTO `s_core_optin` (`type`, `datum`, `hash`, `data`) VALUES ('password', NOW(), ?, ?)";
     Shopware()->Db()->query($sql, array($hash, $userID));
     return array();
 }
Ejemplo n.º 2
0
 /**
  *
  */
 public function refreshCaptchaAction()
 {
     $rand = \Shopware\Components\Random::getAlphanumericString(32);
     $string = md5($rand);
     $string = substr($string, 0, 5);
     $imgResource = $this->getImageResource($string);
     ob_start();
     imagepng($imgResource, null, 9);
     $img = ob_get_clean();
     imagedestroy($imgResource);
     $img = base64_encode($img);
     echo '<img src="data:image/png;base64,' . $img . '" alt="Captcha" />';
     echo '<input type="hidden" name="sRand" value="' . $rand . '" />';
 }
Ejemplo n.º 3
0
 /**
  * Index action method
  */
 public function indexAction()
 {
     $this->View()->voteConfirmed = $this->isConfirmed();
     if (isset($this->Request()->sUnsubscribe)) {
         $this->View()->sUnsubscribe = true;
     } else {
         $this->View()->sUnsubscribe = false;
     }
     $this->View()->_POST = Shopware()->System()->_POST->toArray();
     if (!isset(Shopware()->System()->_POST["newsletter"])) {
         return;
     }
     if (Shopware()->System()->_POST["subscribeToNewsletter"] != 1) {
         // Unsubscribe user
         $this->View()->sStatus = Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST["newsletter"], true);
         $session = $this->container->get('session');
         if ($session->offsetExists('sNewsletter')) {
             $session->offsetSet('sNewsletter', false);
         }
         return;
     }
     if (empty(Shopware()->Config()->sOPTINNEWSLETTER) || $this->View()->voteConfirmed) {
         $this->View()->sStatus = Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST["newsletter"], false);
         if ($this->View()->sStatus['code'] == 3) {
             // Send mail to subscriber
             $this->sendMail(Shopware()->System()->_POST["newsletter"], 'sNEWSLETTERCONFIRMATION');
         }
     } else {
         $this->View()->sStatus = Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST["newsletter"], false);
         if ($this->View()->sStatus["code"] == 3) {
             Shopware()->Modules()->Admin()->sNewsletterSubscription(Shopware()->System()->_POST["newsletter"], true);
             $hash = \Shopware\Components\Random::getAlphanumericString(32);
             $data = serialize(Shopware()->System()->_POST->toArray());
             $link = $this->Front()->Router()->assemble(array('sViewport' => 'newsletter', 'action' => 'confirm', 'sConfirmation' => $hash));
             $this->sendMail(Shopware()->System()->_POST["newsletter"], 'sOPTINNEWSLETTER', $link);
             // Setting status-code
             $this->View()->sStatus = array("code" => 3, "message" => Shopware()->Snippets()->getNamespace('frontend')->get('sMailConfirmation'));
             Shopware()->Db()->query("\n                INSERT INTO s_core_optin (datum,hash,data)\n                VALUES (\n                now(),?,?\n                )\n                ", array($hash, $data));
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Send new password by email address
  *
  * @param string $email
  * @return array
  */
 public function sendPassword($email)
 {
     $snippets = Shopware()->Snippets()->getNamespace('frontend/account/password');
     if (empty($email)) {
         return array('sErrorMessages' => array($snippets->get('ErrorForgotMail')));
     }
     $userID = Shopware()->System()->sMODULES['sAdmin']->sGetUserByMail($email);
     if (empty($userID)) {
         return array('sErrorMessages' => array($snippets->get('ErrorForgotMailUnknown')));
     }
     $password = \Shopware\Components\Random::getAlphanumericString((int) Shopware()->Config()->get('minpassword', 6));
     $encoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();
     $hash = Shopware()->PasswordEncoder()->encodePassword($password, $encoderName);
     $sql = "UPDATE s_user SET password=?, encoder=?, failedlogins=4, lockeduntil='lockeduntil' WHERE id=?";
     Shopware()->Db()->query($sql, array($hash, $encoderName, $userID));
     $context = array('sMail' => $email, 'sPassword' => $password);
     $mail = Shopware()->TemplateMail()->createMail('sPASSWORD', $context);
     $mail->addTo($email);
     $mail->send();
     return array('sSuccess' => true);
 }
Ejemplo n.º 5
0
 /**
  * @param $data
  * @param $encryptionMethod
  * @throws \Exception
  * @return array
  */
 private function encryptData($data, $encryptionMethod)
 {
     $publicKeyString = $this->publicKey;
     $publicKey = openssl_pkey_get_public($publicKeyString);
     $key = Random::getAlphanumericString(32);
     $ivLength = openssl_cipher_iv_length($encryptionMethod);
     $iv = Random::getBytes($ivLength);
     $encryptedMessage = openssl_encrypt($data, $encryptionMethod, $key, false, $iv);
     $encryptedKey = '';
     if (!true === openssl_public_encrypt($key, $encryptedKey, $publicKey)) {
         $errors = array();
         while ($errors[] = openssl_error_string()) {
         }
         $errorString = implode("\n", $errors);
         throw new \Exception("Got openssl error" . $errorString);
     }
     $result = array('encryptedKey' => base64_encode($encryptedKey), 'iv' => base64_encode($iv), 'encryptionMethod' => $encryptionMethod, 'encryptedMessage' => $encryptedMessage);
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * Returns unique id of this shop installation.
  * If no unique id exists it will be created.
  *
  * @return string
  */
 private function getUnique()
 {
     $config = $this->getPluginConfig();
     if (isset($config['update-unique-id']) && !empty($config['update-unique-id'])) {
         return $config['update-unique-id'];
     }
     $uniqueid = Random::getAlphanumericString(32);
     $shop = $this->get('models')->getRepository('Shopware\\Models\\Shop\\Shop')->findOneBy(array('default' => true));
     $pluginManager = $this->container->get('shopware.plugin_manager');
     $plugin = $pluginManager->getPluginByName('SwagUpdate');
     $pluginManager->saveConfigElement($plugin, 'update-unique-id', $uniqueid, $shop);
     return $uniqueid;
 }
Ejemplo n.º 7
0
 /**
  * Called on register for status updates
  * Check user email address and send double optin to confirm the email
  * @static
  * @param Enlight_Event_EventArgs $args
  * @return
  */
 public static function onNotifyAction(Enlight_Event_EventArgs $args)
 {
     $args->setProcessed(true);
     $action = $args->getSubject();
     $id = (int) $action->Request()->sArticle;
     $email = $action->Request()->sNotificationEmail;
     $sError = false;
     $action->View()->NotifyEmailError = false;
     $notifyOrderNumber = $action->Request()->notifyOrdernumber;
     if (!empty($notifyOrderNumber)) {
         $validator = Shopware()->Container()->get('validator.email');
         if (empty($email) || !$validator->isValid($email)) {
             $sError = true;
             $action->View()->NotifyEmailError = true;
         } elseif (!empty($notifyOrderNumber)) {
             if (!empty(Shopware()->Session()->sNotificatedArticles)) {
                 if (in_array($notifyOrderNumber, Shopware()->Session()->sNotificatedArticles)) {
                     $sError = true;
                     $action->View()->ShowNotification = false;
                     $action->View()->NotifyAlreadyRegistered = true;
                 } else {
                     Shopware()->Session()->sNotificatedArticles[] = $notifyOrderNumber;
                 }
             } else {
                 Shopware()->Session()->sNotificatedArticles = array($notifyOrderNumber);
             }
         } else {
             $sError = true;
         }
         if (!$sError) {
             $AlreadyNotified = Shopware()->Db()->fetchRow('
                 SELECT *  FROM `s_articles_notification`
                 WHERE `ordernumber`=?
                 AND `mail` = ?
                 AND send = 0
             ', array($notifyOrderNumber, $email));
             if (empty($AlreadyNotified)) {
                 $action->View()->NotifyAlreadyRegistered = false;
                 $hash = \Shopware\Components\Random::getAlphanumericString(32);
                 $link = $action->Front()->Router()->assemble(array('sViewport' => 'detail', 'sArticle' => $id, 'sNotificationConfirmation' => $hash, 'sNotify' => '1', 'action' => 'notifyConfirm', 'number' => $notifyOrderNumber));
                 $name = Shopware()->Modules()->Articles()->sGetArticleNameByOrderNumber($notifyOrderNumber);
                 $basePath = $action->Front()->Router()->assemble(array('sViewport' => 'index'));
                 Shopware()->System()->_POST['sLanguage'] = Shopware()->Shop()->getId();
                 Shopware()->System()->_POST['sShopPath'] = $basePath . Shopware()->Config()->sBASEFILE;
                 $sql = '
                     INSERT INTO s_core_optin (datum, hash, data)
                     VALUES (NOW(), ?, ?)
                 ';
                 Shopware()->Db()->query($sql, array($hash, serialize(Shopware()->System()->_POST->toArray())));
                 $context = array('sConfirmLink' => $link, 'sArticleName' => $name);
                 $mail = Shopware()->TemplateMail()->createMail('sACCEPTNOTIFICATION', $context);
                 $mail->addTo($email);
                 $mail->send();
                 Shopware()->Session()->sNotifcationArticleWaitingForOptInApprovement[$notifyOrderNumber] = true;
             } else {
                 $action->View()->NotifyAlreadyRegistered = true;
             }
         }
     }
     return $action->forward('index');
 }
Ejemplo n.º 8
0
 /**
  * Rating action method
  *
  * Save and review the product rating
  */
 public function ratingAction()
 {
     $id = (int) $this->Request()->sArticle;
     if (empty($id)) {
         return $this->forward('error');
     }
     $article = Shopware()->Modules()->Articles()->sGetArticleNameByArticleId($id);
     if (empty($article)) {
         return $this->forward('error');
     }
     $voteConfirmed = false;
     if ($hash = $this->Request()->sConfirmation) {
         $getVote = Shopware()->Db()->fetchRow('
             SELECT * FROM s_core_optin WHERE hash = ?
         ', array($hash));
         if (!empty($getVote['data'])) {
             Shopware()->System()->_POST = unserialize($getVote['data']);
             $voteConfirmed = true;
             Shopware()->Db()->query('DELETE FROM s_core_optin WHERE hash = ?', array($hash));
         }
     }
     if (empty(Shopware()->System()->_POST['sVoteName'])) {
         $sErrorFlag['sVoteName'] = true;
     }
     if (empty(Shopware()->System()->_POST['sVoteSummary'])) {
         $sErrorFlag['sVoteSummary'] = true;
     }
     if (!empty(Shopware()->Config()->CaptchaColor) && !$voteConfirmed) {
         $captcha = str_replace(' ', '', strtolower($this->Request()->sCaptcha));
         $rand = $this->Request()->getPost('sRand');
         if (empty($rand) || $captcha != substr(md5($rand), 0, 5)) {
             $sErrorFlag['sCaptcha'] = true;
         }
     }
     $validator = $this->container->get('validator.email');
     if (!empty(Shopware()->Config()->sOPTINVOTE) && (empty(Shopware()->System()->_POST['sVoteMail']) || !$validator->isValid(Shopware()->System()->_POST['sVoteMail']))) {
         $sErrorFlag['sVoteMail'] = true;
     }
     if (empty($sErrorFlag)) {
         if (!empty(Shopware()->Config()->sOPTINVOTE) && !$voteConfirmed && empty(Shopware()->Session()->sUserId)) {
             $hash = \Shopware\Components\Random::getAlphanumericString(32);
             $sql = '
                 INSERT INTO s_core_optin (datum, hash, data)
                 VALUES (NOW(), ?, ?)
             ';
             Shopware()->Db()->query($sql, array($hash, serialize(Shopware()->System()->_POST->toArray())));
             $link = $this->Front()->Router()->assemble(array('sViewport' => 'detail', 'action' => 'rating', 'sArticle' => $id, 'sConfirmation' => $hash));
             $context = array('sConfirmLink' => $link, 'sArticle' => array('articleName' => $article));
             $mail = Shopware()->TemplateMail()->createMail('sOPTINVOTE', $context);
             $mail->addTo($this->Request()->getParam('sVoteMail'));
             $mail->send();
         } else {
             unset(Shopware()->Config()->sOPTINVOTE);
             Shopware()->Modules()->Articles()->sSaveComment($id);
         }
     } else {
         $this->View()->sFormData = Shopware()->System()->_POST->toArray();
         $this->View()->sErrorFlag = $sErrorFlag;
     }
     $this->View()->sAction = 'ratingAction';
     $this->forward('index');
 }