From 20eb2affde88d01830f86b5b824aaa4e89748a25 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 30 May 2025 13:37:50 +0200 Subject: [PATCH 1/4] Frontend: reintroducing site redirection for "staging" version --- frontend/src/index.ts | 10 ++++++++++ frontend/src/ts/staging.ts | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 frontend/src/ts/staging.ts diff --git a/frontend/src/index.ts b/frontend/src/index.ts index d7d3257f4..30b5a1fb0 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -4,6 +4,10 @@ import {getElemsByClass, getElemById} from './ts/dom-utils'; import {widgetFactory} from './ts/widget'; import {scrollTop} from './ts/scrolltop'; +// #if STAGING +import {stagingRedirect} from './ts/staging'; +// #endif + /** * Entrypoint * The main entrypoint for the application @@ -17,6 +21,12 @@ function entrypoint(): void { // register scroll to top btn functionality const btn = getElemById('scrollToTopBtn'); scrollTop(btn as HTMLButtonElement); + + // #if STAGING + // This is used to redirect non AdaCore staff to the main site if + // the staging site is accidentally reached + stagingRedirect(); + // #endif } (function(): void { diff --git a/frontend/src/ts/staging.ts b/frontend/src/ts/staging.ts new file mode 100644 index 000000000..62f461d99 --- /dev/null +++ b/frontend/src/ts/staging.ts @@ -0,0 +1,17 @@ +import Cookies from 'js-cookie'; + +/** + * Redirects the user to main learn site if not AdaCore employee + * + * @export + */ +export function stagingRedirect(): void { + /* istanbul ignore next */ + if (!Cookies.get('AdaCore_staff')) { + const msg = 'You have reached learn-staging, 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'; + } +} From 2752b1d4a8691ee7aa404b4d4347248189ec1379 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 30 May 2025 18:06:23 +0200 Subject: [PATCH 2/4] Editorial change: renaming "staging" => "sandbox" --- frontend/src/index.ts | 8 ++++---- frontend/src/ts/{staging.ts => sandbox-redirect.ts} | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename frontend/src/ts/{staging.ts => sandbox-redirect.ts} (79%) diff --git a/frontend/src/index.ts b/frontend/src/index.ts index 30b5a1fb0..546578c70 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -4,8 +4,8 @@ import {getElemsByClass, getElemById} from './ts/dom-utils'; import {widgetFactory} from './ts/widget'; import {scrollTop} from './ts/scrolltop'; -// #if STAGING -import {stagingRedirect} from './ts/staging'; +// #if SANDBOX +import {sandboxRedirect} from './ts/sandbox-redirect'; // #endif /** @@ -22,10 +22,10 @@ function entrypoint(): void { const btn = getElemById('scrollToTopBtn'); scrollTop(btn as HTMLButtonElement); - // #if STAGING + // #if SANDBOX // This is used to redirect non AdaCore staff to the main site if // the staging site is accidentally reached - stagingRedirect(); + sandboxRedirect(); // #endif } diff --git a/frontend/src/ts/staging.ts b/frontend/src/ts/sandbox-redirect.ts similarity index 79% rename from frontend/src/ts/staging.ts rename to frontend/src/ts/sandbox-redirect.ts index 62f461d99..08ff51e3c 100644 --- a/frontend/src/ts/staging.ts +++ b/frontend/src/ts/sandbox-redirect.ts @@ -5,10 +5,10 @@ import Cookies from 'js-cookie'; * * @export */ -export function stagingRedirect(): void { +export function sandboxRedirect(): void { /* istanbul ignore next */ if (!Cookies.get('AdaCore_staff')) { - const msg = 'You have reached learn-staging, the learn testing site. ' + + 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); From 398f11d7e081fe664f6f317fad678df93bad7f9c Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 30 May 2025 18:07:09 +0200 Subject: [PATCH 3/4] Fix warning: remove wrong function documentation --- frontend/src/ts/sandbox-redirect.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/ts/sandbox-redirect.ts b/frontend/src/ts/sandbox-redirect.ts index 08ff51e3c..69096f5dd 100644 --- a/frontend/src/ts/sandbox-redirect.ts +++ b/frontend/src/ts/sandbox-redirect.ts @@ -2,8 +2,6 @@ import Cookies from 'js-cookie'; /** * Redirects the user to main learn site if not AdaCore employee - * - * @export */ export function sandboxRedirect(): void { /* istanbul ignore next */ From 67d6dd63f2dc05758384b4cf0ff95feeb10af0d6 Mon Sep 17 00:00:00 2001 From: gusthoff Date: Fri, 30 May 2025 18:08:29 +0200 Subject: [PATCH 4/4] Frontend: introducing password/cookie-based authentication --- frontend/src/ts/sandbox-redirect.ts | 34 ++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/frontend/src/ts/sandbox-redirect.ts b/frontend/src/ts/sandbox-redirect.ts index 69096f5dd..a36f19013 100644 --- a/frontend/src/ts/sandbox-redirect.ts +++ b/frontend/src/ts/sandbox-redirect.ts @@ -1,15 +1,33 @@ -import Cookies from 'js-cookie'; +import {Cookies} from 'typescript-cookies' + +const cookies = new Cookies({ + path: '/', + secure: true, + samesite: 'none', +}) /** - * Redirects the user to main learn site if not AdaCore employee + * Redirects the user to main learn site if not authenticated */ export function sandboxRedirect(): void { /* istanbul ignore next */ - if (!Cookies.get('AdaCore_staff')) { - 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'; + 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}); + } } }