From 664e0a8454f2b82615c8909c4c85ce61ae5ed011 Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Wed, 9 Sep 2020 19:29:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=8A=A0ip=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/ip.go | 16 ++++++++++++++++ models/ipblacks.go | 9 +++++++++ router/api.go | 1 + static/html/chat_main.html | 28 ++++++++++++++++++++++++++-- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 controller/ip.go diff --git a/controller/ip.go b/controller/ip.go new file mode 100644 index 0000000..eb5df77 --- /dev/null +++ b/controller/ip.go @@ -0,0 +1,16 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "github.com/taoshihan1991/imaptool/models" +) + +func PostIpblack(c *gin.Context) { + ip := c.PostForm("ip") + kefuId, _ := c.Get("kefu_name") + models.CreateIpblack(ip,kefuId) + c.JSON(200, gin.H{ + "code": 200, + "msg": "添加黑名单成功!", + }) +} diff --git a/models/ipblacks.go b/models/ipblacks.go index 1ae5a2f..10fbd30 100644 --- a/models/ipblacks.go +++ b/models/ipblacks.go @@ -8,3 +8,12 @@ type Ipblack struct{ KefuId string `json:"kefu_id"` CreateAt time.Time `json:"create_at"` } +func CreateIpblack(ip string,kefuId interface{})uint{ + black:=&Ipblack{ + IP:ip, + KefuId: kefuId, + CreateAt: time.Now(), + } + DB.Create(black) + return black.ID +} \ No newline at end of file diff --git a/router/api.go b/router/api.go index 4c7bafc..829b2ff 100644 --- a/router/api.go +++ b/router/api.go @@ -49,4 +49,5 @@ func InitApiRouter(engine *gin.Engine){ engine.POST("/notice",middleware.JwtApiMiddleware, controller.PostNotice) engine.DELETE("/notice",middleware.JwtApiMiddleware, controller.DelNotice) engine.GET("/notices",middleware.JwtApiMiddleware, controller.GetNotices) + engine.POST("/ipblack",controller.PostIpblack) } \ No newline at end of file diff --git a/static/html/chat_main.html b/static/html/chat_main.html index 8aaee52..dde6e57 100644 --- a/static/html/chat_main.html +++ b/static/html/chat_main.html @@ -142,13 +142,13 @@ - + ClientIP:<{visitor.source_ip}> - + IP:<{visitor.client_ip}> @@ -626,6 +626,30 @@ }); }); }, + addIpblack(ip){ + let _this=this; + $.ajax({ + type:"post", + url:"/ipblack", + data:{ip:ip}, + headers:{ + "token":localStorage.getItem("token") + }, + success: function(data) { + if(data.code!=200){ + _this.$message({ + message: data.msg, + type: 'error' + }); + }else{ + _this.$message({ + message: data.msg, + type: 'success' + }); + } + } + }); + }, }, created: function () { //jquery