Skip to content

Commit 67d6dd6

Browse files
committed
Frontend: introducing password/cookie-based authentication
1 parent 398f11d commit 67d6dd6

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
1-
import Cookies from 'js-cookie';
1+
import {Cookies} from 'typescript-cookies'
2+
3+
const cookies = new Cookies({
4+
path: '/',
5+
secure: true,
6+
samesite: 'none',
7+
})
28

39
/**
4-
* Redirects the user to main learn site if not AdaCore employee
10+
* Redirects the user to main learn site if not authenticated
511
*/
612
export function sandboxRedirect(): void {
713
/* istanbul ignore next */
8-
if (!Cookies.get('AdaCore_staff')) {
9-
const msg = 'You have reached learn-sandbox, the learn testing site. ' +
10-
'This is reserved for testers only. You will be directed to the main ' +
11-
'learn.adacore.com site after pressing OK.';
12-
alert(msg);
13-
window.location.href = 'http://learn.adacore.com';
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+
}
1432
}
1533
}

0 commit comments

Comments
 (0)