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

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

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

Loading…
Cancel
Save