优化代码添加黑名单

pull/30/head
陶士涵 4 years ago
parent 664e0a8454
commit 4f548505d4

@ -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": "添加黑名单成功!",

@ -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": "验证失败",
})
}

@ -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

@ -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=

@ -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"])
}
//}
}

@ -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,

@ -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)
}
Loading…
Cancel
Save