This commit is contained in:
Alex Grintsvayg 2017-01-30 15:19:31 -05:00
parent 8d0c394d59
commit 4849c5b370
4 changed files with 62 additions and 25 deletions

View file

@ -90,7 +90,7 @@ class Controller
$router->get('/roadmap', 'ContentActions::executeRoadmap'); $router->get('/roadmap', 'ContentActions::executeRoadmap');
$router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram'); $router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram');
$router->post('/developer-program', 'AcquisitionActions::executeDeveloperProgramRedirect'); $router->post('/developer-program/post', 'AcquisitionActions::executeDeveloperProgramPost');
$router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback'); $router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback');
$router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit');

View file

@ -3,9 +3,9 @@
class AcquisitionActions extends Actions class AcquisitionActions extends Actions
{ {
const DEVELOPER_REWARD = 250, const DEVELOPER_REWARD = 250,
SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error', SESSION_KEY_DEVELOPER_CREDITS_ERROR = 'acquisition.developer-credits-error',
SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success', SESSION_KEY_DEVELOPER_CREDITS_SUCCESS = 'acquisition.developer-credits-success',
SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address';
public static function executeThanks() public static function executeThanks()
{ {
@ -49,15 +49,15 @@ class AcquisitionActions extends Actions
{ {
$vars = [ $vars = [
'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), 'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS),
'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR),
'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS)
]; ];
Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS); Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS);
Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR); Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR);
return ['acquisition/developer-program', $vars]; return ['acquisition/developer-program', $vars];
} }
public static function executeDeveloperProgramRedirect() public static function executeDeveloperProgramPost()
{ {
$walletAddress = trim(Request::getPostParam('wallet')); $walletAddress = trim(Request::getPostParam('wallet'));
Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress);
@ -71,10 +71,15 @@ class AcquisitionActions extends Actions
} }
else 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'), 'client_id' => Config::get('github_developer_credits_client_id'),
'redirect_uri' => 'http://localhost:8000/developer-program/callback', 'redirect_uri' => Request::getHostAndProto() . '/developer-program/callback',
'scope' => 'user:email', 'scope' => 'user:email',
'allow_signup' => false '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));
@ -84,9 +89,10 @@ class AcquisitionActions extends Actions
public static function executeDeveloperProgramGithubCallback() public static function executeDeveloperProgramGithubCallback()
{ {
$code = Request::getParam('code'); $code = Request::getParam('code');
$walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); $walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS);
if (!$walletAddress || !$code)
if (!$walletAddress)
{ {
Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.');
} }
@ -97,11 +103,11 @@ class AcquisitionActions extends Actions
else else
{ {
$authResponseData = Curl::post('https://github.com/login/oauth/access_token', [ $authResponseData = Curl::post('https://github.com/login/oauth/access_token', [
'code' => $code, 'code' => $code,
'client_id' => Config::get('github_developer_credits_client_id'), 'client_id' => Config::get('github_developer_credits_client_id'),
'client_secret' => Config::get('github_developer_credits_client_secret') 'client_secret' => Config::get('github_developer_credits_client_secret')
], [ ], [
'headers' => ['Accept: application/json'], 'headers' => ['Accept: application/json'],
'json_response' => true 'json_response' => true
]); ]);
if (!$authResponseData || !isset($authResponseData['access_token'])) if (!$authResponseData || !isset($authResponseData['access_token']))
@ -114,9 +120,9 @@ class AcquisitionActions extends Actions
} }
else else
{ {
$accessToken = $authResponseData['access_token']; $accessToken = $authResponseData['access_token'];
$userResponseData = Curl::get('https://api.github.com/user', [], [ $userResponseData = Curl::get('https://api.github.com/user', [], [
'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'],
'json_response' => true 'json_response' => true
]); ]);
@ -133,7 +139,8 @@ class AcquisitionActions extends Actions
*/ */
Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS, Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS,
'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . $walletAddress); 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' .
$walletAddress);
} }
} }
} }

View file

@ -10,7 +10,7 @@
<p> <p>
We will store your GitHub username and email address, but nothing else. We will store your GitHub username and email address, but nothing else.
</p> </p>
<form method="POST" action="/developer-program" class="form-inset"> <form method="POST" action="/developer-program/post" class="form-inset">
<h3 style="margin-top: 0">Receive Credits</h3> <h3 style="margin-top: 0">Receive Credits</h3>
<?php if ($error): ?> <?php if ($error): ?>
<div class="notice notice-error spacer1"><?php echo $error ?></div> <div class="notice notice-error spacer1"><?php echo $error ?></div>

View file

@ -61,11 +61,41 @@
<p> <p>
To verify the LBRY daemon is running correctly and responding to requests, run: To verify the LBRY daemon is running correctly and responding to requests, run:
</p> </p>
<pre><code>curl --data "{ method: 'status' }" http://localhost:5279/lbryapi <pre><code>curl 'http://localhost:5279/lbryapi' --data '{"method":"status","params":[]}'
(add response when this works)</code></pre> [
{
"connection_status": {
"message": "No connection problems detected",
"code": "connected"
},
"is_first_run": false,
"is_running": true,
"blocks_behind": 0,
"startup_status": {
"message": "Started lbrynet",
"code": "started"
},
"lbry_id": "7J75jSuxU9eizREuxk1r"
}
]</code></pre>
<p>This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:</p> <p>This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:</p>
<pre><code>curl --data "{ method: 'resolve_name', params: [{ name: "what"}] }" http://localhost:5279/lbryapi <pre><code>curl 'http://localhost:5279/lbryapi' --data '{"method":"resolve_name","params":[{"name":"what"}]}'
(add response when this works)</code></pre> [
{
"ver": "0.0.3",
"description": "What is LBRY? An introduction with Alex Tabarrok",
"license": "LBRY inc",
"title": "What is LBRY?",
"author": "Samuel Bryan",
"language": "en",
"sources": {
"lbry_sd_hash": "d5169241150022f996fa7cd6a9a1c421937276a3275eb912790bd07ba7aec1fac5fd45431d226b8fb402691e79aeb24b"
},
"content_type": "video\/mp4",
"nsfw": false,
"thumbnail": "https:\/\/s3.amazonaws.com\/files.lbry.io\/logo.png"
}
]</code></pre>
<p>LBRY can be used to build everything from a censorship-proof image host, to a store for 3D printing files, to distribute large files or datasets, or use cases even we can't imagine!</p> <p>LBRY can be used to build everything from a censorship-proof image host, to a store for 3D printing files, to distribute large files or datasets, or use cases even we can't imagine!</p>
<p><a class="btn-alt" href="http://lbryio.github.io/lbry/api/">View Full API Documentation</a></p> <p><a class="btn-alt" href="http://lbryio.github.io/lbry/api/">View Full API Documentation</a></p>
</section> </section>
@ -73,8 +103,8 @@
<h3 id="credits">4. Getting Credits</h3> <h3 id="credits">4. Getting Credits</h3>
<p>Many actions, such as reserving a name or purchasing paid content, require credits.</p> <p>Many actions, such as reserving a name or purchasing paid content, require credits.</p>
<p>To receive credits, first generate a wallet address:</p> <p>To receive credits, first generate a wallet address:</p>
<pre><code>curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi <pre><code>curl 'http://localhost:5279/lbryapi' --data '{"method":"wallet_new_address","params":[]}'
I am a response</code></pre> ["bbFxRyWCFRkA9YcuuZD8nE7XTLUxYnddTs"]</code></pre>
<p>Use this address to get credits in one of two ways:</p> <p>Use this address to get credits in one of two ways:</p>
<div class="row-fluid"> <div class="row-fluid">
<div class="span6"> <div class="span6">