feat(tender): 登录加图形验证码、注册加短信验证码;改按 body.code 判定 401/403
- 新增 captcha / sms / logout 三个 Nuxt server 代理 - 修复代理把 ApiResult 拍扁成 data 的问题(my-orders、enterprise、order、pay、 mark-paid):登录态失败被前端当成「没有订单 / 未提交资质」,无法区分 - 新增 handleAuthCode 统一处理:401 → 清凭据并跳 /login?redirect=…; 403 → 只提示「没有访问权限」,不清 token、不跳登录页 - 登录页与注册页分别接入图形验证码与短信验证码(含 60s 倒计时) - 修复回跳开放重定向:redirect 参数安全解码且只接受站内路径 (拒绝 //evil.com、https://… 及反斜杠变体 /\evil.com) - 下单成功但发起支付失败时停在支付步,避免用户重提交产生重复订单
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { $fetch } from 'ofetch'
|
||||
import { createError, defineEventHandler } from 'h3'
|
||||
import { useRuntimeConfig } from '#imports'
|
||||
import { getTenantFromContext } from '../../utils/tenant'
|
||||
|
||||
/**
|
||||
* 图形验证码(登录用)
|
||||
* GET /api/tender/captcha
|
||||
* 代理到 mp-api /api/hjc/auth/captcha;匿名可访问。
|
||||
*
|
||||
* 约定:mp-api 原样透传 ApiResult{code,message,data},
|
||||
* data = { image: 'data:image/png;base64,...' }。<b>后端刻意不下发答案</b>,
|
||||
* 必须把图片显示给用户肉眼识别后输入,前端不得(也无法)自行校验答案。
|
||||
*/
|
||||
export default defineEventHandler(async (event) => {
|
||||
const config = useRuntimeConfig()
|
||||
const ctx = getTenantFromContext(event, config)
|
||||
|
||||
try {
|
||||
return await $fetch('/hjc/auth/captcha', {
|
||||
baseURL: config.public.modulesApiBase,
|
||||
method: 'GET',
|
||||
headers: { TenantId: ctx.tenantId },
|
||||
query: { TenantId: ctx.tenantId }
|
||||
})
|
||||
} catch (error: any) {
|
||||
throw createError({
|
||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||
statusMessage: error?.data?.message || error?.statusMessage || 'Failed to fetch captcha'
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user