Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {getElemsByClass, getElemById} from './ts/dom-utils';
import {widgetFactory} from './ts/widget';
import {scrollTop} from './ts/scrolltop';

// #if SANDBOX
import {sandboxRedirect} from './ts/sandbox-redirect';
// #endif

/**
* Entrypoint
* The main entrypoint for the application
Expand All @@ -17,6 +21,12 @@ function entrypoint(): void {
// register scroll to top btn functionality
const btn = getElemById('scrollToTopBtn');
scrollTop(btn as HTMLButtonElement);

// #if SANDBOX
// This is used to redirect non AdaCore staff to the main site if
// the staging site is accidentally reached
sandboxRedirect();
// #endif
}

(function(): void {
Expand Down
33 changes: 33 additions & 0 deletions frontend/src/ts/sandbox-redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {Cookies} from 'typescript-cookies'

const cookies = new Cookies({
path: '/',
secure: true,
samesite: 'none',
})

/**
* Redirects the user to main learn site if not authenticated
*/
export function sandboxRedirect(): void {
/* istanbul ignore next */
const cookieName = "Learn_Sandbox_Authenticated";
const cookieValue = cookies.get(cookieName) as string;
const cookieReferenceValue = "true";

if (cookieValue != cookieReferenceValue) {
const passw = prompt("Enter site password:")

if (passw != "Ada") {
const msg = 'You have reached learn-sandbox, the learn testing site. ' +
'This is reserved for testers only. You will be directed to the main ' +
'learn.adacore.com site after pressing OK.';
alert(msg);
window.location.href = 'http://learn.adacore.com';
}
else
{
cookies.set(cookieName, cookieReferenceValue, {expires: 3650});
}
}
}
Loading