MCPcopy Index your code
hub / github.com/Tatamo/atcoder-cli / login

Method login

src/atcoder.ts:62–100  ·  view source on GitHub ↗

* ログイン処理します * あまりパスワード文字列を引き回したくないので、この中で標準入力からユーザー名とパスワードを尋ねる

()

Source from the content-addressed store, hash-verified

60 * あまりパスワード文字列を引き回したくないので、この中で標準入力からユーザー名とパスワードを尋ねる
61 */
62 async login(): Promise<boolean> {
63 if (await this.checkSession()) {
64 console.error("you logged-in already");
65 return true;
66 }
67 return this.session.transaction(async ()=> {
68 const {csrf_token} = await this.getCSRFToken();
69
70 // ユーザーネームとパスワードを入力させる
71 const inquirer = await import("inquirer");
72 const {username, password} = await inquirer.prompt([{
73 type: "input",
74 message: "username:",
75 name: "username"
76 }, {
77 type: "password",
78 message: "password:",
79 name: "password"
80 }]) as { username: string, password: string };
81
82 const response = await this.session.post(
83 AtCoder.login_url,
84 querystring.stringify({username, password, csrf_token}),
85 {
86 maxRedirects: 0,
87 validateStatus: (status) => (status >= 200 && status < 300) || status === 302,
88 }
89 )
90
91
92 // ログインページ以外にリダイレクトされていればログイン成功とみなす
93 const result = response.headers.location !== "/login";
94 if (result) {
95 // ログインに成功していた場合はセッション情報を保存する
96 await response.saveSession()
97 }
98 return result;
99 });
100 }
101
102 /**
103 * ログインページにアクセスしてCSRFトークンを取得

Callers 7

loginFunction · 0.80
contestFunction · 0.80
taskFunction · 0.80
tasksFunction · 0.80
formatFunction · 0.80
initFunction · 0.80
atcoder.tsFile · 0.80

Calls 5

checkSessionMethod · 0.95
getCSRFTokenMethod · 0.95
transactionMethod · 0.65
postMethod · 0.65
saveSessionMethod · 0.65

Tested by

no test coverage detected