Repository navigation
Add site login with TJUPT password and two-step code - #23
Merged
Merged
Conversation
Add the auth.login_effectful capability and SessionLoginer port, and a `ptctl site login --credential-bundle-stdin [--session-days N] SITE` command that reads site_username, site_password, and an optional site_totp from one strict stdin bundle and writes only the new session cookie to a pipe or owner-only stdout. TJUPT posts the login form once with no retry, recognizes the two-step and failed-login pages (including the site's remaining-attempts count), clears the response body that echoes the password, and keeps the issued access_token cookie only after one verifying mybonus.php read names the same account. httpguard gains PostLoginFormOnce, which captures only allowlisted live Set-Cookie values behind a redacting SessionCookie. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Until now a TJUPT session cookie had to be copied out of a browser by hand. This adds a full login flow so ptctl can issue its own session cookie from the account password and, for accounts with two-step verification, the current one-time code.
How it works
auth.login_effectfulcapability andsite.SessionLoginerport (LoginConfig+Login),site.LoginCredentials(redacting, validated username/password/optional 4–10 digit code), andsite.LoginErrorwith fixed stop reasons.PostLoginFormOncesends one strict HTTP/1.1 form POST with no cookie, redirect following, or retry, and captures only allowlisted liveSet-Cookievalues behind a redactingSessionCookie(deleted/expired values ignored; conflicting values fail closed).NewSessionCookiebuilds one for test doubles.takelogin.php(username,password,logoutdays, plusverify_codewhen a code is given). Recognizes theverifyformtwo-step page and the failed-login page, including TJUPT's "你还有 N 次尝试机会" count. The response body is cleared after classification because the two-step page echoes the password in a hidden field. An issuedaccess_tokenis kept only after a 2 s pause and onemybonus.phpread that is authenticated as the same username. Declared only on the default origin.ptctl site login --credential-bundle-stdin [--session-days N] SITE. Usage, session length, and stdout safety are checked before stdin is read. Stdout must be a pipe or an owner-only file (a terminal, device, or group/other-readable file is refused). Only the cookie goes to stdout; a one-line summary goes to stderr.Deliberate public changes
auth.login_effectful;ptctl site listnow reports 9 capabilities for tjupt (was 8), andsite capabilities tjuptlists it last.site login, with usage and safety lines inptctl help.site login stopped: <reason>with reasonslogin_credentials_rejected,login_two_factor_required,login_two_factor_rejected,login_response_unrecognized,login_session_unverified, andlogin_request_failed, optionally suffixed with(the site reports N login attempts left before it blocks this IP);site login failed[: <fixed cause>],site login canceled,site login timed out.ptctl.credentials/v1bundles forsite logintakesite_username,site_password, and optionalsite_totp. Existing bundles are unchanged; the shared decoder now supports optional fields.Verification
gofmt,go vet ./...,go test -race ./..., andgo build -trimpath ./cmd/ptctlpass locally.sitetestconformance suite now checks the login config and a canceled-context login.login_two_factor_required (the site reports 10 login attempts left before it blocks this IP).site login succeeded: site=tjupt username=<account> session_expires=<+7 days> requests=2. The cookie went to a 0600 file.site status(authenticated, same username) andsite account(full snapshot).🤖 Generated with Claude Code