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 @@