it works?

This commit is contained in:
Jeremy Kauffman 2017-02-26 14:59:44 -05:00
parent 32ca0d7f94
commit ab45fce4ff
14 changed files with 144 additions and 114 deletions

View file

@ -89,10 +89,9 @@ class Controller
$router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet');
$router->get('/roadmap', 'ContentActions::executeRoadmap');
$router->post('/quickstart/auth', 'DeveloperActions::executeQuickstartAuth');
$router->get('/quickstart/{step}?', 'DeveloperActions::executeQuickstart');
$router->get('/developer-program', 'DeveloperActions::executeDeveloperProgram');
$router->post('/developer-program/post', 'DeveloperActions::executeDeveloperProgramPost');
$router->get('/developer-program/callback', 'DeveloperActions::executeDeveloperProgramGithubCallback');
$router->get('/quickstart/github/callback', 'DeveloperActions::executeQuickstartGithubCallback');
$router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit');

View file

@ -7,8 +7,9 @@ class Session
KEY_PREFINERY_USER_ID = 'prefinery_user_id',
KEY_PREFINER_USED_CUSTOM_CODE = 'prefinery_used_custom_code',
KEY_DEVELOPER_CREDITS_ERROR = 'developer_credits_error',
KEY_DEVELOPER_CREDITS_SUCCESS = 'developer_credits_success',
KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'developer_credits_wallet_address',
KEY_DEVELOPER_RETURN_URL_SUCCESS = 'developer_return_url_success',
KEY_GITHUB_ACCESS_TOKEN = 'github_access_token',
KEY_LIST_SUB_ERROR = 'list_error',
KEY_USER_CULTURE = 'user_culture';

View file

@ -47,21 +47,14 @@ class DeveloperActions extends Actions
];
}
public static function executeDeveloperProgram()
{
return ['developer/developer-program', [
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR),
'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS)
]];
}
public static function prepareFormNewPartial(array $vars)
public static function prepareFormNewDeveloperRewardPartial(array $vars)
{
$sendToGithub = !Session::get(Session::KEY_GITHUB_ACCESS_TOKEN);
return $vars + [
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR),
'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS)
'sendToGithub' => $sendToGithub,
'apiUrl' => LBRY::getApiUrl('/user/new_github')
];
}
@ -70,68 +63,66 @@ class DeveloperActions extends Actions
return $vars + [
'defaultWalletAddress' => Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
'error' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_ERROR),
'success' => Session::getFlash(Session::KEY_DEVELOPER_CREDITS_SUCCESS)
];
}
public static function executeDeveloperProgramPost()
public static function executeQuickstartAuth()
{
$walletAddress = trim(Request::getPostParam('wallet'));
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress);
Session::set(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, trim(Request::getPostParam('wallet_address')));
if (!$walletAddress)
if (Request::getPostParam('returnUrl'))
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.');
Session::set(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, Request::getPostParam('returnUrl'));
}
elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress))
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.');
}
else
{
if (!Config::get('github_developer_credits_client_id'))
{
throw new Exception('no github client id');
}
$githubParams = [
$gitHubParams = [
'client_id' => Config::get('github_developer_credits_client_id'),
'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback',
'redirect_uri' => Request::getHostAndProto() . '/quickstart/github/callback',
'scope' => 'user:email public_repo',
'allow_signup' => false
];
return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams));
return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($gitHubParams));
}
return Controller::redirect(Request::getReferrer('/quickstart/credits'));
}
public static function executeDeveloperProgramGithubCallback()
public static function executeQuickstartGithubCallback()
{
$code = Request::getParam('code');
$walletAddress = Session::get(Session::KEY_DEVELOPER_CREDITS_WALLET_ADDRESS);
if (!$walletAddress)
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.');
}
elseif (!$code)
if (!$code)
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.');
}
else
{
$newUserUrl = LBRY::getApiUrl('/user/new_developer');
$lbryApiResponseData = Curl::post($newUserUrl, [
'github_code' => $code
$authResponseData = Curl::post('https://github.com/login/oauth/access_token', [
'code' => $code,
'client_id' => Config::get('github_developer_credits_client_id'),
'client_secret' => Config::get('github_developer_credits_client_secret')
], [
// 'json_response' => true
'headers' => ['Accept: application/json'],
'json_response' => true
]);
echo '<pre>';
print_r($lbryApiResponseData);
die('omg');
if (!$authResponseData || !isset($authResponseData['access_token']))
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.');
}
elseif (isset($authResponseData['error_description']))
{
Session::setFlash(Session::KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']);
}
else
{
Session::set(Session::KEY_GITHUB_ACCESS_TOKEN, $authResponseData['access_token']);
}
}
return Controller::redirect(Request::getReferrer('/quickstart/credits'));
return Controller::redirect(Session::get(Session::KEY_DEVELOPER_RETURN_URL_SUCCESS, '/quickstart/credits'));
}
}

View file

@ -14,6 +14,6 @@ class LBRY
'cache' => 3600, //one hour
'json_response' => true
]);
return $response['rate'];
return $response['data']['lbc_usd'] ?? 0;
}
}

View file

@ -1,4 +1,4 @@
<form method="POST" action="/developer-program/post" class="form-inset">
<form method="POST" action="/quickstart/auth" class="form-inset">
<h4 style="margin-top: 0">Receive Credits</h4>
<?php if ($error): ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div>

View file

@ -1,20 +0,0 @@
<form method="POST" action="/developer-program/post" class="form-inset">
<h4 style="margin-top: 0">Receive Credits</h4>
<?php if ($error): ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div>
<?php elseif ($success): ?>
<div class="notice notice-success spacer1"><?php echo $success ?></div>
<?php endif ?>
<div class="form-row">
<label for="wallet">Wallet Address</label>
<div class="form-input">
<input type="text" name="wallet" value="<?php echo $defaultWalletAddress ?>"
class="required standard input-wallet" placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
</div>
</div>
<div class="spacer-half">
<input type="submit" value="Continue to GitHub" class="btn-primary">
</div>
<div class="meta">We require a GitHub account to prevent abuse. This will record your email (no spam) and mark you as interested in the lbry repo.
No GitHub account? No problem! Join our <a href="https://slack.lbry.io" class="link-primary">Slack channel</a> and post an introduction in #tech.</div>
</form>

View file

@ -0,0 +1,22 @@
<?php js_start() ?>
lbry.quickstartForm('#form-new-developer-reward', "<?php echo $apiUrl ?>");
<?php js_end() ?>
<form method="POST" action="/quickstart/auth" class="form-inset" id="form-new-developer-reward">
<h4 style="margin-top: 0">Receive Credits</h4>
<div class="notice notice-error spacer1 <?php echo isset($error) && $error ? '' : 'hide' ?>"><?php echo $error ?? null ?></div>
<div class="notice notice-success spacer1 hide"></div>
<div class="form-row">
<label for="wallet">Wallet Address</label>
<div class="form-input">
<input type="text" name="wallet_address" value="<?php echo $defaultWalletAddress ?>"
class="required standard input-wallet" placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
</div>
</div>
<div class="submit-row spacer-half">
<input type="hidden" name="returnUrl" value="<?php echo $returnUrl ?? '/quickstart/credits#no-return' ?>" />
<input type="hidden" name="access_token" value="<?php echo Session::get(Session::KEY_GITHUB_ACCESS_TOKEN) ?>" />
<input type="submit" value="Send" class="btn-primary" data-submit-label="Send" data-submitting-label="Sending credits..." />
</div>
<div class="meta">We require a GitHub account to prevent abuse. This will record your email (no spam) and mark you as interested in the lbry repo.
No GitHub account? No problem! Join our <a href="https://slack.lbry.io" class="link-primary">Slack channel</a> and post an introduction in #tech.</div>
</form>

View file

@ -3,7 +3,7 @@
When running, the LBRY daemon provides a JSON-RPC server running at <span class="code-plain">https://localhost:5279/lbryapi</span>.
</p>
<p>
It can be accessed via cURL or any other utility capable of making HTTPS GET and POST requests. So, basically anything, including possibly your toaster.
It can be accessed by any utility capable of making HTTPS GET and POST requests, such as cURL or possibly your toaster.
</p>
<p>
To verify the LBRY daemon is running correctly, let's try looking up a name:

View file

@ -4,8 +4,10 @@
<code class="code-bash"><span class="code-bash__prompt">$</span>curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}'
["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"]</code>
<p>Enter this address in the form below and we'll send you 50 credits.</p>
<div class="quickstart__claim-form content-light content">
<?php echo View::render('developer/_formNew') ?>
<div class="quickstart__claim-form content-light content" id="new-developer">
<?php echo View::render('developer/_formNewDeveloperReward', [
'returnUrl' => Request::getRelativeUri() . '#new-developer'
]) ?>
</div>
<p>Next, confirm you've received your credits by calling <span class="code-plain">wallet_balance</span>:</p>
<code class="code-bash"><span class="code-bash__prompt">$</span>curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_balance"}'

View file

@ -29,5 +29,5 @@
<p>While running, the daemon will provide a JSON-RPC interface on localhost. We'll learn how to interact with that next.</p>
<?php /*
<div class="meta spacer1">macOS and Windows do not currently bundle the daemon separately. Just launch the full app and the API will still be available. This will be resolved in v0.9.</div>
*/ ?>
<div class="meta">The first time you run the daemon, it must catch-up with most recent blockheaders. This can take a few minutes.</div>
*/ ?>

View file

@ -1,31 +0,0 @@
<?php NavActions::setNavUri('/learn') ?>
<?php Response::setMetaDescription('Be up and running with the LBRY API in just a few minutes.') ?>
<?php Response::setMetaTitle('LBRY Quickstart') ?>
<?php echo View::render('nav/_header', ['isDark' => false, 'isAbsolute' => false]) ?>
<main >
<div class="content content-light markdown">
<h1>Developer Program</h1>
<p>All developers with a GitHub account prior to January 31st, 2017 are eligible for <?php echo DeveloperActions::DEVELOPER_REWARD ?> free credits.</p>
<p>To claim your credits, enter a wallet address in the form below and authenticate with GitHub.</p>
<p>
We will store your GitHub username and email address, but nothing else.
</p>
<form method="POST" action="/developer-program/post" class="form-inset">
<h3 style="margin-top: 0">Receive Credits</h3>
<?php if ($error): ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div>
<?php elseif ($success): ?>
<div class="notice notice-success spacer1"><?php echo $success ?></div>
<?php endif ?>
<div class="form-row">
<label for="wallet">Wallet Address</label>
<div class="form-input">
<input type="text" name="wallet" value="<?php echo $defaultWalletAddress ?>"
class="required standard input-wallet" placeholder="bYnFQUPTTDM1BYNCxgxKEav4FFQsrgDBoE">
</div>
</div>
<input type="submit" value="Continue to GitHub" class="btn-primary">
</form>
</div>
</main>
<?php echo View::render('nav/_footer') ?>

View file

@ -1,4 +1,5 @@
<?php NavActions::setNavUri('/learn') ?>
<?php Response::addJsAsset('/js/quickstart.js') ?>
<?php Response::setMetaDescription('Be up and running with the LBRY API in just a few minutes.') ?>
<?php Response::setMetaTitle('LBRY Quickstart') ?>
<?php echo View::render('nav/_header', ['isDark' => false, 'isAbsolute' => false]) ?>

59
web/js/quickstart.js Normal file
View file

@ -0,0 +1,59 @@
lbry.quickstartForm = function (selector, apiUrl) {
var form = $(selector),
accessToken = form.find(':input[name="access_token"]').val(),
walletAddressInput = form.find(':input[name="wallet_address"]'),
submitButton = form.find(':input[type="submit"]'),
isSubmitting = false;
function resetFormState() {
isSubmitting = false;
walletAddressInput.attr('readonly', null);
submitButton.val(submitButton.data('submitLabel')).attr('disabled', null);
}
if (window.localStorage.getItem("quickstartFormSuccessHtml")) {
form.find('.notice-success').html(window.localStorage.getItem("quickstartFormSuccessHtml")).show();
form.find('.form-row, .submit-row').hide();
} else if (accessToken) {
form.submit(function (event) {
if (isSubmitting) {
return false;
}
form.find('.notice-success, .notice-error').hide();
if (!walletAddressInput.val()) {
resetFormState();
form.find('.notice-error').html("Please supply a wallet address.").show();
return false;
}
event.preventDefault();
walletAddressInput.attr('readonly', 'readonly');
submitButton.val(submitButton.data('submittingLabel')).attr('disabled', 'disabled');
$.post(apiUrl, {
access_token: accessToken,
wallet_address: walletAddressInput.val()
})
.done(function (responseData) {
var data = responseData.data;
var anchor = $('<a class="link-primary"></a>');
anchor.attr("href", "https://explorer.lbry.io/tx/" + data.TransactionHash);
anchor.html(data.TransactionHash)
form.find('.notice-success')
.html(data.RewardAmount + " credits sent in transaction ")
.append(anchor)
.show();
window.localStorage.setItem("quickstartFormSuccessHtml", form.find('.notice-success').html());
})
.fail(function (xhr) {
var responseData = $.parseJSON(xhr.responseText);
form.find('.notice-error').html(responseData.error.length ? responseData.error : "Something went wrong. Please email grin@lbry.io").show();
})
.always(resetFormState);
})
form.submit();
}
}

View file

@ -104,6 +104,9 @@ input[type="date"] {
border: 1px solid #ccc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.1);
transition: all 0.2s linear;
&[readonly] {
background-color: #bbb;
}
}
textarea:focus,
@ -126,6 +129,9 @@ input[type="checkbox"] {
width: auto;
}
input[type="submit"][disabled] {
cursor: auto;
}
.mail-submit, .invite-submit
{