mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-21 09:19:01 +08:00
用户表增加注册IP 登陆IP
1、用户表增加注册IP 登陆IP 2、新增ip_limit表、user_ip_limit表 3、用户创建需要增加createIp参数同步 用户登录需要增加loginIp参数同步 login_limit 限制说明 0:读取ip_limits表 限制用户注册+用户登陆IP 1:读取user_ip_limits表 限制用户在指定IP登陆 2:读取black_lists表 限制用户在限制时间不能登陆
This commit is contained in:
@@ -10,8 +10,9 @@ import (
|
||||
"Open_IM/pkg/utils"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ParamsLogin struct {
|
||||
@@ -62,6 +63,11 @@ func Login(c *gin.Context) {
|
||||
openIMGetUserToken.Platform = params.Platform
|
||||
openIMGetUserToken.Secret = config.Config.Secret
|
||||
openIMGetUserToken.UserID = userID
|
||||
loginIp := c.Request.Header.Get("X-Forward-For")
|
||||
if loginIp == "" {
|
||||
loginIp = c.ClientIP()
|
||||
}
|
||||
openIMGetUserToken.LoginIp = loginIp
|
||||
openIMGetUserTokenResp := api.UserTokenResp{}
|
||||
bMsg, err := http2.Post(url, openIMGetUserToken, 2)
|
||||
if err != nil {
|
||||
@@ -72,7 +78,11 @@ func Login(c *gin.Context) {
|
||||
err = json.Unmarshal(bMsg, &openIMGetUserTokenResp)
|
||||
if err != nil || openIMGetUserTokenResp.ErrCode != 0 {
|
||||
log.NewError(params.OperationID, "request get user token", account, "err", "")
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": ""})
|
||||
if openIMGetUserTokenResp.ErrCode == constant.LoginLimit {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.LoginLimit, "errMsg": "用户登录被限制"})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.GetIMTokenErr, "errMsg": ""})
|
||||
}
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMGetUserTokenResp.UserToken})
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type ParamsSetPassword struct {
|
||||
@@ -81,6 +82,11 @@ func SetPassword(c *gin.Context) {
|
||||
openIMRegisterReq.Nickname = params.Nickname
|
||||
openIMRegisterReq.Secret = config.Config.Secret
|
||||
openIMRegisterReq.FaceURL = params.FaceURL
|
||||
createIp := c.Request.Header.Get("X-Forward-For")
|
||||
if createIp == "" {
|
||||
createIp = c.ClientIP()
|
||||
}
|
||||
openIMRegisterReq.CreateIp = createIp
|
||||
openIMRegisterResp := api.UserRegisterResp{}
|
||||
log.NewDebug(params.OperationID, utils.GetSelfFuncName(), "register req:", openIMRegisterReq)
|
||||
bMsg, err := http2.Post(url, openIMRegisterReq, 2)
|
||||
@@ -95,7 +101,11 @@ func SetPassword(c *gin.Context) {
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, utils.GetSelfFuncName(), err.Error())
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
||||
if openIMRegisterResp.ErrCode == constant.RegisterLimit {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterLimit, "errMsg": "用户注册被限制"})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.RegisterFailed, "errMsg": "register failed: " + openIMRegisterResp.ErrMsg})
|
||||
}
|
||||
return
|
||||
}
|
||||
log.Info(params.OperationID, "begin store mysql", account, params.Password, "info", params.FaceURL, params.Nickname)
|
||||
|
||||
Reference in New Issue
Block a user