diff --git a/VERSION b/VERSION index b0c2058e..8ea9cc1e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.5.2 +v0.5.4 diff --git a/controller/wechat.go b/controller/wechat.go index ff4c9fb6..fd5f7e35 100644 --- a/controller/wechat.go +++ b/controller/wechat.go @@ -84,8 +84,16 @@ func WeChatAuth(c *gin.Context) { user.DisplayName = "WeChat User" user.Role = common.RoleCommonUser user.Status = common.UserStatusEnabled - - if err := user.Insert(0); err != nil { + // 开始处理邀请码逻辑 类似 https://aiapi2d.com/login?aff=XqgY 带邀请码的链接,按照邀请码寻找邀请者。 + affCode := c.Query("affCode") // this code is the inviter's code, not the user's own code + inviterId := 0 + if affCode == "" { + + } else { + inviterId, _ = model.GetUserIdByAffCode(affCode) + } + user.InviterId = inviterId + if err := user.Insert(inviterId); err != nil { c.JSON(http.StatusOK, gin.H{ "success": false, "message": err.Error(), diff --git a/one-api b/one-api index 697ddfc3..9a1b8f4c 100755 Binary files a/one-api and b/one-api differ diff --git a/one-api.old b/one-api.old new file mode 100755 index 00000000..697ddfc3 Binary files /dev/null and b/one-api.old differ diff --git a/web/src/components/LoginForm.js b/web/src/components/LoginForm.js index a1d53b3c..d192e13c 100644 --- a/web/src/components/LoginForm.js +++ b/web/src/components/LoginForm.js @@ -18,7 +18,10 @@ const LoginForm = () => { let navigate = useNavigate(); const [status, setStatus] = useState({}); const logo = getLogo(); - + let affCode = new URLSearchParams(window.location.search).get('aff'); + if (affCode) { + localStorage.setItem('aff', affCode); + } useEffect(() => { if (searchParams.get('expired')) { showError('未登录或登录已过期,请重新登录!'); @@ -37,8 +40,20 @@ const LoginForm = () => { }; const onSubmitWeChatVerificationCode = async () => { + // WeChat 渠道注册也能带上邀请码链接,这里检查是否之前打开过邀请码链接,通过localStorage存储来寻找 + if (!affCode) { + affCode = localStorage.getItem('aff'); + } + // 检查 affCode 是否有值 + if (affCode) { + // 如果有值,拼接到 URL 中 + var url = `/api/oauth/wechat?code=${inputs.wechat_verification_code}&affCode=${affCode}`; + } else { + // 如果没有值,不拼接affCode + var url = `/api/oauth/wechat?code=${inputs.wechat_verification_code}`; + } const res = await API.get( - `/api/oauth/wechat?code=${inputs.wechat_verification_code}` + url ); const { success, message, data } = res.data; if (success) {