add android/ios tags

This commit is contained in:
Alex Grintsvayg 2017-12-13 10:57:27 -05:00
parent 19c061bca9
commit 66397a7f93
9 changed files with 34 additions and 110 deletions

View file

@ -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))

View file

@ -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

View file

@ -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']]];

View file

@ -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)

View file

@ -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 <mail@' . static::MAIL_DOMAIN . '>',
'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);

View file

@ -1,17 +0,0 @@
<form method="POST" action="/signup" id="signup-form">
<?php if (Session::get(Session::KEY_DOWNLOAD_ACCESS_ERROR)): ?>
<div class="notice notice-error spacer1"><?php echo Session::get(Session::KEY_DOWNLOAD_ACCESS_ERROR) ?></div>
<?php Session::unsetKey(Session::KEY_DOWNLOAD_ACCESS_ERROR) ?>
<?php endif ?>
<div class="form-row">
<label for="email">
<?php echo __('email.address') ?>
</label>
<div class="form-input">
<input type="text" value="<?php echo htmlspecialchars($defaultEmail) ?>" name="email" class="required standard input-large" placeholder="someone@somewhere.com">
</div>
</div>
<div class="invite-submit">
<input type="submit" value="Join List" name="subscribe" class="btn-alt btn-large">
</div>
</form>

View file

@ -44,14 +44,18 @@
</div>
<?php else: ?>
<p>{{download.unavailable}}</p>
<?php echo View::render('download/_signup') ?>
<?php echo View::render('mail/_subscribeForm', [
'tag' => 'lbryio-waitlist-'.ltrim($os, '/'),
'submitLabel' => 'Join List',
'hideDisclaimer' => true,
'largeInput' => true,
'btnClass' => 'btn-alt btn-large',
]) ?>
<?php endif ?>
</div>
</div>
<div class="span5">
<?php echo View::render('download/_list', [
'excludeOs' => $os
]) ?>
<?php echo View::render('download/_list', ['excludeOs' => $os]) ?>
<?php echo View::render('download/_social') ?>
</div>
</main>

View file

@ -47,7 +47,13 @@
</div>
<?php else: ?>
<p>{{download.unavailable}}</p>
<?php echo View::render('download/_signup') ?>
<?php echo View::render('mail/_subscribeForm', [
'tag' => 'lbryio-waitlist-'.ltrim($os, '/'),
'submitLabel' => 'Join List',
'hideDisclaimer' => true,
'largeInput' => true,
'btnClass' => 'btn-alt btn-large',
]) ?>
<?php endif ?>
</div>
</div>

View file

@ -1,4 +1,6 @@
<?php $error = $error ?? null ?>
<?php $tag = $tag ?? null ?>
<?php $largeInput = $largeInput ?? false ?>
<form action="/list/subscribe" method="POST" novalidate>
<?php if ($error): ?>
@ -6,9 +8,16 @@
<?php endif ?>
<div class="mail-submit">
<input type="email" name="email" class="required email standard <?php echo $largeInput ? 'input-large' : '' ?>" placeholder="{{email.placeholder}}">
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?>"/>
<input type="email" name="email" class="required email standard" placeholder="{{email.placeholder}}">
<?php if ($tag): ?>
<input type="hidden" name="tag" value="<?php echo $tag ?>"/>
<?php endif ?>
<input type="submit" value="<?php echo $submitLabel ?? __('email.subs') ?>" name="subscribe" class="<?php echo $btnClass ?>">
<div class="meta">{{email.disclaimer}}</div>
<?php if (!($hideDisclaimer ?? false)): ?>
<div class="meta">{{email.disclaimer}}</div>
<?php endif ?>
</div>
</form>