[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [donate/master] Changes to handle subscriptions from lektor



commit 1934fbdb02066f5729cf502d3f340a7efe3a1337
Author: Peter Haight <peterh@xxxxxxxxxxxxxxx>
Date:   Fri Sep 25 17:29:03 2020 -0700

    Changes to handle subscriptions from lektor
    
    This lets Lektor handle the subscription forms and get back error
    messages and get redirected back to the correct pages.
    
    Issue #48283
---
 src/SubscriptionController.php | 28 +++++++++++++++++++++-------
 src/settings.php               | 11 ++++++++---
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/src/SubscriptionController.php b/src/SubscriptionController.php
index c1ee6b66..7b8f7bc9 100644
--- a/src/SubscriptionController.php
+++ b/src/SubscriptionController.php
@@ -6,16 +6,17 @@ class SubscriptionController extends BaseController {
   const REDIS_PREFIX = "subscription_request:";
   public $vars;
   public $redisClient = NULL;
+  public $settings;
 
   public function __construct($container) {
     parent::__construct($container);
     $this->vars = array();
+    $this->settings = $this->container->get('settings');
   }
 
   public function getRedisClient() {
     if ($this->redisClient == NULL) {
-      $settings = $this->container->get('settings');
-      $this->redisClient = new \Predis\Client($settings['redis']);
+      $this->redisClient = new \Predis\Client($this->settings['redis']);
     }
     return $this->redisClient;
   }
@@ -35,7 +36,7 @@ class SubscriptionController extends BaseController {
     $queryParams = $request->getQueryParams();
     $token = ArrayExt::fetch($queryParams, 'token');
     if ($token === NULL) {
-      $errors[] = "There should have been a query parameter called token in the URL we sent you, but that seems to be missing. If you cut and pasted the URL, double check that you got the entire streng.";
+      $errors[] = "There should have been a query parameter called token in the URL we sent you, but that seems to be missing. If you cut and pasted the URL, double check that you got the entire string.";
     }
     if (empty($errors)) {
       $redis = $this->getRedisClient();
@@ -54,10 +55,17 @@ class SubscriptionController extends BaseController {
       $crmController->sendMessage('Tor\Subscription\Subscribe', $subscriptionInfo);
       $counter = new SubscriptionCounter($this->container);
       $counter->countSubscriptionConfirmed();
-      return $response->withRedirect("/subscribed");
+      return $response->withRedirect($this->settings->get('subscriptionConfirmedUrl', '/subscribed'));
     } else {
-      $this->vars['errors'] = $errors;
-      return $this->renderer->render($response, 'subscribe.twig', $this->vars);
+      $subscriptionErrorUrl = $this->settings->get('subscriptionErrorUrl');
+      if ($subscriptionErrorUrl === NULL) {
+        $this->vars['errors'] = $errors;
+        return $this->renderer->render($response, 'subscribe.twig', $this->vars);
+      } else {
+        $uri = Uri::createFromString($subscriptionErrorUrl);
+        $uri->addQueryParam('errors', json_encode($errors));
+        return $response->withRedirect($uri->toString());
+      }
     }
   }
 
@@ -91,8 +99,14 @@ class SubscriptionController extends BaseController {
       $ipRateLimiter = $this->container->get('ipRateLimiter');
       $ipRateLimiter->check($request);
       $this->sendSubscriptionConfirmation($request, $subscriptionInfo);
-      return $response->withRedirect("/subscription-request-sent");
+      return $response->withRedirect($this->settings->get('subscriptionRequestSentUrl', '/subscription-request-sent'));
     } else {
+      if (ArrayExt::fetch($parsedBody, 'returnToReferrer')) {
+        $referer = reset($request->getHeader("HTTP_REFERER"));
+        $uri = Uri::createFromString($referer);
+        $uri->addQueryParam('errors', json_encode($errors));
+        return $response->withRedirect($uri->toString());
+      }
       $this->vars['errors'] = $errors;
       $this->vars['parsedBody'] = $parsedBody;
       return $this->renderer->render($response, 'subscribe.twig', $this->vars);
diff --git a/src/settings.php b/src/settings.php
index 0324bbae..3958ddea 100644
--- a/src/settings.php
+++ b/src/settings.php
@@ -3,8 +3,12 @@
 define('PP_CONFIG_PATH', __DIR__ . '/../private');
 require PP_CONFIG_PATH . '/settings.local.php';
 
-if (!isset($torSiteBaseUrl)) {
-  $torSiteBaseUrl = 'https://www.torproject.org/';
+if (!isset($localOptions)) {
+  $localOptions = [];
+}
+
+if (!array_key_exists('torSiteBaseUrl', $localOptions)) {
+  $localOptions['torSiteBaseUrl'] = 'https://www.torproject.org/';
 }
 
 $config = [
@@ -55,8 +59,9 @@ $config = [
       'sandbox' => 'AZc7yGlGGXnOjwt55x4wRGbWHo7Fdj83JAu0lqYruVWVoYa7JfQhy5F_ucy2mR6CjPmpmJwmtHONjTeB',
       'production' => 'AbzwWJgUgwGMvTupfvigx1yAj75jNnCj4mFGC_VbiROUi2TfVwPS9IZ5MfqLsSUnXJFSMwaSaTR4FY_A'
     ],
-    'torSiteBaseUrl' => $torSiteBaseUrl,
   ],
 ];
 
+$config['settings'] = array_merge($config['settings'], $localOptions);
+
 return $config;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits