Skip to content

Commit 130ddc0

Browse files
committed
Add page for testing new community service
1 parent b20bf75 commit 130ddc0

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

_config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,7 @@ exclude:
113113
- README.md
114114
- CNAME
115115
- vendor
116+
117+
include:
118+
- experimental/test-login.html
119+
- experimental/test-login.js

experimental/test-login.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<title>Test Page</title>
7+
<script src="test-login.js" async="true"></script>
8+
</head>
9+
<body>
10+
<noscript>You need to enable JavaScript to run this app.</noscript>
11+
<div id="root"></div>
12+
</body>
13+
</html>

experimental/test-login.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
console.log('Starting test-login.js');
2+
3+
const rootDiv = document.getElementById('root');
4+
5+
if (!rootDiv) {
6+
throw new Error('Root div not found');
7+
}
8+
9+
var cookieMap = {};
10+
11+
document.cookie
12+
.split(';')
13+
.map(function (part) {
14+
return part.trim().split('=');
15+
})
16+
.forEach(function (pair) {
17+
cookieMap[pair[0]] = decodeURIComponent(pair[1]);
18+
});
19+
20+
function htmlEncode(text) {
21+
const tempDiv = document.createElement('div');
22+
tempDiv.innerText = text;
23+
return tempDiv.innerHTML;
24+
}
25+
26+
var loggedInUser = (cookieMap['rscommunity-logged-in-user'] || '').trim();
27+
28+
var serviceUrl = '';
29+
if (document.location.hostname.toUpperCase() !== 'LOCALHOST') {
30+
serviceUrl = 'https://service.rushstack.io/';
31+
}
32+
var returnUrlQuery = 'returnUrl=' + encodeURIComponent(document.location.pathname);
33+
34+
if (loggedInUser) {
35+
// prettier-ignore
36+
rootDiv.innerHTML = 'You are logged in as <b>' + htmlEncode(loggedInUser) + '</b>.'
37+
+ '<p>'
38+
+ '<a href="' + serviceUrl + '/logout?' + returnUrlQuery + '">'
39+
+ 'LOG OUT'
40+
+ '</a>';
41+
} else {
42+
// prettier-ignore
43+
rootDiv.innerHTML = 'You are not logged in'
44+
+ '<p>'
45+
+ '<a href="' + serviceUrl + '/login?' + returnUrlQuery + '">'
46+
+ 'LOG IN'
47+
+ '</a>';
48+
}

0 commit comments

Comments
 (0)