diff --git a/dashboard/src2/pages/LoginSignup.vue b/dashboard/src2/pages/LoginSignup.vue index 60c789a..0a6e52a 100644 --- a/dashboard/src2/pages/LoginSignup.vue +++ b/dashboard/src2/pages/LoginSignup.vue @@ -608,36 +608,39 @@ export default { }, }; }, - signupWithUsername() { - return { - url: 'jcloud.api.account.signup_with_username', - params: { - username: this.username, - email: this.email || null, - phone_number: this.phoneNumber || null, - password: this.signupPassword, - referrer: this.getReferrerIfAny(), - product: this.$route.query.product, - }, - onSuccess(res) { - // 保存用户信息 - localStorage.setItem('login_email', this.username || this.email); - - if (res && res.dashboard_route) { - // 使用后端提供的路由 - window.location.href = res.dashboard_route; - } else { - // 简化URL,仅确保前缀正确 - window.location.href = '/dashboard/welcome'; - } - }, - onError(err) { - toast.error( - getToastErrorMessage(err, '注册失败,请检查您的信息'), - ); - }, - }; - }, + signupWithUsername() { + return { + url: 'jcloud.api.account.signup_with_username', + params: { + username: this.username, + email: this.email || null, + phone_number: this.phoneNumber || null, + password: this.signupPassword, + referrer: this.getReferrerIfAny(), + product: this.$route.query.product, + }, + onSuccess(res) { + if (res && res.success === false) { + toast.error(res.message || '注册失败,请检查您的信息'); + return; + } + + localStorage.setItem('login_email', this.username || this.email); + + if (res && res.dashboard_route) { + window.location.href = res.dashboard_route; + } else { + window.location.href = '/dashboard/welcome'; + } + }, + onError(err) { + const errorMessage = err?.messages?.length + ? err.messages.join('\n') + : (err?.message || '注册失败,请检查您的信息'); + toast.error(errorMessage); + }, + }; + }, }, methods: { resetSignupState() { @@ -654,14 +657,10 @@ export default { provider: this.socialLoginKey, }); } else if (this.useEmail && this.otpSent) { - // 如果是邮箱验证码登录且已发送验证码,则通过verifyOTPAndLogin处理 - // 这部分由专门的按钮处理,不在表单提交中处理 return; } else if (!this.useEmail && this.email && this.password) { - // 密码登录 this.checkTwoFactorAndLogin(); } else if (this.useEmail && !this.otpSent) { - // 请求发送验证码 this.$resources.sendOTP.submit(); } } else if (this.hasForgotPassword) { diff --git a/jcloud/api/account.py b/jcloud/api/account.py index c157b33..0e9ec02 100644 --- a/jcloud/api/account.py +++ b/jcloud/api/account.py @@ -73,6 +73,7 @@ def signup(email, product=None, referrer=None): def signup_with_username(username, password, email=None, phone_number=None, referrer=None, product=None): """ 使用用户名注册新账户,邮箱和手机号为可选 + 返回格式: {"success": bool, "message": str, "dashboard_route": str} """ from jingrow.utils import validate_email_address from jingrow.utils.password import update_password @@ -83,11 +84,17 @@ def signup_with_username(username, password, email=None, phone_number=None, refe try: # 验证用户名 if not username or len(username) < 3: - jingrow.throw("用户名至少需要3个字符") + return { + "success": False, + "message": "用户名至少需要3个字符" + } # 检查用户名是否已存在 if jingrow.db.exists("User", {"username": username}): - jingrow.throw("该用户名已被使用") + return { + "success": False, + "message": "该用户名已被使用" + } # 如果提供了邮箱,验证邮箱格式并检查是否已存在 user_email = None @@ -95,18 +102,30 @@ def signup_with_username(username, password, email=None, phone_number=None, refe try: validate_email_address(email, True) except: - jingrow.throw("请输入有效的邮箱地址") + return { + "success": False, + "message": "请输入有效的邮箱地址" + } if jingrow.db.exists("User", {"email": email}): - jingrow.throw("该邮箱已被注册") + return { + "success": False, + "message": "该邮箱已被注册" + } user_email = email # 如果提供了手机号,验证手机号格式并检查是否已存在 if phone_number: if not re.match(r'^1[3-9]\d{9}$', phone_number): - jingrow.throw("请输入有效的手机号码") + return { + "success": False, + "message": "请输入有效的手机号码" + } if jingrow.db.exists("User", {"mobile_no": phone_number}): - jingrow.throw("该手机号已被注册") + return { + "success": False, + "message": "该手机号已被注册" + } # 创建用户,但先不设置密码 user_pg = { @@ -179,11 +198,20 @@ def signup_with_username(username, password, email=None, phone_number=None, refe jingrow.db.commit() - # 返回与标准流程一致的响应 + # 返回成功响应 return { + "success": True, + "message": "注册成功", "dashboard_route": "" } + except Exception as e: + # 捕获其他异常并返回错误消息 + jingrow.log_error("signup_with_username 错误", str(e)) + return { + "success": False, + "message": f"注册失败: {str(e)}" + } finally: # 恢复原始用户 jingrow.set_user(current_user)