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:
+92
-2
@@ -12,6 +12,28 @@
|
||||
show-password
|
||||
/>
|
||||
|
||||
<!-- 短信验证码:发到「经办人手机号」(即账号手机号),注册接口的 code 用它校验 -->
|
||||
<div class="space-y-1">
|
||||
<label class="block text-sm text-gray-600">短信验证码</label>
|
||||
<div class="flex items-center gap-2">
|
||||
<input
|
||||
v-model="smsCode"
|
||||
class="w-full rounded-md border border-gray-300 px-4 py-2 text-sm"
|
||||
placeholder="发送至上方填写的经办人手机号"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
class="h-[38px] w-32 shrink-0 rounded-md border border-gray-300 text-xs text-gray-600 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50"
|
||||
:disabled="countdown > 0 || sending"
|
||||
@click="sendCode"
|
||||
>
|
||||
{{ countdown > 0 ? `${countdown} 秒后重发` : sending ? '发送中...' : '发送验证码' }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400">验证码发到「经办人手机号」,该号码就是登录账号手机号</p>
|
||||
</div>
|
||||
|
||||
<p class="text-center text-xs text-gray-500">
|
||||
企业联系电话、企业地址选填,其余项必填;提交后等待平台审核,审核通过方可购买标书
|
||||
</p>
|
||||
@@ -35,12 +57,38 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { register } = useHjcAuth()
|
||||
const { register, sendSms } = useHjcAuth()
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const entForm = ref<any>(null)
|
||||
|
||||
/** 短信验证码(注册接口的 code)+ 发送倒计时 */
|
||||
const smsCode = ref('')
|
||||
const sending = ref(false)
|
||||
const countdown = ref(0)
|
||||
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
const SMS_COUNTDOWN_SECONDS = 60
|
||||
|
||||
/**
|
||||
* 注册成功后的去向:`redirect` 可能被 encodeURIComponent 过(如 /buy%3Fid%3D3),
|
||||
* 这里安全解码;仅接受站内路径,避免开放重定向。
|
||||
*/
|
||||
function resolveRedirect() {
|
||||
const raw = (route.query.redirect as string) || ''
|
||||
if (!raw) return '/tender'
|
||||
let target = raw
|
||||
try {
|
||||
target = decodeURIComponent(raw)
|
||||
} catch {
|
||||
target = raw
|
||||
}
|
||||
// 必须以单个 '/' 开头:排除 http(s)://、协议相对地址 //evil.com,
|
||||
// 以及反斜杠变体 /\evil.com(部分浏览器把 '\' 归一成 '/',等价于 //evil.com)
|
||||
return target.startsWith('/') && !target.startsWith('//') && !target.includes('\\') ? target : '/tender'
|
||||
}
|
||||
|
||||
const form = ref<Record<string, any>>({
|
||||
name: '',
|
||||
password: '',
|
||||
@@ -62,9 +110,49 @@ const materials = ref<any[]>([
|
||||
{ materialType: 'license', label: '营业执照', materialName: '营业执照', fileUrl: '' }
|
||||
])
|
||||
|
||||
/** 停止倒计时(倒计时结束或页面卸载时调用) */
|
||||
function stopCountdown() {
|
||||
if (countdownTimer) {
|
||||
clearInterval(countdownTimer)
|
||||
countdownTimer = null
|
||||
}
|
||||
countdown.value = 0
|
||||
}
|
||||
|
||||
/** 发送短信验证码到经办人手机号(= 账号手机号) */
|
||||
async function sendCode() {
|
||||
error.value = ''
|
||||
const phone = String(form.value.agentPhone || '').trim()
|
||||
if (!phone) {
|
||||
error.value = '请先填写经办人手机号'
|
||||
return
|
||||
}
|
||||
sending.value = true
|
||||
try {
|
||||
const res = await sendSms(phone)
|
||||
if (!res.ok) {
|
||||
error.value = res.message || '验证码发送失败'
|
||||
return
|
||||
}
|
||||
countdown.value = SMS_COUNTDOWN_SECONDS
|
||||
countdownTimer = setInterval(() => {
|
||||
countdown.value -= 1
|
||||
if (countdown.value <= 0) stopCountdown()
|
||||
}, 1000)
|
||||
} finally {
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onUnmounted(stopCountdown)
|
||||
|
||||
async function submitForm() {
|
||||
error.value = ''
|
||||
if (!entForm.value?.validate()) return
|
||||
if (!smsCode.value.trim()) {
|
||||
error.value = '请输入短信验证码'
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
// buildPayload 返回 { name, ... };注册接口用 enterpriseName 作为登录账号
|
||||
@@ -72,10 +160,12 @@ async function submitForm() {
|
||||
const res = await register({
|
||||
enterpriseName: name,
|
||||
password: form.value.password,
|
||||
// code = 短信验证码(登录接口的 code 是图形验证码,两者不同)
|
||||
code: smsCode.value.trim(),
|
||||
...rest
|
||||
})
|
||||
if (res.ok) {
|
||||
return navigateTo((route.query.redirect as string) || '/tender')
|
||||
return navigateTo(resolveRedirect())
|
||||
}
|
||||
error.value = res.message || '注册失败'
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user