diff --git a/controller/Controller.class.php b/controller/Controller.class.php index ec62b745..d344c8a9 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -88,7 +88,10 @@ class Controller $router->get(['/android', 'get-android'], 'DownloadActions::executeGet'); $router->get(['/ios', 'get-ios'], 'DownloadActions::executeGet'); $router->get('/roadmap', 'ContentActions::executeRoadmap'); - $router->get('/credits-for-developers', 'AcquisitionActions::executeCreditsForDevelopers'); + + $router->get('/developer-program', 'AcquisitionActions::executeDeveloperProgram'); + $router->post('/developer-program', 'AcquisitionActions::executeDeveloperProgramRedirect'); + $router->get('/developer-program/callback', 'AcquisitionActions::executeDeveloperProgramGithubCallback'); $router->get(['/press-kit.zip', 'press-kit'], 'ContentActions::executePressKit'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 42c2e804..82cd1249 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -2,8 +2,11 @@ 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_SUCCESS = 'acquisition.developer-credits-success', + SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS = 'acquisition.developer-credits-wallet-address'; + public static function executeThanks() { return ['acquisition/thanks']; @@ -42,8 +45,98 @@ class AcquisitionActions extends Actions return [$template]; } - public static function executeCreditsForDevelopers() + public static function executeDeveloperProgram() { - return ['acquisition/credits-for-developers']; + $vars = [ + 'defaultWalletAddress' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS), + 'error' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR), + 'success' => Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS) + ]; + Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS); + Session::unsetKey(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR); + return ['acquisition/developer-program', $vars]; + } + + public static function executeDeveloperProgramRedirect() + { + $walletAddress = trim(Request::getPostParam('wallet')); + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS, $walletAddress); + if (!$walletAddress) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Please provide a wallet address.'); + } + elseif (!preg_match('/^b[1-9A-HJ-NP-Za-km-z]{33}$/', $walletAddress)) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid wallet address.'); + } + else + { + $githubParams = [ + 'client_id' => Config::get('github_developer_credits_client_id'), + 'redirect_uri' => 'http://localhost:8000/developer-program/callback', + 'scope' => 'user:email', + 'allow_signup' => false + ]; + return Controller::redirect('https://github.com/login/oauth/authorize?' . http_build_query($githubParams)); + } + return Controller::redirect('/developer-program'); + } + + public static function executeDeveloperProgramGithubCallback() + { + $code = Request::getParam('code'); + $walletAddress = Session::get(static::SESSION_KEY_DEVELOPER_CREDITS_WALLET_ADDRESS); + if (!$walletAddress || !$code) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Your wallet address disappeared while authenticated with GitHub.'); + } + elseif (!$code) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This does not appear to be a valid response from GitHub.'); + } + else + { + $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') + ], [ + 'headers' => ['Accept: application/json'], + 'json_response' => true + ]); + if (!$authResponseData || !isset($authResponseData['access_token'])) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'Request to GitHub failed.'); + } + elseif (isset($authResponseData['error_description'])) + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'GitHub replied: ' . $authResponseData['error_description']); + } + else + { + $accessToken = $authResponseData['access_token']; + $userResponseData = Curl::get('https://api.github.com/user', [], [ + 'headers' => ['Authorization: token ' . $accessToken, 'Accept: application/json', 'User-Agent: lbryio'], + 'json_response' => true + ]); + + if (date('Y-m', strtotime($userResponseData['created_at'])) > '2017-01') + { + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_ERROR, 'This GitHub account is too recent.'); + } + else + { + // print_r($userResponseData); + /* + * TODO: send credits here, see success message below for relevant values + * (keep wallet address in success message) + */ + + Session::set(static::SESSION_KEY_DEVELOPER_CREDITS_SUCCESS, + 'Send credits to GitHub user ' . $userResponseData['login'] . ' (' . $userResponseData['email'] . ') at wallet address ' . $walletAddress); + } + } + } + return Controller::redirect('/developer-program'); } } \ No newline at end of file diff --git a/view/template/acquisition/credits-for-developers.php b/view/template/acquisition/developer-program.php similarity index 55% rename from view/template/acquisition/credits-for-developers.php rename to view/template/acquisition/developer-program.php index 6df1b9e6..c6c66347 100644 --- a/view/template/acquisition/credits-for-developers.php +++ b/view/template/acquisition/developer-program.php @@ -4,18 +4,24 @@ false, 'isAbsolute' => false]) ?>
-

Credits For Developers

-

All developers with a GitHub account prior to 2017 are eligible for free credits.

+

Developer Program

+

All developers with a GitHub account prior to January 31st, 2017 are eligible for free credits.

To claim your credits, enter a wallet address in the form below and authenticate with GitHub.

We will store your GitHub username and email address, but nothing else.

-
+

Receive Credits

+ +
+ +
+
- +
diff --git a/view/template/page/quickstart.php b/view/template/page/quickstart.php index 94cbc46b..845d0d8e 100644 --- a/view/template/page/quickstart.php +++ b/view/template/page/quickstart.php @@ -10,9 +10,8 @@
  1. Installation
  2. Running LBRY
  3. -
  4. API Basics
  5. +
  6. The API
  7. Credits
  8. -
  9. Start Building
  10. Community & Issues
@@ -52,7 +51,7 @@

The first time you run the daemon, it must catch-up with most recent blockheaders. This can take several minutes.

-

3. API Basics

+

3. The API

When running, the LBRY daemon provides a JSON-RPC server running at https://localhost:5279/lbryapi.

@@ -62,57 +61,45 @@

To verify the LBRY daemon is running correctly and responding to requests, run:

-

- - curl --data "{ method: 'status' }" http://localhost:5279/lbryapi - -

-

- You should receive a response like: -

-

- - (will copy/paste once it works) - -

-

This makes it easy to interact with the LBRY API in the programming language of your choice.

+
curl --data "{ method: 'status' }" http://localhost:5279/lbryapi
+(add response when this works)
+

This makes it easy to interact with the LBRY API in the programming language of your choice. Here's another example:

+
curl --data "{ method: 'resolve_name', params: [{ name: "what"}] }" http://localhost:5279/lbryapi
+(add response when this works)
+

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!

+

View Full API Documentation

4. Getting Credits

-

Many actions, such as publishing or purchasing paid content, require credits.

+

Many actions, such as reserving a name or purchasing paid content, require credits.

To receive credits, first generate a wallet address:

-

- - curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
- I am a response -
-

+
curl --data "{ method: 'wallet_new_address' }" http://localhost:5279/lbryapi
+I am a response

Use this address to get credits in one of two ways:

-

4a) Get Credits For Free

+

4a) Receive Free Credits

- All developers are eligible to receive free credits. - Go here to claim them. + All developers with a valid GitHub account are eligible to receive free credits.

+ Claim Your Free Credits

4b) Purchase Credits

- Credits can be bought on a variety of exchanges. - Go here to see a full list. - After purchasing them, send them to the address generated above. + Credits can be bought on a variety of exchanges. + After purchasing, send them to the address generated above.

-

6. Community & Issues

+

5. Community & Issues

- Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (this is not a default channel). + Join our Slack Channel to interact with LBRY developers and other community members. Please visit the #dev room (note: this is not a default channel).

- Visit our GitHub to view the source code or report issues. + Visit our GitHub page to view the source code or report issues.

diff --git a/view/template/report/dmca.php b/view/template/report/dmca.php index f406e38c..6011fc01 100644 --- a/view/template/report/dmca.php +++ b/view/template/report/dmca.php @@ -10,7 +10,7 @@
- + 'name',