From fcafd053cb30368dca0e94a76fe31b3be6e74f86 Mon Sep 17 00:00:00 2001 From: Maxime St-Pierre Date: Fri, 9 Mar 2018 22:14:38 -0500 Subject: [PATCH] Remove sync consent check, add error message to youtube edit page and check that email is changed --- controller/action/AcquisitionActions.class.php | 17 +++++++++++++++++ lib/thirdparty/LBRY.class.php | 10 ++++++++-- view/template/acquisition/youtube_edit.php | 7 +++++-- view/template/acquisition/youtube_status.php | 5 ++++- view/template/acquisition/youtube_token.php | 1 - web/js/yt2/FormValidation.js | 6 ------ 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/controller/action/AcquisitionActions.class.php b/controller/action/AcquisitionActions.class.php index 5d426ae7..91837079 100644 --- a/controller/action/AcquisitionActions.class.php +++ b/controller/action/AcquisitionActions.class.php @@ -67,7 +67,24 @@ class AcquisitionActions extends Actions Controller::redirect($token['data']); } } + public static function actionYoutubeEdit($status_token, $channel_name, $email, $sync_consent, $current_value) + { + if($current_value['data']['email'] == $email) + { + $status = LBRY::editYoutube($status_token, $channel_name, null, $sync_consent); + } + else + { + $status = LBRY::editYoutube($status_token, $channel_name, $email, $sync_consent); + } + if($status['success'] == false){ + Controller::redirect("/youtube/status/". $status_token . "?error=true&error_message=" . $status['error']); + } + else{ + Controller::redirect("/youtube/status/" . $status_token); + } + } public static function executeYoutubeEdit(){ return ['acquisition/youtube_edit']; } diff --git a/lib/thirdparty/LBRY.class.php b/lib/thirdparty/LBRY.class.php index 64cea091..2e0abf10 100644 --- a/lib/thirdparty/LBRY.class.php +++ b/lib/thirdparty/LBRY.class.php @@ -29,7 +29,7 @@ class LBRY { return Curl::post(static::getApiUrl('/list/unsubscribe'), ['email' => $email], ['json_response' => true]); } - + public static function connectYoutube($channel_name) { $type = 'sync'; @@ -49,6 +49,12 @@ class LBRY 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]); + if ($email == null){ + return Curl::post(static::getApiUrl("/yt/update"),['status_token' => $status_token, 'new_preferred_channel' => $channel_name, 'sync_consent' => $sync_consent],['json_response' => true]); + } + else{ + + 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 index d0464218..92884925 100644 --- a/view/template/acquisition/youtube_edit.php +++ b/view/template/acquisition/youtube_edit.php @@ -4,7 +4,10 @@ $channel_name = $_POST['new_preferred_channel']; $email = $_POST['new_email']; $sync_consent = isset($_POST['sync_consent']); -LBRY::editYouTube($status_token, $channel_name, $email, $sync_consent); +$current_value = LBRY::statusYoutube($status_token); +if(!preg_match("/([@][1-z]+)/", $channel_name)){ + $channel_name = "@" . $channel_name; +} -Controller::redirect("/youtube/status/" . $status_token); +AcquisitionActions::actionYoutubeEdit($status_token, $channel_name, $email, $sync_consent, $current_value); diff --git a/view/template/acquisition/youtube_status.php b/view/template/acquisition/youtube_status.php index a978df2b..ce2ca724 100644 --- a/view/template/acquisition/youtube_status.php +++ b/view/template/acquisition/youtube_status.php @@ -33,6 +33,9 @@
+ " . "The following error occurred: ". $_GET['error_message'] . " For support please send an email to hello@lbry.io" . ""; + endif;?>
@@ -44,7 +47,7 @@
- I want to sync my content to the LBRY network and agree to the "terms" + >I want to sync my content to the LBRY network and agree to the "terms"
diff --git a/view/template/acquisition/youtube_token.php b/view/template/acquisition/youtube_token.php index 32a99b90..460ec13e 100644 --- a/view/template/acquisition/youtube_token.php +++ b/view/template/acquisition/youtube_token.php @@ -5,4 +5,3 @@ if(!preg_match("/([@][1-z]+)/", $desired_lbry_channel_name)){ $desired_lbry_channel_name = "@" . $desired_lbry_channel_name; } AcquisitionActions::actionYoutubeToken($desired_lbry_channel_name); - ?> diff --git a/web/js/yt2/FormValidation.js b/web/js/yt2/FormValidation.js index 7aed2df7..8cb59b2c 100644 --- a/web/js/yt2/FormValidation.js +++ b/web/js/yt2/FormValidation.js @@ -22,12 +22,6 @@ function submitEditForm(){ 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())); });