pull/267/head
wangchuxiao 2 years ago
parent b705ac24fa
commit 919e2543ca

@ -46,7 +46,7 @@ func main() {
cmsRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode) cmsRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode)
cmsRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes) cmsRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes)
cmsRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIPLimitLogin) cmsRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIDLimitLogin)
cmsRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin) cmsRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin)
cmsRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin) cmsRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin)

@ -43,7 +43,7 @@ func QueryIPRegister(c *gin.Context) {
resp.UserIDList = userIDList resp.UserIDList = userIDList
ipLimits, err := imdb.QueryIPLimits(req.IP) ipLimits, err := imdb.QueryIPLimits(req.IP)
if err != nil { if err != nil {
log.NewError(req.OperationID, "QueryIPLimits failed", req.IP) log.NewError(req.OperationID, "QueryIPLimits failed", req.IP, err.Error())
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "QueryIPLimits error!"}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "QueryIPLimits error!"})
return return
} }
@ -76,7 +76,7 @@ func AddIPLimit(c *gin.Context) {
LimitRegister: 1, LimitRegister: 1,
LimitLogin: 1, LimitLogin: 1,
CreateTime: time.Now(), CreateTime: time.Now(),
LimitTime: time.Time{}, LimitTime: utils.UnixSecondToTime(int64(req.LimitTime)),
}); err != nil { }); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP, req.LimitTime) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP, req.LimitTime)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"})
@ -94,15 +94,15 @@ type RemoveIPLimitResp struct {
} }
func RemoveIPLimit(c *gin.Context) { func RemoveIPLimit(c *gin.Context) {
req := AddIPLimitReq{} req := RemoveIPLimitReq{}
//resp := AddIPLimitResp{} //resp := AddIPLimitResp{}
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.ErrArgs, "errMsg": err.Error()})
return return
} }
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req)
if err := imdb.DeleteOneFromIpLimits(req.IP); err != nil { if err := imdb.DeleteOneFromIpLimits(req.IP); err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP, req.LimitTime) log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.IP)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"}) c.JSON(http.StatusInternalServerError, gin.H{"errCode": constant.ErrDB.ErrCode, "errMsg": "InsertOneIntoIpLimits error!"})
return return
} }
@ -120,7 +120,7 @@ type QueryUserIDIPLimitLoginReq struct {
// UserIpLimit []db.UserIpLimit `json:"userIpLimit"` // UserIpLimit []db.UserIpLimit `json:"userIpLimit"`
//} //}
func QueryUserIPLimitLogin(c *gin.Context) { func QueryUserIDLimitLogin(c *gin.Context) {
req := QueryUserIDIPLimitLoginReq{} req := QueryUserIDIPLimitLoginReq{}
if err := c.BindJSON(&req); err != nil { if err := c.BindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()}) c.JSON(http.StatusBadRequest, gin.H{"errCode": constant.FormattingError, "errMsg": err.Error()})
@ -138,7 +138,7 @@ func QueryUserIPLimitLogin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp}) c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
return return
} }
c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": "[]"}) c.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "data": resp})
} }
type AddUserIPLimitLoginReq struct { type AddUserIPLimitLoginReq struct {

@ -53,7 +53,7 @@ func InsertOneIntoIpLimits(ipLimits db.IpLimit) error {
} }
func DeleteOneFromIpLimits(ip string) error { func DeleteOneFromIpLimits(ip string) error {
ipLimits := &db.IpLimit{} ipLimits := &db.IpLimit{Ip: ip}
return db.DB.MysqlDB.DefaultGormDB().Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error return db.DB.MysqlDB.DefaultGormDB().Model(ipLimits).Where("ip=?", ip).Delete(ipLimits).Error
} }

Loading…
Cancel
Save