Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/browser/auth/methods/EmailLogin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type { Page } from 'patchright'
import type { MicrosoftRewardsBot } from '../../../index'
import { getErrorMessage, promptInput } from './LoginUtils'

export class EmailLogin {
private submitButton = 'button[type="submit"]'
private readonly maxManualSeconds = 120

constructor(private bot: MicrosoftRewardsBot) {}

Expand Down Expand Up @@ -58,6 +60,21 @@ export class EmailLogin {
return 'error'
}

// 密码为空时,提示手动输入
password = password?.trim() ? password : ''
if (!password) {
this.bot.logger.info(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'No password provided, awaiting manual input')
password = await promptInput({
question: `Enter your password (waiting ${this.maxManualSeconds}s): `,
timeoutSeconds: this.maxManualSeconds,
transform: input => input.trim()
}) ?? ''
if (!password) {
this.bot.logger.error(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'Password input timed out')
return 'error'
}
}

await this.bot.utils.wait(1000)
await page.fill(passwordInputSelector, '').catch(() => {})
await this.bot.utils.wait(500)
Expand All @@ -73,6 +90,13 @@ export class EmailLogin {
this.bot.logger.info(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', 'Password submitted')
}

await page.waitForLoadState('networkidle', { timeout: 5000 }).catch(() => {})
const errorMessage = await getErrorMessage(page)
if (errorMessage) {
this.bot.logger.warn(this.bot.isMobile, 'LOGIN-ENTER-PASSWORD', `Password error: ${errorMessage}`)
return 'error'
}

return 'ok'
} catch (error) {
this.bot.logger.error(
Expand Down