forked from pangeo-data/pangeo-custom-jupyterhub-templates
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from 2i2c-org/utoronto-staging
Redirect utoronto home pages more selectively
- Loading branch information
Showing
7 changed files
with
34 additions
and
436 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
function redirectIfNeeded() { | ||
// Only redirect utoronto.2i2c.cloud, lets us keep staging at staging.utoronto.2i2c.cloud | ||
if (window.location.hostname === 'utoronto.2i2c.cloud') { | ||
// Let's give users an indication that something is happening | ||
document.write("Redirecting you to jupyter.utoronto.ca"); | ||
window.location.hostname = 'jupyter.utoronto.ca'; | ||
} | ||
// This code must be run *as early as possible*, as we care about redirecting the user | ||
// *somewhere* immediately. So this isn't wrapped in a window.onload or similar, but bare. | ||
// This code is also loaded directly in <head>, so it will block page load. | ||
const curUrl = new URL(document.location); | ||
// if next query param is presentm just do nothing | ||
const nextUrl = curUrl.searchParams.get('next'); | ||
// /hub/ being next should be treated same as no next present | ||
if (!nextUrl || nextUrl === "/hub/") { | ||
// The 'unified' home page for all the hubs is at https://datatools.utoronto.ca, | ||
// so anyone landing on the home page should just be redirected. | ||
window.location.replace("https://datatools.utoronto.ca"); | ||
} else { | ||
// The user has landed on this page, which means they are not actually logged in, | ||
// and need to login to continue to wherever they are going. So let's construct the | ||
// appropriate oauth_login URL for them to go to. | ||
let oauthLoginUrl = new URL(document.location); | ||
// Pass along all url parameters we got, just change from /login to /oauth_login | ||
oauthLoginUrl.pathname = "/oauth_login"; | ||
window.location.replace(oauthLoginUrl); | ||
} | ||
function setInterface(interfaceUrl) { | ||
let loginUrl = new URL($('#home').data('authenticator-login-url'), document.location.origin); | ||
loginUrl.searchParams.set('next', '/hub/user-redirect/' + interfaceUrl) | ||
$('#login-button').attr( | ||
'href', | ||
loginUrl.toString() | ||
); | ||
} | ||
$(function() { | ||
redirectIfNeeded(); | ||
// if next query param is presentm just do nothing | ||
const nextPresent = new URL(document.location).searchParams.get('next'); | ||
// /hub/ being next should be treated same as no next present | ||
if (!nextPresent || nextPresent === "/hub/") { | ||
setInterface($("input[name='interface']:checked").val()); | ||
|
||
$("input[name='interface']").change(function() { | ||
if (this.checked) { | ||
setInterface(this.value) | ||
} | ||
}); | ||
} | ||
|
||
}) |
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
Oops, something went wrong.