From 4f548505d4bcd50d874139070c0c901bfcda1cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E5=A3=AB=E6=B6=B5?= <630892807@qq.com> Date: Wed, 9 Sep 2020 20:59:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=BB=91=E5=90=8D=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/ip.go | 9 ++++++++- controller/login.go | 33 +-------------------------------- go.mod | 1 - go.sum | 2 -- middleware/jwt.go | 5 +++-- models/ipblacks.go | 2 +- router/api.go | 2 +- 7 files changed, 14 insertions(+), 40 deletions(-) diff --git a/controller/ip.go b/controller/ip.go index eb5df77..8a31409 100644 --- a/controller/ip.go +++ b/controller/ip.go @@ -7,8 +7,15 @@ import ( func PostIpblack(c *gin.Context) { ip := c.PostForm("ip") + if ip==""{ + c.JSON(200, gin.H{ + "code": 400, + "msg": "请输入IP!", + }) + return + } kefuId, _ := c.Get("kefu_name") - models.CreateIpblack(ip,kefuId) + models.CreateIpblack(ip,kefuId.(string)) c.JSON(200, gin.H{ "code": 200, "msg": "添加黑名单成功!", diff --git a/controller/login.go b/controller/login.go index 0229a50..37560c1 100644 --- a/controller/login.go +++ b/controller/login.go @@ -3,7 +3,6 @@ package controller import ( "github.com/gin-gonic/gin" "github.com/taoshihan1991/imaptool/tools" - "log" "time" ) // @Summary 登陆验证接口 @@ -17,32 +16,9 @@ import ( // @Router /check [post] //验证接口 func LoginCheckPass(c *gin.Context) { - authType := c.PostForm("type") password := c.PostForm("password") username := c.PostForm("username") - switch authType { - case "local": - sessionId := CheckPass(username, password) - userinfo := make(map[string]interface{}) - userinfo["name"] = username - userinfo["create_time"] = time.Now().Unix() - token, err := tools.MakeToken(userinfo) - userinfo["ref_token"]=true - refToken, _ := tools.MakeToken(userinfo) - log.Println(err) - if sessionId != "" { - c.JSON(200, gin.H{ - "code": 200, - "msg": "验证成功,正在跳转", - "result": gin.H{ - "token": token, - "ref_token":refToken, - "create_time":userinfo["create_time"], - }, - }) - return - } - case "kefu": + info,uRole,ok:=CheckKefuPass(username, password) userinfo:= make(map[string]interface{}) if !ok{ @@ -74,11 +50,4 @@ func LoginCheckPass(c *gin.Context) { "create_time":userinfo["create_time"], }, }) - return - - } - c.JSON(200, gin.H{ - "code": 400, - "msg": "验证失败", - }) } diff --git a/go.mod b/go.mod index 649dda7..327f091 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/jinzhu/gorm v1.9.14 github.com/spf13/cobra v0.0.5 - github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/swag v1.5.1 golang.org/x/net v0.0.0-20200513185701-a91f0712d120 diff --git a/go.sum b/go.sum index b039232..af137b8 100644 --- a/go.sum +++ b/go.sum @@ -165,8 +165,6 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM= -github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= github.com/swaggo/gin-swagger v1.2.0 h1:YskZXEiv51fjOMTsXrOetAjrMDfFaXD79PEoQBOe2W0= github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= github.com/swaggo/swag v1.5.1 h1:2Agm8I4K5qb00620mHq0VJ05/KT4FtmALPIcQR9lEZM= diff --git a/middleware/jwt.go b/middleware/jwt.go index e1c7c6f..70a1421 100644 --- a/middleware/jwt.go +++ b/middleware/jwt.go @@ -36,9 +36,10 @@ func JwtApiMiddleware(c *gin.Context){ c.Abort() } c.Set("user",userinfo["name"]) - if userinfo["type"]=="kefu"{ + //log.Println(userinfo) + //if userinfo["type"]=="kefu"{ c.Set("kefu_id",userinfo["kefu_id"]) c.Set("kefu_name",userinfo["name"]) c.Set("role_id",userinfo["role_id"]) - } + //} } diff --git a/models/ipblacks.go b/models/ipblacks.go index 10fbd30..fa0c444 100644 --- a/models/ipblacks.go +++ b/models/ipblacks.go @@ -8,7 +8,7 @@ type Ipblack struct{ KefuId string `json:"kefu_id"` CreateAt time.Time `json:"create_at"` } -func CreateIpblack(ip string,kefuId interface{})uint{ +func CreateIpblack(ip string,kefuId string)uint{ black:=&Ipblack{ IP:ip, KefuId: kefuId, diff --git a/router/api.go b/router/api.go index 829b2ff..d508c9d 100644 --- a/router/api.go +++ b/router/api.go @@ -49,5 +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) + engine.POST("/ipblack",middleware.JwtApiMiddleware,controller.PostIpblack) } \ No newline at end of file