fix(codechef): fast bad-credentials detection and prompt prefix
Replace `wait_for_url` with `wait_for_function` in both login and submit `login_action` callbacks, racing URL change against `div.error` appearing — same pattern as AtCoder and Codeforces. Also prefix credential prompts with `[cp.nvim]:` for consistency.
This commit is contained in:
parent
0ad7a9614f
commit
f63b72788c
2 changed files with 12 additions and 8 deletions
|
|
@ -15,13 +15,13 @@ local STATUS_MESSAGES = {
|
|||
---@param platform string
|
||||
---@param display string
|
||||
local function prompt_and_login(platform, display)
|
||||
vim.ui.input({ prompt = display .. ' username: ' }, function(username)
|
||||
vim.ui.input({ prompt = '[cp.nvim]: ' .. display .. ' username: ' }, function(username)
|
||||
if not username or username == '' then
|
||||
logger.log('Cancelled', { level = vim.log.levels.WARN })
|
||||
return
|
||||
end
|
||||
vim.fn.inputsave()
|
||||
local password = vim.fn.inputsecret(display .. ' password: ')
|
||||
local password = vim.fn.inputsecret('[cp.nvim]: ' .. display .. ' password: ')
|
||||
vim.fn.inputrestore()
|
||||
if not password or password == '' then
|
||||
logger.log('Cancelled', { level = vim.log.levels.WARN })
|
||||
|
|
|
|||
|
|
@ -84,9 +84,11 @@ def _login_headless_codechef(credentials: dict[str, str]) -> LoginResult:
|
|||
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
||||
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
||||
page.locator("input.cc-login-btn").click()
|
||||
try:
|
||||
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
||||
except Exception:
|
||||
page.wait_for_function(
|
||||
"() => !window.location.href.includes('/login') || !!document.querySelector('div.error')",
|
||||
timeout=BROWSER_NAV_TIMEOUT,
|
||||
)
|
||||
if "/login" in page.url:
|
||||
login_error = "bad_credentials"
|
||||
return
|
||||
except Exception as e:
|
||||
|
|
@ -163,9 +165,11 @@ def _submit_headless_codechef(
|
|||
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
||||
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
||||
page.locator("input.cc-login-btn").click()
|
||||
try:
|
||||
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
||||
except Exception:
|
||||
page.wait_for_function(
|
||||
"() => !window.location.href.includes('/login') || !!document.querySelector('div.error')",
|
||||
timeout=BROWSER_NAV_TIMEOUT,
|
||||
)
|
||||
if "/login" in page.url:
|
||||
login_error = "bad_credentials"
|
||||
return
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue