mirror of
https://github.com/LightZirconite/Microsoft-Rewards-Bot.git
synced 2026-01-24 23:01:01 +00:00
Refactor: Simplify recovery email handling and validation; update documentation for clarity
This commit is contained in:
@@ -379,27 +379,20 @@ export function loadAccounts(): Account[] {
|
||||
}
|
||||
a.email = String(a.email).trim()
|
||||
a.password = String(a.password)
|
||||
const recoveryRequired = a.recoveryRequired !== false
|
||||
a.recoveryRequired = recoveryRequired
|
||||
|
||||
if (recoveryRequired) {
|
||||
if (typeof a.recoveryEmail !== 'string') {
|
||||
throw new Error(`account ${a.email || '<unknown>'} must include a recoveryEmail string (or set "recoveryRequired": false)`)
|
||||
}
|
||||
a.recoveryEmail = String(a.recoveryEmail).trim()
|
||||
if (!a.recoveryEmail || !/@/.test(a.recoveryEmail)) {
|
||||
throw new Error(`account ${a.email} recoveryEmail must be a valid email address (got: "${a.recoveryEmail}") - set "recoveryRequired": false if not needed`)
|
||||
}
|
||||
} else {
|
||||
if (typeof a.recoveryEmail === 'string' && a.recoveryEmail.trim() !== '') {
|
||||
const trimmed = a.recoveryEmail.trim()
|
||||
// Simplified recovery email logic: if present and non-empty, validate it
|
||||
if (typeof a.recoveryEmail === 'string') {
|
||||
const trimmed = a.recoveryEmail.trim()
|
||||
if (trimmed !== '') {
|
||||
if (!/@/.test(trimmed)) {
|
||||
throw new Error(`account ${a.email} recoveryEmail must be a valid email address`)
|
||||
throw new Error(`account ${a.email} recoveryEmail must be a valid email address (got: "${trimmed}")`)
|
||||
}
|
||||
a.recoveryEmail = trimmed
|
||||
} else {
|
||||
a.recoveryEmail = undefined
|
||||
}
|
||||
} else {
|
||||
a.recoveryEmail = undefined
|
||||
}
|
||||
|
||||
if (!a.proxy || typeof a.proxy !== 'object') {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import chalk from 'chalk'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import chalk from 'chalk'
|
||||
import { Config } from '../interface/Config'
|
||||
import { Account } from '../interface/Account'
|
||||
import { Config } from '../interface/Config'
|
||||
import { log } from './Logger'
|
||||
|
||||
interface ValidationError {
|
||||
@@ -105,43 +105,22 @@ export class StartupValidator {
|
||||
)
|
||||
}
|
||||
|
||||
const recoveryRequired = account.recoveryRequired !== false
|
||||
if (recoveryRequired) {
|
||||
if (!account.recoveryEmail || typeof account.recoveryEmail !== 'string') {
|
||||
this.addError(
|
||||
'accounts',
|
||||
`${prefix}: Missing required field "recoveryEmail"`,
|
||||
'Add your recovery/backup email address. This is required for security checks unless you explicitly disable it.\nExample: "recoveryEmail": "backup@gmail.com"',
|
||||
'docs/accounts.md'
|
||||
)
|
||||
} else if (!/@/.test(account.recoveryEmail)) {
|
||||
// Simplified: only validate recovery email if provided
|
||||
if (account.recoveryEmail && typeof account.recoveryEmail === 'string' && account.recoveryEmail.trim() !== '') {
|
||||
if (!/@/.test(account.recoveryEmail)) {
|
||||
this.addError(
|
||||
'accounts',
|
||||
`${prefix}: Recovery email format is invalid`,
|
||||
'Recovery email must be a valid email address (e.g., backup@gmail.com)'
|
||||
)
|
||||
} else if (account.recoveryEmail.trim() === '') {
|
||||
this.addError(
|
||||
'accounts',
|
||||
`${prefix}: Recovery email cannot be empty`,
|
||||
'Provide the actual recovery email associated with this Microsoft account'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (!account.recoveryEmail || account.recoveryEmail.trim() === '') {
|
||||
this.addWarning(
|
||||
'accounts',
|
||||
`${prefix}: Recovery email checks disabled`,
|
||||
'The bot will skip recovery-email mismatch detection for this account. Re-enable by removing "recoveryRequired": false.',
|
||||
'docs/accounts.md'
|
||||
)
|
||||
} else if (!/@/.test(account.recoveryEmail)) {
|
||||
this.addError(
|
||||
'accounts',
|
||||
`${prefix}: Recovery email format is invalid`,
|
||||
'Recovery email must be a valid email address (e.g., backup@gmail.com)'
|
||||
)
|
||||
}
|
||||
this.addWarning(
|
||||
'accounts',
|
||||
`${prefix}: No recovery email configured`,
|
||||
'Recovery email is optional but recommended for security challenge verification',
|
||||
'docs/accounts.md'
|
||||
)
|
||||
}
|
||||
|
||||
// Optional but recommended: TOTP
|
||||
|
||||
Reference in New Issue
Block a user