Skip to content

Commit bb1bbd2

Browse files
committed
Reintroduce the authenticate method in the list-chairs CLI
1 parent 81dafed commit bb1bbd2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tools/list-chairs.mjs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,40 @@
1010
import { getEnvKey } from './common/envkeys.mjs';
1111
import { loadProject } from './node/lib/project.mjs'
1212
import { validateGrid } from './common/validate.mjs';
13-
import { authenticate } from './node/lib/calendar.mjs';
1413
import checkRegistrants from './node/lib/check-registrants.mjs';
1514
import puppeteer from 'puppeteer';
1615

1716
function sleep(ms) {
1817
return new Promise(resolve => setTimeout(resolve, ms, 'slept'));
1918
}
2019

20+
/**
21+
* Login to W3C server.
22+
*
23+
* The function throws if login fails.
24+
*/
25+
export async function authenticate(page, login, password, redirectUrl) {
26+
const url = await page.evaluate(() => window.location.href);
27+
if (!url.endsWith('/login')) {
28+
return;
29+
}
30+
31+
const usernameInput = await page.waitForSelector('input#username');
32+
await usernameInput.type(login);
33+
34+
const passwordInput = await page.waitForSelector('input#password');
35+
await passwordInput.type(password);
36+
37+
const submitButton = await page.waitForSelector('button[type=submit]');
38+
await submitButton.click();
39+
40+
await page.waitForNavigation();
41+
const newUrl = await page.evaluate(() => window.location.href);
42+
if (newUrl !== redirectUrl) {
43+
throw new Error('Could not login. Invalid credentials?');
44+
}
45+
}
46+
2147
async function main(format) {
2248
format = format ?? 'text';
2349

0 commit comments

Comments
 (0)