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