1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-21 23:30:58 +00:00

switch to HTTPS menu option

This commit is contained in:
Steven Hugg 2019-05-25 23:15:25 -04:00
parent decccdf0d7
commit 89c608dc2c
4 changed files with 25 additions and 3 deletions

View File

@ -63,6 +63,7 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
<hr>
<li><a class="dropdown-item" href="#" id="item_addfile_include">Add Include File...</a></li>
<li><a class="dropdown-item" href="#" id="item_addfile_link">Add Linked File...</a></li>
<li><a class="dropdown-item" href="#" id="item_switch_https" style="display:none">Switch to HTTPS...</a></li>
</ul>
</li>
<li class="dropdown dropdown-submenu">

@ -1 +1 @@
Subproject commit 5e79821e85a9e4dda78973456ed9f8a04991093c
Subproject commit 53470410c34d2738a9f52e65bf8ffe1eabbef19b

View File

@ -2,6 +2,12 @@
"name": "8bitworkshop",
"version": "3.4.0",
"author": "Steven Hugg",
"description": "A programming IDE for retro hardware.",
"repository": {
"type": "git",
"url": "https://github.com/sehugg/8bitworkshop/"
},
"license": "GPLv3 and others, see README",
"dependencies": {},
"devDependencies": {
"@types/bootbox": "^4.4.36",

View File

@ -1910,6 +1910,10 @@ function convertLegacyVCS(store) {
const useHTTPSCookieName = "__use_https";
function setHTTPSCookie(val : number) {
document.cookie = useHTTPSCookieName + "=" + val + ";domain=8bitworkshop.com;path=/;max-age=315360000";
}
function shouldRedirectHTTPS() : boolean {
// cookie set? either true or false
var shouldRedir = getCookie(useHTTPSCookieName);
@ -1918,16 +1922,27 @@ function shouldRedirectHTTPS() : boolean {
}
// set a 10yr cookie, value depends on if it's our first time here
var val = hasLocalStorage && !localStorage.getItem("__lastplatform") ? 1 : 0;
document.cookie = useHTTPSCookieName + "=" + val + ";domain=8bitworkshop.com;path=/;max-age=315360000";
setHTTPSCookie(val);
return !!val;
}
function _switchToHTTPS() {
bootbox.confirm('<p>Do you want to force the browser to use HTTPS from now on?</p>'+
'<p>WARNING: This will make all of your local files unavailable, so you should "Download All Changes" first for each platform where you have done work.</p>'+
'<p>You can go back to HTTP by setting the "'+useHTTPSCookieName+'" cookie to 0.</p>', (ok) => {
if (ok) {
setHTTPSCookie(1);
redirectToHTTPS();
}
});
}
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
$("#item_switch_https").click(_switchToHTTPS).show();
}
}
}