HTTPS redirect cookie

This commit is contained in:
Steven Hugg 2019-05-18 18:33:38 -04:00
parent 433e982424
commit 2e448e9ae8
2 changed files with 31 additions and 2 deletions

View File

@ -287,7 +287,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
</div>
</div>
<div id="videoPreviewModal" class="modal fade">
<div class="modal-dialog modal-md" role="document">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Video Preview - Right-click to save</h3>

View File

@ -387,7 +387,7 @@ function getCurrentEditorFilename() : string {
var githubService : GithubService;
function getCookie(name) {
function getCookie(name) : string {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
@ -1848,3 +1848,32 @@ function convertLegacyVCS(store) {
})
}
}
const useHTTPSCookieName = "__use_https";
function shouldRedirectHTTPS() {
// cookie set?
if (getCookie(useHTTPSCookieName)) {
return true;
}
// is this our first time here? if so, set a 10yr cookie
if (hasLocalStorage && !localStorage.getItem("__lastplatform")) {
document.cookie = useHTTPSCookieName + "=1;domain=8bitworkshop.com;path=/;max-age=315360000";
return true;
}
// we can't redirect, might still have HTTP files
return false;
}
function redirectToHTTPS() {
if (window.location.protocol == 'http:' && window.location.host == '8bitworkshop.com') {
if (shouldRedirectHTTPS()) {
window.location.replace(window.location.href.replace(/^http:/, 'https:'));
} else {
$("#http_warning").show(); // TODO
}
}
}
// redirect to HTTPS after script loads?
redirectToHTTPS();