File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ import {getElemsByClass, getElemById} from './ts/dom-utils';
44import { widgetFactory } from './ts/widget' ;
55import { 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 {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments