From 66397a7f93117388d082aa658c2007ef3c93c806 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 13 Dec 2017 10:57:27 -0500 Subject: [PATCH] add android/ios tags --- controller/Controller.class.php | 2 - controller/action/DownloadActions.class.php | 24 --------- controller/action/MailActions.class.php | 4 +- lib/thirdparty/LBRY.class.php | 7 ++- lib/thirdparty/Mailgun.class.php | 57 --------------------- view/template/download/_signup.php | 17 ------ view/template/download/get.php | 12 +++-- view/template/download/getrubin.php | 8 ++- view/template/mail/_subscribeForm.php | 13 ++++- 9 files changed, 34 insertions(+), 110 deletions(-) delete mode 100644 view/template/download/_signup.php diff --git a/controller/Controller.class.php b/controller/Controller.class.php index 96674605..462494da 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -180,8 +180,6 @@ class Controller $router->get(ContentActions::URL_CREDIT_REPORTS, 'ContentActions::executeCreditReports'); $router->get([ContentActions::URL_CREDIT_REPORTS . '/{year:c}-q{quarter:c}', ContentActions::URL_CREDIT_REPORTS . '/{year:c}-Q{quarter:c}'], 'ContentActions::executeCreditReport'); - $router->any(['/signup{whatever}?', 'signup'], 'DownloadActions::executeSignup'); - $router->get('/{slug}', function (string $slug) { if (View::exists('page/' . $slug)) diff --git a/controller/action/DownloadActions.class.php b/controller/action/DownloadActions.class.php index 9c91d7e5..e977f207 100644 --- a/controller/action/DownloadActions.class.php +++ b/controller/action/DownloadActions.class.php @@ -52,23 +52,6 @@ class DownloadActions extends Actions return ['download/get-no-os']; } - - public static function executeSignup() - { - $email = Request::getParam('email'); - - if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) - { - Session::set(Session::KEY_DOWNLOAD_ACCESS_ERROR, 'Please provide a valid email. You provided: ' . htmlspecialchars($email)); - } - else - { - Mailgun::sendSubscriptionConfirmation($email); - } - - return Controller::redirect(Request::getReferrer('/get')); - } - public static function prepareListPartial(array $vars) { return $vars + ['osChoices' => isset($vars['excludeOs']) ? @@ -77,13 +60,6 @@ class DownloadActions extends Actions ]; } - public static function prepareSignupPartial(array $vars) - { - return $vars + [ - 'defaultEmail' => static::getEmailParam(), - ]; - } - protected static function guessOs() { //if exact OS is requested, use that diff --git a/controller/action/MailActions.class.php b/controller/action/MailActions.class.php index c53c5e9b..a2cbc9b9 100644 --- a/controller/action/MailActions.class.php +++ b/controller/action/MailActions.class.php @@ -24,7 +24,9 @@ class MailActions extends Actions return Controller::redirect(Request::getRelativeUri()); } - $response = LBRY::subscribe($email); + $tag = Request::getPostParam('tag'); + + $response = LBRY::subscribe($email, $tag); if ($response['error']) { return ['mail/subscribe', ['error' => $response['error']]]; diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php index d601be12..6232b092 100644 --- a/lib/thirdparty/LBRY.class.php +++ b/lib/thirdparty/LBRY.class.php @@ -17,9 +17,12 @@ class LBRY return $response['data']['lbc_usd'] ?? 0; } - public static function subscribe($email) + public static function subscribe($email, $tag = null) { - return Curl::post(static::getApiUrl('/list/subscribe'), ['email' => $email], ['json_response' => true]); + return Curl::post(static::getApiUrl('/list/subscribe'), array_filter([ + 'email' => $email, + 'tag' => $tag, + ]), ['json_response' => true]); } public static function unsubscribe($email) diff --git a/lib/thirdparty/Mailgun.class.php b/lib/thirdparty/Mailgun.class.php index e9d4de13..1fb79693 100644 --- a/lib/thirdparty/Mailgun.class.php +++ b/lib/thirdparty/Mailgun.class.php @@ -37,63 +37,6 @@ class Mailgun return $status == 200; } - public static function sendSubscriptionConfirmation($email) - { - $confirmHash = static::getConfirmHash($email); - list($status, $headers, $body) = static::post('/' . static::MAIL_DOMAIN . '/messages', [ - 'from' => 'LBRY ', - 'to' => $email, - 'h:Reply-To' => 'help@lbry.io', - 'subject' => __('email.confirm_email_subject'), - 'html' => static::inlineCss(View::render('email_templates/_confirmHash', [ - 'confirmHash' => $confirmHash - ])), - 'o:tracking-clicks' => 'no', - 'o:tracking-opens' => 'no' - ]); - - return $status == 200; - } - - protected static function getConfirmHash($email, $timestamp = null, $nonce = null) - { - $timestamp = $timestamp !== null ? $timestamp : time(); - $nonce = $nonce !== null ? $nonce : bin2hex(random_bytes(8)); - $secret = Config::get('mailing_list_hmac_secret'); - - if (!$secret) - { - throw new RuntimeException('Mailing list HMAC secret is missing'); - } - - return Encoding::base64EncodeUrlsafe(join('|', [ - $email, $timestamp, $nonce, hash_hmac('sha256', $email . $timestamp . $nonce, $secret) - ])); - } - - public static function checkConfirmHashAndGetEmail($hash) - { - $parts = explode('|', Encoding::base64DecodeUrlsafe($hash)); - if (count($parts) !== 4) - { - return null; - } - - list($email, $timestamp, $nonce, $signature) = $parts; - - if (!hash_equals(static::getConfirmHash($email, $timestamp, $nonce), $hash)) - { - return null; - } - - if (!is_numeric($timestamp) || time() - $timestamp > 60 * 60 * 24 * 3) - { - return null; - } - - return $email; - } - protected static function post($endpoint, $data) { return static::request(Curl::POST, $endpoint, $data); diff --git a/view/template/download/_signup.php b/view/template/download/_signup.php deleted file mode 100644 index c7e46f25..00000000 --- a/view/template/download/_signup.php +++ /dev/null @@ -1,17 +0,0 @@ -
- -
- - -
- -
- -
-
-
- -
-
\ No newline at end of file diff --git a/view/template/download/get.php b/view/template/download/get.php index 4b323220..4b0372e5 100644 --- a/view/template/download/get.php +++ b/view/template/download/get.php @@ -44,14 +44,18 @@

{{download.unavailable}}

- + 'lbryio-waitlist-'.ltrim($os, '/'), + 'submitLabel' => 'Join List', + 'hideDisclaimer' => true, + 'largeInput' => true, + 'btnClass' => 'btn-alt btn-large', + ]) ?>
- $os - ]) ?> + $os]) ?>
diff --git a/view/template/download/getrubin.php b/view/template/download/getrubin.php index ef4cac78..c8886f17 100644 --- a/view/template/download/getrubin.php +++ b/view/template/download/getrubin.php @@ -47,7 +47,13 @@

{{download.unavailable}}

- + 'lbryio-waitlist-'.ltrim($os, '/'), + 'submitLabel' => 'Join List', + 'hideDisclaimer' => true, + 'largeInput' => true, + 'btnClass' => 'btn-alt btn-large', + ]) ?> diff --git a/view/template/mail/_subscribeForm.php b/view/template/mail/_subscribeForm.php index 132b7406..dedbd15b 100644 --- a/view/template/mail/_subscribeForm.php +++ b/view/template/mail/_subscribeForm.php @@ -1,4 +1,6 @@ + +
@@ -6,9 +8,16 @@
+ - + + + + -
{{email.disclaimer}}
+ + +
{{email.disclaimer}}
+
\ No newline at end of file