增加微信邀请码功能 升级到one-api最新版代码 0.5.4版本
This commit is contained in:
parent
dd8cc364fe
commit
7b60ccb9ba
@ -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(),
|
||||
|
BIN
one-api.old
Executable file
BIN
one-api.old
Executable file
Binary file not shown.
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user