mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
fix for custom codes (blah) + put support for curl
This commit is contained in:
parent
98d9c5bb3f
commit
f17d0ae5c4
6 changed files with 72 additions and 14 deletions
|
@ -11,6 +11,7 @@ class Session
|
||||||
KEY_DOWNLOAD_ACCESS_ERROR = 'download_error2',
|
KEY_DOWNLOAD_ACCESS_ERROR = 'download_error2',
|
||||||
KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2',
|
KEY_DOWNLOAD_ALLOWED = 'beta_download_allowed2',
|
||||||
KEY_PREFINERY_USER_ID = 'prefinery_user_id',
|
KEY_PREFINERY_USER_ID = 'prefinery_user_id',
|
||||||
|
KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code',
|
||||||
KEY_LIST_SUB_ERROR = 'list_error',
|
KEY_LIST_SUB_ERROR = 'list_error',
|
||||||
KEY_LIST_SUB_SIGNATURE = 'list_sub_sig',
|
KEY_LIST_SUB_SIGNATURE = 'list_sub_sig',
|
||||||
KEY_LIST_SUB_SUCCESS = 'list_success',
|
KEY_LIST_SUB_SUCCESS = 'list_success',
|
||||||
|
|
|
@ -98,6 +98,10 @@ class DownloadActions extends Actions
|
||||||
{
|
{
|
||||||
$user = Prefinery::findOrCreateUser($email, $code, $referrerId);
|
$user = Prefinery::findOrCreateUser($email, $code, $referrerId);
|
||||||
static::setSessionVarsForPrefineryUser($user);
|
static::setSessionVarsForPrefineryUser($user);
|
||||||
|
if ($code && strlen($code) > 2 && in_array(substr($code, 0, 2), ['my', 'pf', 'sl']))
|
||||||
|
{
|
||||||
|
Session::set(Session::KEY_PREFINER_USED_CUSTOM_CODE, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (PrefineryException $e)
|
catch (PrefineryException $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
class Curl
|
class Curl
|
||||||
{
|
{
|
||||||
const GET = 'GET';
|
const GET = 'GET',
|
||||||
const POST = 'POST';
|
POST = 'POST',
|
||||||
|
PUT = 'PUT';
|
||||||
|
|
||||||
public static function get($url, $params = [], $options = [])
|
public static function get($url, $params = [], $options = [])
|
||||||
{
|
{
|
||||||
|
@ -17,6 +18,12 @@ class Curl
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function put($url, $params = [], $options = [])
|
||||||
|
{
|
||||||
|
list ($status, $headers, $body) = static::doCurl(static::PUT, $url, $params, $options);
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
public static function doCurl($method, $url, $params = [], $options = [])
|
public static function doCurl($method, $url, $params = [], $options = [])
|
||||||
{
|
{
|
||||||
$defaults = [
|
$defaults = [
|
||||||
|
@ -28,7 +35,7 @@ class Curl
|
||||||
'proxy' => null,
|
'proxy' => null,
|
||||||
'password' => null,
|
'password' => null,
|
||||||
'cookie' => null,
|
'cookie' => null,
|
||||||
'json_post' => false,
|
'json_data' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
$invalid = array_diff_key($options, $defaults);
|
$invalid = array_diff_key($options, $defaults);
|
||||||
|
@ -39,7 +46,7 @@ class Curl
|
||||||
|
|
||||||
$options = array_merge($defaults, $options);
|
$options = array_merge($defaults, $options);
|
||||||
|
|
||||||
if (!in_array($method, [static::GET, static::POST]))
|
if (!in_array($method, [static::GET, static::POST, static::PUT]))
|
||||||
{
|
{
|
||||||
throw new DomainException('Invalid method: ' . $method);
|
throw new DomainException('Invalid method: ' . $method);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +84,19 @@ class Curl
|
||||||
if ($method == static::POST)
|
if ($method == static::POST)
|
||||||
{
|
{
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['json_post'] ? json_encode($params) : http_build_query($params));
|
}
|
||||||
|
|
||||||
|
if ($method == static::PUT)
|
||||||
|
{
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_PUT, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($method, [static::PUT, static::POST]))
|
||||||
|
{
|
||||||
|
print_r($options['json_data'] ? json_encode($params) : http_build_query($params));
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $options['json_data'] ? json_encode($params) : http_build_query($params));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['proxy'])
|
if ($options['proxy'])
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Prefinery
|
||||||
'Accept: application/json',
|
'Accept: application/json',
|
||||||
'Content-type: application/json'
|
'Content-type: application/json'
|
||||||
],
|
],
|
||||||
'json_post' => true
|
'json_data' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,9 +70,20 @@ class Prefinery
|
||||||
'referrer_id' => $referrerId,
|
'referrer_id' => $referrerId,
|
||||||
'profile' => ['ip' => $ip, 'user_agent' => $ua]
|
'profile' => ['ip' => $ip, 'user_agent' => $ua]
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
// if ($inviteCode)
|
||||||
|
// {
|
||||||
|
// $user = static::updateTester(array_intersect_key($user, ['id' => null]) + ['status' => static::STATE_ACTIVE]);
|
||||||
|
// if ($user['invitation_code'] != $inviteCode)
|
||||||
|
// {
|
||||||
|
// $user['is_custom_code'] = true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
$user['is_custom_code'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($user['invitation_code']); // so we dont leak it
|
// unset($user['invitation_code']); // so we dont leak it
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,6 +92,25 @@ class Prefinery
|
||||||
return static::post('/testers', ['tester' => array_filter($testerData)], false);
|
return static::post('/testers', ['tester' => array_filter($testerData)], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function updateTester(array $testerData)
|
||||||
|
{
|
||||||
|
if (!$testerData['id'])
|
||||||
|
{
|
||||||
|
throw new PrefineryException('Update tester must be called with a tester id');
|
||||||
|
}
|
||||||
|
return static::put('/testers/' . $testerData['id'], ['tester' => array_diff_key(array_filter($testerData), ['id' => null])], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function put($endpoint, array $data = [])
|
||||||
|
{
|
||||||
|
$apiKey = Config::get('prefinery_key');
|
||||||
|
$options = static::$curlOptions;
|
||||||
|
$options['headers'][] = 'X-HTTP-Method-Override: PUT';
|
||||||
|
return static::decodePrefineryResponse(
|
||||||
|
Curl::put(static::DOMAIN . static::PREFIX . $endpoint . '.json?api_key=' . $apiKey, $data, $options)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected static function get($endpoint, array $data = [])
|
protected static function get($endpoint, array $data = [])
|
||||||
{
|
{
|
||||||
$apiKey = Config::get('prefinery_key');
|
$apiKey = Config::get('prefinery_key');
|
||||||
|
@ -119,10 +149,9 @@ class Prefinery
|
||||||
|
|
||||||
if (isset($data['errors']))
|
if (isset($data['errors']))
|
||||||
{
|
{
|
||||||
throw new PrefineryException(implode("\n", array_map(function ($error)
|
throw new PrefineryException($data['errors'] ? implode("\n", array_map(function ($error) {
|
||||||
{
|
|
||||||
return $error['message'];
|
return $error['message'];
|
||||||
}, (array)$data['errors'])));
|
}, (array)$data['errors'])) : 'Received empty error array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="notice notice-info">
|
<p>
|
||||||
<strong>{{download.beta}}</strong>
|
<strong>{{download.beta}}</strong>
|
||||||
{{download.curse}}
|
{{download.curse}}
|
||||||
</div>
|
</p>
|
|
@ -8,7 +8,12 @@
|
||||||
<h1><?php echo __('download.for-os', ['%os%' => $osTitle]) ?> <span class="<?php echo $osIcon ?>"></span></h1>
|
<h1><?php echo __('download.for-os', ['%os%' => $osTitle]) ?> <span class="<?php echo $osIcon ?>"></span></h1>
|
||||||
<?php if ($downloadHtml): ?>
|
<?php if ($downloadHtml): ?>
|
||||||
<?php echo View::render('download/_betaNotice') ?>
|
<?php echo View::render('download/_betaNotice') ?>
|
||||||
<h4>{{download.verb}}</h4>
|
<?php if (Session::get(Session::KEY_PREFINER_USED_CUSTOM_CODE)): ?>
|
||||||
|
<div class="notice notice-info spacer1">
|
||||||
|
It looks like you may have been invited via a custom code.
|
||||||
|
<strong>If so, please check your email for a single-use code to claim credits after installing.</strong>
|
||||||
|
</div>
|
||||||
|
<?php endif ?>
|
||||||
<?php echo $downloadHtml ?>
|
<?php echo $downloadHtml ?>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<?php echo View::render('download/_unavailable', [
|
<?php echo View::render('download/_unavailable', [
|
||||||
|
|
Loading…
Add table
Reference in a new issue