Skip to content

Commit cd5af6c

Browse files
authored
Merge pull request #1226 from gusthoff/topic/infrastructure/yarn/updates/20250530/sandbox_redict
Frontend: introducing password/cookie-based authentication for learn-sandbox
2 parents 60a3c3d + 67d6dd6 commit cd5af6c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

frontend/src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import {getElemsByClass, getElemById} from './ts/dom-utils';
44
import {widgetFactory} from './ts/widget';
55
import {scrollTop} from './ts/scrolltop';
66

7+
// #if SANDBOX
8+
import {sandboxRedirect} from './ts/sandbox-redirect';
9+
// #endif
10+
711
/**
812
* Entrypoint
913
* The main entrypoint for the application
@@ -17,6 +21,12 @@ function entrypoint(): void {
1721
// register scroll to top btn functionality
1822
const btn = getElemById('scrollToTopBtn');
1923
scrollTop(btn as HTMLButtonElement);
24+
25+
// #if SANDBOX
26+
// This is used to redirect non AdaCore staff to the main site if
27+
// the staging site is accidentally reached
28+
sandboxRedirect();
29+
// #endif
2030
}
2131

2232
(function(): void {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Cookies} from 'typescript-cookies'
2+
3+
const cookies = new Cookies({
4+
path: '/',
5+
secure: true,
6+
samesite: 'none',
7+
})
8+
9+
/**
10+
* Redirects the user to main learn site if not authenticated
11+
*/
12+
export function sandboxRedirect(): void {
13+
/* istanbul ignore next */
14+
const cookieName = "Learn_Sandbox_Authenticated";
15+
const cookieValue = cookies.get(cookieName) as string;
16+
const cookieReferenceValue = "true";
17+
18+
if (cookieValue != cookieReferenceValue) {
19+
const passw = prompt("Enter site password:")
20+
21+
if (passw != "Ada") {
22+
const msg = 'You have reached learn-sandbox, the learn testing site. ' +
23+
'This is reserved for testers only. You will be directed to the main ' +
24+
'learn.adacore.com site after pressing OK.';
25+
alert(msg);
26+
window.location.href = 'http://learn.adacore.com';
27+
}
28+
else
29+
{
30+
cookies.set(cookieName, cookieReferenceValue, {expires: 3650});
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)