base commit
This commit is contained in:
@@ -29,7 +29,22 @@ export async function issueEmailCode({ email, purpose, userId = null }) {
|
||||
await sendLoginCodeEmail({ to: email, code })
|
||||
}
|
||||
|
||||
function parseEnvBool(raw) {
|
||||
const v = String(raw ?? '').trim().toLowerCase()
|
||||
return v === 'true' || v === '1' || v === 'yes'
|
||||
}
|
||||
|
||||
/** Тестовые стенды: принять код из переменной DEFAULT_CODE без записи в БД. */
|
||||
export function isDefaultLoginCodeAccepted(codeInput) {
|
||||
if (!parseEnvBool(process.env.IS_DEFAULT_CODE_ENABLED)) return false
|
||||
const expected = String(process.env.DEFAULT_CODE ?? '').trim()
|
||||
if (!expected || expected.length < 4) return false
|
||||
return String(codeInput ?? '').trim() === expected
|
||||
}
|
||||
|
||||
export async function verifyEmailCode({ email, purpose, code, userId = null }) {
|
||||
if (purpose === 'login' && isDefaultLoginCodeAccepted(code)) return true
|
||||
|
||||
const now = new Date()
|
||||
const codeHash = sha256(`${email}:${purpose}:${code}:${userId ?? ''}`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user