mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 17:13:54 +08:00
update:移动端注册页面加密
This commit is contained in:
@@ -94,8 +94,6 @@ export function getPublicConfig() {
|
|||||||
export interface RegisterData {
|
export interface RegisterData {
|
||||||
username: string
|
username: string
|
||||||
password: string
|
password: string
|
||||||
confirmPassword: string
|
|
||||||
captcha: string
|
|
||||||
captchaId: string
|
captchaId: string
|
||||||
areaCode: string
|
areaCode: string
|
||||||
mobile: string
|
mobile: string
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import { getEnvBaseUrl } from '@/utils'
|
|||||||
import { toast } from '@/utils/toast'
|
import { toast } from '@/utils/toast'
|
||||||
// 导入国际化相关功能
|
// 导入国际化相关功能
|
||||||
import { t, initI18n } from '@/i18n'
|
import { t, initI18n } from '@/i18n'
|
||||||
|
// 导入SM2加密工具
|
||||||
|
import { sm2Encrypt } from '@/utils'
|
||||||
|
|
||||||
// 获取屏幕边界到安全区域距离
|
// 获取屏幕边界到安全区域距离
|
||||||
let safeAreaInsets
|
let safeAreaInsets
|
||||||
@@ -90,6 +92,11 @@ const areaCodeList = computed(() => {
|
|||||||
return configStore.config.mobileAreaList || [{ name: '中国大陆', key: '+86' }]
|
return configStore.config.mobileAreaList || [{ name: '中国大陆', key: '+86' }]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// SM2公钥
|
||||||
|
const sm2PublicKey = computed(() => {
|
||||||
|
return configStore.config.sm2PublicKey
|
||||||
|
})
|
||||||
|
|
||||||
// 切换注册方式
|
// 切换注册方式
|
||||||
function toggleRegisterType() {
|
function toggleRegisterType() {
|
||||||
registerType.value = registerType.value === 'username' ? 'mobile' : 'username'
|
registerType.value = registerType.value === 'username' ? 'mobile' : 'username'
|
||||||
@@ -229,15 +236,31 @@ async function handleRegister() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查SM2公钥是否配置
|
||||||
|
if (!sm2PublicKey.value) {
|
||||||
|
toast.warning(t('sm2.publicKeyNotConfigured'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
|
// 加密密码
|
||||||
|
let encryptedPassword
|
||||||
|
try {
|
||||||
|
// 拼接验证码和密码
|
||||||
|
const captchaAndPassword = formData.value.captcha + formData.value.password
|
||||||
|
encryptedPassword = sm2Encrypt(sm2PublicKey.value, captchaAndPassword)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('密码加密失败:', error)
|
||||||
|
toast.warning(t('sm2.encryptionFailed'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 构建注册数据
|
// 构建注册数据
|
||||||
const registerData = {
|
const registerData = {
|
||||||
username: registerType.value === 'mobile' ? `${selectedAreaCode.value}${formData.value.mobile}` : formData.value.username,
|
username: registerType.value === 'mobile' ? `${selectedAreaCode.value}${formData.value.mobile}` : formData.value.username,
|
||||||
password: formData.value.password,
|
password: encryptedPassword,
|
||||||
confirmPassword: formData.value.confirmPassword,
|
|
||||||
captcha: formData.value.captcha,
|
|
||||||
captchaId: formData.value.captchaId,
|
captchaId: formData.value.captchaId,
|
||||||
areaCode: formData.value.areaCode,
|
areaCode: formData.value.areaCode,
|
||||||
mobile: formData.value.mobile,
|
mobile: formData.value.mobile,
|
||||||
|
|||||||
Reference in New Issue
Block a user