Last active
March 13, 2021 18:49
-
-
Save mckiersey/5d89f8f23c304c0a290d7ea044c63dbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// GET OWNER REQUEST: DESCRIPTION | |
// FUNCTION: Check whether viewer is also owner of profile | |
// 1) Send GET requst to BacKEnd route Owner with token & profile user id | |
// 2) If token is valid and profile user Id matches stored google id, corresponding to token then; | |
// 3) Show hidden element with ID = YouTubeForm | |
// 4) And insert 'Logged in' text into section with ID tag = 'SessionStatusText' | |
// 5) Else, insert 'Unlogged' text into section with ID tag = 'SessionStatusText' | |
try { | |
$.get('http://localhost:80/Owner', { | |
token: CookieToken, | |
ProfileId: user_id, | |
}).done(function (data) { | |
console.log('Server response :', data) | |
if (data == 'User is profile owner') { | |
$('#YouTubeForm').show() //show edit switch | |
document.getElementById('SessionStatusText').innerHTML = | |
"<span style='color: RGB(170, 204, 0);'>Logged in</span>"; | |
} else { | |
document.getElementById('SessionStatusText').innerHTML = | |
"<span style='color: red;'>Unlogged</span>"; | |
} | |
}); | |
} catch (err) { | |
console.log('Error: ' + err) | |
} | |
// POST ADD VIDEO REQUEST: DESCRIPTION | |
// FUNCTION: Allow proflie owner to add content to her own profile (and not someone else's) | |
// 1) Retrieve data submitted by user in 'YouTube Link' form | |
// 2) Send CookieToken, user profile id and submitted link to BackEnd route AddVideo | |
// 3) If token is valid and profile user Id matches stored google id, corresponding to token then; | |
// 4) Set the page 'location' = to the page 'location' => refresh the page. This automatic refresh upon success will then load the newly added video via the Video request, above | |
// 5) Else, send Alert | |
function AddVideo() { | |
console.log('Add video function executed') | |
link = document.getElementsByTagName("input")[0].value; // Retrieve submitted data | |
console.log('To post: User id cookie retrieved: ', user_id, 'with video: ', link) | |
try { // CLOSE THIS CLAUSE | |
$.post('http://localhost:80/AddVideo', { | |
token: CookieToken, | |
ProfileId: user_id, | |
VideoLink: link | |
}).done(function (data) { | |
console.log('Server response :', data) | |
if (data == 'New Video Added') { | |
window.location.href = window.location.href | |
// refresh page after successfully saving a new video | |
} else { | |
alert('Video not added, please try again', data) | |
} | |
}); | |
} catch (err) { | |
console.log('failed to post to backend') | |
console.log('Error: ' + err) | |
} | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment