|
10 | 10 | import { getEnvKey } from './common/envkeys.mjs'; |
11 | 11 | import { loadProject } from './node/lib/project.mjs' |
12 | 12 | import { validateGrid } from './common/validate.mjs'; |
13 | | -import { authenticate } from './node/lib/calendar.mjs'; |
14 | 13 | import checkRegistrants from './node/lib/check-registrants.mjs'; |
15 | 14 | import puppeteer from 'puppeteer'; |
16 | 15 |
|
17 | 16 | function sleep(ms) { |
18 | 17 | return new Promise(resolve => setTimeout(resolve, ms, 'slept')); |
19 | 18 | } |
20 | 19 |
|
| 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 | + |
21 | 47 | async function main(format) { |
22 | 48 | format = format ?? 'text'; |
23 | 49 |
|
|
0 commit comments