Skip to content

Commit 81dafed

Browse files
authored
Revive former authenticate function (#327)
The View registrants functionality still needs to authenticate to W3C servers for now. The feature is available through the command-line but import statements were no longer correct.
1 parent 17817a0 commit 81dafed

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tools/node/view-registrants.mjs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
11
import puppeteer from 'puppeteer';
22
import { validateSession } from '../common/validate.mjs';
3-
import { authenticate } from './lib/calendar.mjs';
43
import { getEnvKey } from '../common/envkeys.mjs';
54
import { exportProjectToGitHub } from '../common/project.mjs';
65
import { parseSessionMeetings } from '../common/meetings.mjs';
76

7+
8+
/**
9+
* Login to W3C server.
10+
*
11+
* The function throws if login fails.
12+
*/
13+
export async function authenticate(page, login, password, redirectUrl) {
14+
const url = await page.evaluate(() => window.location.href);
15+
if (!url.endsWith('/login')) {
16+
return;
17+
}
18+
19+
const usernameInput = await page.waitForSelector('input#username');
20+
await usernameInput.type(login);
21+
22+
const passwordInput = await page.waitForSelector('input#password');
23+
await passwordInput.type(password);
24+
25+
const submitButton = await page.waitForSelector('button[type=submit]');
26+
await submitButton.click();
27+
28+
await page.waitForNavigation();
29+
const newUrl = await page.evaluate(() => window.location.href);
30+
if (newUrl !== redirectUrl) {
31+
throw new Error('Could not login. Invalid credentials?');
32+
}
33+
}
34+
835
export default async function (project, number, options) {
936
const meeting = project.metadata.meeting.toLowerCase().replace(/\s+/g, '');
1037
const registrantsUrl = options?.url ??

0 commit comments

Comments
 (0)