diff --git a/controller/Controller.class.php b/controller/Controller.class.php index f4cba28d..5a978a86 100644 --- a/controller/Controller.class.php +++ b/controller/Controller.class.php @@ -122,6 +122,7 @@ class Controller $router->any('/youtube/thanks', 'AcquisitionActions::executeThanks'); $router->any('/youtube/sub', 'AcquisitionActions::executeYouTubeSub'); $router->any('/youtube', 'AcquisitionActions::executeYT2'); + $router->post('/youtube/edit', 'AcquisitionActions::executeYoutubeEdit'); $router->post('/youtube/token', 'AcquisitionActions::executeYoutubeToken'); $router->any('/youtube/status/{token}', 'AcquisitionActions::executeYoutubeStatus'); $router->get('/verify/{token}', 'AcquisitionActions::executeVerify'); diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 403832e8..87424a46 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -57,28 +57,21 @@ class AcquisitionActions extends Actions return ['acquisition/youtube_status', ['token' => $token]]; } - public static function actionYoutubeToken(string $email, string $desired_lbry_channel_name, string $youtube_channel_id) + public static function actionYoutubeToken(string $desired_lbry_channel_name) { - $email_is_valid = static::email_verification($email); $desired_lbry_channel_name_is_valid = static::lbry_channel_verification($desired_lbry_channel_name); - $youtube_channel_id_is_valid = static::youtube_channel_verification($youtube_channel_id); + var_dump($desired_lbry_channel_name); + var_dump($desired_lbry_channel_name_is_valid); + //if ($desired_lbry_channel_name_is_valid) { + $token = LBRY::connectYoutube($desired_lbry_channel_name); + var_dump($token); + //} + } - if ($email_is_valid && $desired_lbry_channel_name_is_valid && $youtube_channel_id_is_valid) { - $token = LBRY::newYoutube($email, $youtube_channel_id, $desired_lbry_channel_name); - - if ($token['error'] === null) { - $url = "/youtube/status/" . $token['data']['status_token']; - Controller::redirect($url); - } else { - $url = "/yt2?error=true&error_message=" . $token['error']; - Controller::redirect($url); - } - } else { - $url = "/yt2?error=true"; - Controller::redirect($url); - } + public static function executeYoutubeEdit(){ + return ['acquisition/youtube_edit']; } protected static function email_verification($email) diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php index 255de6a1..9bf312d9 100644 --- a/lib/thirdparty/LBRY.class.php +++ b/lib/thirdparty/LBRY.class.php @@ -36,6 +36,11 @@ class LBRY return Curl::post(static::getApiUrl('/yt/new'), ['email' => $email, 'youtube_channel_id' => $channel_id,'desired_lbry_channel_name' => $channel_name], ['json_response' => true]); } + public static function connectYoutube($channel_name) + { + $type = 'sync'; + return Curl::post(static::getApiUrl('/yt/connect'), ['desired_lbry_channel_name' => $channel_name, 'type' => $type], ['json_response' => true]); + } // Check the sync status public static function statusYoutube($status_token) { @@ -45,4 +50,8 @@ class LBRY public static function youtubeReward(){ return CurlWithCache::post(static::getApiUrl('/yt/rewards'),[], ['cache' => 3600, 'json_response' => true ]); } + + public static function editYouTube($status_token, $channel_name, $email, $sync_consent){ + return Curl::post(static::getApiUrl("/yt/update"),['status_token' => $status_token, 'new_email' => $email, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent], ['json_response' => true]); + } } diff --git a/view/template/acquisition/youtube_edit.php b/view/template/acquisition/youtube_edit.php new file mode 100644 index 00000000..d0464218 --- /dev/null +++ b/view/template/acquisition/youtube_edit.php @@ -0,0 +1,10 @@ + false]) ?> - + - + + + + + + Channel is invalid or blank + LBRY channel name: + + Email is invalid or blank + - LBRY channel name: + Email: - - Youtube Sync status: - - > - Don't sync yet - - > - Sync my channel - - - disabled="disabled"> - Being synced - - - disabled="disabled"> - Syncing completed - - - + Expected Reward: LBC - Edit my preferences + Number Of Subscriber: + + + + Number Of Video: + + + + You must agreed to sync to continue + + + I want to sync my content to the LBRY network and agree to the "terms" + + + Edit my preferences \ No newline at end of file diff --git a/view/template/acquisition/youtube_token.php b/view/template/acquisition/youtube_token.php index 688e4294..32a99b90 100644 --- a/view/template/acquisition/youtube_token.php +++ b/view/template/acquisition/youtube_token.php @@ -1,3 +1,8 @@ diff --git a/view/template/acquisition/yt2.php b/view/template/acquisition/yt2.php index 5ec69e78..d619aee6 100644 --- a/view/template/acquisition/yt2.php +++ b/view/template/acquisition/yt2.php @@ -4,6 +4,7 @@ Response::addJsAsset('/js/yt2/TweenMax.min.js'); Response::addJsAsset('/js/yt2/ScrollToPlugin.min.js'); Response::addJsAsset('/js/yt2/app.js'); Response::addJsAsset('/js/yt2/FormValidation.js'); +Response::addJsAsset('/js/yt2/SyncStatus.js'); $reward = LBRY::youtubeReward(); ?> @@ -59,21 +60,16 @@ $reward = LBRY::youtubeReward(); endif;?> Own your identity. For real this time. + + + LBRY channel name is not valid or blank + @ - Email is not valid or blank - - - - Youtube id is not valid or blank - - - - diff --git a/web/js/yt2/FormValidation.js b/web/js/yt2/FormValidation.js index 0ab700d9..7aed2df7 100644 --- a/web/js/yt2/FormValidation.js +++ b/web/js/yt2/FormValidation.js @@ -1,15 +1,46 @@ +function submitEditForm(){ + $("#youtube_settings").submit(function (event) { + + // get value from id + var lbry_channel_name = $.trim($('#channel-name').val()); + var email = $.trim($('#email').val()); + + // Hide the error message + $('#channel-name-error').hide(); + $('#email-error').hide(); + + // If the channel name is invalid or blank stop the post request + if(!validateLBRYName(lbry_channel_name) || lbry_channel_name === ''){ + $('#lbry_channel_name').addClass('error_form'); + $('#channel-name-error').show(); + event.preventDefault(); + } + + if(!validateEmail(email) || email === ''){ + $('#email').addClass('error_form'); + $('#email-error').show(); + event.preventDefault(); + } + + // If the checkbox is not check stop the post request + if(!$('#sync-consent').prop('checked')){ + $('#sync-consent').addClass('error_form'); + $('#sync-consent-error').show(); + event.preventDefault(); + } + localStorage.setItem("status_token", $.trim($('#status_token').val())); + localStorage.setItem("lbry_channel_name_sync", $.trim($('#channel-name').val())); + }); +} + function submitDetailsForm() { $("#youtube_claim").submit(function (event) { // get value from id var lbry_channel_name = $.trim($('#lbry_channel_name').val()); - var email = $.trim($('#email').val()); - var youtube_url = $.trim($('#youtube_url').val()); // Make sure that the error message are hidden before trying to validate value $('#lbry_error').hide(); - $('#email_error').hide(); - $('#youtube_url_error').hide(); // If the lbry name is invalid or blank stop the post request if(!validateLBRYName(lbry_channel_name) || lbry_channel_name === '') { @@ -17,32 +48,6 @@ function submitDetailsForm() { $('#lbry_error').show(); event.preventDefault(); } - // Show the other field if the LBRY channel name field is validated once - else{ - // Check only if the two fields - if ($('#email').is(":visible") && $('#youtube_url').is(":visible")) { - // If the email is invalid or blank stop the post request - if (!validateEmail(email) || email === '') { - $('#email').addClass('error_form'); - $('#email_error').show(); - event.preventDefault(); - } - - // If the youtube url is invalid or blank stop the post request - if (!validateYoutubeChannelUrl(youtube_url) || youtube_url === '') { - $('#youtube_url').addClass('error_form'); - $('#youtube_url_error').show(); - event.preventDefault(); - } - } - else{ - event.preventDefault(); - } - $('#youtube_url').show(); - $('#email').show(); - } - - }); } diff --git a/web/js/yt2/SyncStatus.js b/web/js/yt2/SyncStatus.js new file mode 100644 index 00000000..625f82c9 --- /dev/null +++ b/web/js/yt2/SyncStatus.js @@ -0,0 +1,10 @@ +$(document).ready(function () { + var status_token = localStorage.getItem("status_token"); + var lbry_channel_name_sync = localStorage.getItem("lbry_channel_name_sync"); + + if (status_token || lbry_channel_name_sync){ + var url = "/youtube/status/" + status_token; + $("#sync-status").show(); + $("#sync-status").html("To see the sync status of channel: " +lbry_channel_name_sync + " " + "Please" + ' Click Here '); + } +}); \ No newline at end of file