- 新增直播评论/上下文/礼物等 API 与回放组件 - 主播开播、云端推流配置与 streamer 校验 - 依赖与 Mongo 集合/种子更新 - 需求与调研文档补充 Made-with: Cursor
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
/**
|
||
* 重置指定手机号的登录密码(userAuths.credential)
|
||
* 用法:pnpm exec tsx scripts/set-user-password.ts [手机号] [新密码]
|
||
* 默认:15880802661 key123456
|
||
*/
|
||
|
||
import { config } from "dotenv"
|
||
import { resolve } from "path"
|
||
|
||
config({ path: resolve(process.cwd(), ".env.local") })
|
||
|
||
import { MongoClient } from "mongodb"
|
||
import { hashPassword } from "../lib/auth-utils"
|
||
import { COLLECTIONS } from "../lib/db/mongo/collections"
|
||
|
||
const phone = process.argv[2]?.trim() || "15880802661"
|
||
const newPassword = process.argv[3] || "key123456"
|
||
|
||
async function main() {
|
||
const uri = process.env.MONGODB_URI
|
||
if (!uri) {
|
||
console.error("缺少 MONGODB_URI,请在 .env.local 配置")
|
||
process.exit(1)
|
||
}
|
||
const client = new MongoClient(uri)
|
||
await client.connect()
|
||
try {
|
||
const db = client.db("wanzhi_esports")
|
||
const auths = db.collection(COLLECTIONS.userAuths)
|
||
const hash = hashPassword(newPassword)
|
||
const r = await auths.updateOne(
|
||
{ authType: "phone", authId: phone },
|
||
{ $set: { credential: hash, updatedAt: new Date() } },
|
||
)
|
||
if (r.matchedCount === 0) {
|
||
console.error(`未找到手机号 ${phone} 的认证记录,请先注册或检查号码`)
|
||
process.exit(1)
|
||
}
|
||
console.log(`已更新 ${phone} 的登录密码(${newPassword.length} 位)`)
|
||
} finally {
|
||
await client.close()
|
||
}
|
||
}
|
||
|
||
main().catch((e) => {
|
||
console.error(e)
|
||
process.exit(1)
|
||
})
|