pull/271/head
wangchuxiao 2 years ago
parent cb10df7c9f
commit dfee8891d3

@ -8,6 +8,7 @@ import (
"Open_IM/pkg/common/log" "Open_IM/pkg/common/log"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"net/http" "net/http"
"time" "time"
) )
@ -41,16 +42,19 @@ func QueryIPRegister(c *gin.Context) {
resp.IP = req.IP resp.IP = req.IP
resp.RegisterNum = len(userIDList) resp.RegisterNum = len(userIDList)
resp.UserIDList = userIDList resp.UserIDList = userIDList
ipLimits, err := imdb.QueryIPLimits(req.IP) _, err = imdb.QueryIPLimits(req.IP)
if err != nil { if err != nil {
log.NewError(req.OperationID, "QueryIPLimits failed", req.IP, err.Error()) if gorm.IsRecordNotFoundError(err) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "QueryIPLimits error!"}) resp.Status = 0
return } else {
} log.NewError(req.OperationID, "QueryIPLimits failed", req.IP, err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "QueryIPLimits error!"})
if ipLimits.Ip != "" { return
}
} else {
resp.Status = 1 resp.Status = 1
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp}) c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
} }

@ -2,7 +2,6 @@ package im_mysql_model
import ( import (
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"github.com/jinzhu/gorm"
"time" "time"
) )
@ -35,10 +34,7 @@ func IsLimitUserLoginIp(userID string, LoginIp string) (bool, error) {
func QueryIPLimits(ip string) (*db.IpLimit, error) { func QueryIPLimits(ip string) (*db.IpLimit, error) {
var ipLimit db.IpLimit var ipLimit db.IpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Where("ip=?", ip).Take(&ip).Error err := db.DB.MysqlDB.DefaultGormDB().Model(&db.IpLimit{}).Where("ip=?", ip).First(&ip).Error
if gorm.IsRecordNotFoundError(err) {
return &ipLimit, nil
}
return &ipLimit, err return &ipLimit, err
} }

Loading…
Cancel
Save