Restrict user login with IP

This commit is contained in:
skiffer-git 2022-08-15 18:43:12 +08:00
parent 44e4c59493
commit 630fef29a2
2 changed files with 7 additions and 3 deletions

View File

@ -125,8 +125,12 @@ func QueryUserIPLimitLogin(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "GetIpLimitsByUserID error!"})
return
}
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
if len(resp) > 0 {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", resp)
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return
}
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": "[]"})
}
type AddUserIPLimitLoginReq struct {

View File

@ -44,7 +44,7 @@ func InsertOneIntoIpLimits(ipLimits db.IpLimit) error {
func GetIpLimitsLoginByUserID(userID string) ([]db.UserIpLimit, error) {
var ips []db.UserIpLimit
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("user_id=?", userID).Take(&ips).Error
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Where("user_id=?", userID).Find(&ips).Error
return ips, err
}